Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ sequence = [

# Other tools

[tool.black]
line-length = 79
include = '\.py$'

[tool.coverage.run]
branch = true
command_line = "-m pytest"
Expand All @@ -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
Expand Down
29 changes: 14 additions & 15 deletions src/git_draft/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions src/git_draft/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/git_draft/drafter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/git_draft/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down