diff --git a/pyproject.toml b/pyproject.toml index 9df2634..8a763ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,10 +75,6 @@ sequence = [ # Other tools -[tool.black] -line-length = 79 -include = '\.py$' - [tool.coverage.run] branch = true command_line = "-m pytest" @@ -98,8 +94,8 @@ log_level = "DEBUG" line-length = 79 [tool.ruff.lint] -select = ["D", "E", "F", "I"] -ignore = ["D102", "D103", "D105", "D107", "D415"] +select = ["D", "E", "F", "I", "N", "PL", "RUF", "SIM"] +ignore = ["D102", "D103", "D105", "D107", "D415", "PLR2004"] [tool.ruff.lint.isort] force-sort-within-sections = true diff --git a/src/git_draft/__main__.py b/src/git_draft/__main__.py index 6fa07d4..29b56bf 100644 --- a/src/git_draft/__main__.py +++ b/src/git_draft/__main__.py @@ -147,27 +147,26 @@ def on_delete_file(self, path: PurePosixPath, _reason: str | None) -> None: def edit(*, path: Path | None = None, text: str | None = None) -> str: if sys.stdin.isatty(): return open_editor(text or "", path) + # We exit with a custom code to allow the caller to act accordingly. + # For example we can handle this from Vim by opening the returned path + # or text in a buffer, to then continue to another command on save. + # https://unix.stackexchange.com/q/604260 + elif path is None: + assert text, "Empty path and text" + print(text) + sys.exit(198) else: - # We exit with a custom code to allow the caller to act accordingly. - # For example we can handle this from Vim by opening the returned path - # or text in a buffer, to then continue to another command on save. - # https://unix.stackexchange.com/q/604260 - if path is None: - assert text, "Empty path and text" - print(text) - sys.exit(198) - else: - if text is not None: - with open(path, "w") as f: - f.write(text) - print(path) - sys.exit(199) + if text is not None: + with open(path, "w") as f: + f.write(text) + print(path) + sys.exit(199) _PROMPT_PLACEHOLDER = "Enter your prompt here..." -def main() -> None: +def main() -> None: # noqa: PLR0912 PLR0915 config = Config.load() (opts, args) = new_parser().parse_args() diff --git a/src/git_draft/common.py b/src/git_draft/common.py index ebf3c40..c3673a1 100644 --- a/src/git_draft/common.py +++ b/src/git_draft/common.py @@ -11,7 +11,7 @@ import string import textwrap import tomllib -from typing import Any, Mapping, Self, Sequence, Type +from typing import Any, ClassVar, Mapping, Self, Sequence, Type import prettytable import xdg_base_dirs @@ -104,7 +104,7 @@ def qualified_class_name(cls: Type) -> str: class Table: """Pretty-printable table""" - _kwargs = dict(border=False) # Shared options + _kwargs: ClassVar[Mapping[str, Any]] = dict(border=False) # Shared options def __init__(self, data: prettytable.PrettyTable) -> None: self.data = data diff --git a/src/git_draft/drafter.py b/src/git_draft/drafter.py index 90c05ca..9da8b67 100644 --- a/src/git_draft/drafter.py +++ b/src/git_draft/drafter.py @@ -73,7 +73,7 @@ def create(cls, store: Store, path: str | None = None) -> Drafter: except git.NoSuchPathError: raise ValueError(f"No git repository at {path}") - def generate_draft( + def generate_draft( # noqa: PLR0913 self, prompt: str | TemplatedPrompt, bot: Bot, @@ -126,7 +126,7 @@ def generate_draft( # Trigger code generation. _logger.debug("Running bot... [bot=%s]", bot) operation_recorder = _OperationRecorder() - tool_visitors = [operation_recorder] + list(tool_visitors or []) + tool_visitors = [operation_recorder, *list(tool_visitors or [])] toolbox = StagingToolbox(self._repo, tool_visitors) start_time = time.perf_counter() goal = Goal(prompt_contents, timeout) diff --git a/src/git_draft/store.py b/src/git_draft/store.py index 648e533..5b50924 100644 --- a/src/git_draft/store.py +++ b/src/git_draft/store.py @@ -38,7 +38,7 @@ def cursor(self) -> Iterator[sqlite3.Cursor]: with contextlib.closing(self._connection.cursor()) as cursor: try: yield cursor - except: # noqa + except: self._connection.rollback() raise else: