Loading .lint +2 −0 Original line number Diff line number Diff line [mypy] strict = true warn_unreachable = true [flake8] max-line-length = 92 Loading hooks/copyright.py +1 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,7 @@ def cli_parser() -> argparse.ArgumentParser: return parser def main(): def main() -> None: """ CLI entrypoint """ Loading hooks/squash.py +25 −18 Original line number Diff line number Diff line Loading @@ -20,15 +20,18 @@ Block commit starting with "squash!" or "fixup!" from being pushed These commits must be squashed before a push to a remote """ from __future__ import annotations import argparse import os import sys from collections import defaultdict from fnmatch import fnmatch from pathlib import Path from subprocess import PIPE from subprocess import Popen from textwrap import dedent from typing import DefaultDict from typing import Generator from typing import List from urllib.parse import urlparse Loading @@ -40,16 +43,6 @@ PRE_COMMIT_REMOTE_URL = 'PRE_COMMIT_REMOTE_URL' PRE_COMMIT_REMOTE_BRANCH = 'PRE_COMMIT_REMOTE_BRANCH' class CommitDict(defaultdict): """ A dict for holding Commit objects mapped from their subject lines """ def __missing__(self, subject): self[subject] = commit = Commit(subject) return commit class Commit: """ A class for holding information about regular commits Loading @@ -65,18 +58,28 @@ class Commit: self.updates: List[str] = [] def git_log_cmd(): class CommitDict(DefaultDict[str, Commit]): """ A dict for holding Commit objects mapped from their subject lines """ def __missing__(self, subject: str) -> Commit: self[subject] = commit = Commit(subject) return commit def git_log_cmd() -> List[str]: """ Return the first arguments for running a git-log command """ if GIT_EXEC_PATH in os.environ: git_log = Path.cwd() / os.environ[GIT_EXEC_PATH] / 'git-log' if git_log.exists() and git_log.stat().st_mode & os.X_OK: return [git_log] return [git_log.as_posix()] return ['git', 'log'] def catalogue_commits(): def catalogue_commits() -> Generator[Commit, None, None]: """ Yield all regular commits as Commit objects, containing any update (squash) commits """ Loading @@ -93,6 +96,8 @@ def catalogue_commits(): commits = CommitDict() with Popen(cmd, stdout=PIPE, text=True) as proc: if proc.stdout is None: raise RuntimeError # Satisfying mypy which thinks stdout could be None for line in proc.stdout.readlines(): sha, _, subject = line.partition(' ') keyword, has_marker, target = subject.partition('! ') Loading @@ -112,7 +117,7 @@ def catalogue_commits(): yield from commits.values() def parse_arguments(): def parse_arguments() -> argparse.Namespace: """ Parse command line arguments and handle any that have an immediate effect """ Loading @@ -126,8 +131,10 @@ def parse_arguments(): if opts.skip_remote: skip_remote(*opts.skip_remote) return opts def skip_branch(*skip_branches: str): def skip_branch(*skip_branches: str) -> None: """ Exit (0) if PRE_COMMIT_REMOTE_BRANCH is set and matches a provided fnmatch() pattern """ Loading @@ -148,7 +155,7 @@ def skip_branch(*skip_branches: str): sys.exit(0) def skip_remote(*skip_remotes: str): def skip_remote(*skip_remotes: str) -> None: """ Exit (0) if PRE_COMMIT_REMOTE_URL is set and matches a provided URL pattern """ Loading @@ -174,7 +181,7 @@ def skip_remote(*skip_remotes: str): sys.exit(0) def main(): def main() -> None: """ CLI entrypoint """ Loading Loading
.lint +2 −0 Original line number Diff line number Diff line [mypy] strict = true warn_unreachable = true [flake8] max-line-length = 92 Loading
hooks/copyright.py +1 −1 Original line number Diff line number Diff line Loading @@ -111,7 +111,7 @@ def cli_parser() -> argparse.ArgumentParser: return parser def main(): def main() -> None: """ CLI entrypoint """ Loading
hooks/squash.py +25 −18 Original line number Diff line number Diff line Loading @@ -20,15 +20,18 @@ Block commit starting with "squash!" or "fixup!" from being pushed These commits must be squashed before a push to a remote """ from __future__ import annotations import argparse import os import sys from collections import defaultdict from fnmatch import fnmatch from pathlib import Path from subprocess import PIPE from subprocess import Popen from textwrap import dedent from typing import DefaultDict from typing import Generator from typing import List from urllib.parse import urlparse Loading @@ -40,16 +43,6 @@ PRE_COMMIT_REMOTE_URL = 'PRE_COMMIT_REMOTE_URL' PRE_COMMIT_REMOTE_BRANCH = 'PRE_COMMIT_REMOTE_BRANCH' class CommitDict(defaultdict): """ A dict for holding Commit objects mapped from their subject lines """ def __missing__(self, subject): self[subject] = commit = Commit(subject) return commit class Commit: """ A class for holding information about regular commits Loading @@ -65,18 +58,28 @@ class Commit: self.updates: List[str] = [] def git_log_cmd(): class CommitDict(DefaultDict[str, Commit]): """ A dict for holding Commit objects mapped from their subject lines """ def __missing__(self, subject: str) -> Commit: self[subject] = commit = Commit(subject) return commit def git_log_cmd() -> List[str]: """ Return the first arguments for running a git-log command """ if GIT_EXEC_PATH in os.environ: git_log = Path.cwd() / os.environ[GIT_EXEC_PATH] / 'git-log' if git_log.exists() and git_log.stat().st_mode & os.X_OK: return [git_log] return [git_log.as_posix()] return ['git', 'log'] def catalogue_commits(): def catalogue_commits() -> Generator[Commit, None, None]: """ Yield all regular commits as Commit objects, containing any update (squash) commits """ Loading @@ -93,6 +96,8 @@ def catalogue_commits(): commits = CommitDict() with Popen(cmd, stdout=PIPE, text=True) as proc: if proc.stdout is None: raise RuntimeError # Satisfying mypy which thinks stdout could be None for line in proc.stdout.readlines(): sha, _, subject = line.partition(' ') keyword, has_marker, target = subject.partition('! ') Loading @@ -112,7 +117,7 @@ def catalogue_commits(): yield from commits.values() def parse_arguments(): def parse_arguments() -> argparse.Namespace: """ Parse command line arguments and handle any that have an immediate effect """ Loading @@ -126,8 +131,10 @@ def parse_arguments(): if opts.skip_remote: skip_remote(*opts.skip_remote) return opts def skip_branch(*skip_branches: str): def skip_branch(*skip_branches: str) -> None: """ Exit (0) if PRE_COMMIT_REMOTE_BRANCH is set and matches a provided fnmatch() pattern """ Loading @@ -148,7 +155,7 @@ def skip_branch(*skip_branches: str): sys.exit(0) def skip_remote(*skip_remotes: str): def skip_remote(*skip_remotes: str) -> None: """ Exit (0) if PRE_COMMIT_REMOTE_URL is set and matches a provided URL pattern """ Loading @@ -174,7 +181,7 @@ def skip_remote(*skip_remotes: str): sys.exit(0) def main(): def main() -> None: """ CLI entrypoint """ Loading