diff --git a/poetry.lock b/poetry.lock index e5290ac..9d9b964 100644 --- a/poetry.lock +++ b/poetry.lock @@ -369,6 +369,22 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "isort" +version = "6.0.1" +description = "A Python utility / library to sort Python imports." +optional = false +python-versions = ">=3.9.0" +groups = ["dev"] +files = [ + {file = "isort-6.0.1-py3-none-any.whl", hash = "sha256:2dc5d7f65c9678d94c88dfc29161a320eec67328bc97aad576874cb4be1e9615"}, + {file = "isort-6.0.1.tar.gz", hash = "sha256:1cb5df28dfbc742e490c5e41bad6da41b805b0a8be7bc93cd0fb2a8a890ac450"}, +] + +[package.extras] +colors = ["colorama"] +plugins = ["setuptools"] + [[package]] name = "jinja2" version = "3.1.6" @@ -1039,4 +1055,4 @@ openai = ["openai"] [metadata] lock-version = "2.1" python-versions = ">=3.12,<4" -content-hash = "56104e3bfea6903e5624f065ce029ed7870e7fccd672ed4f94a2fea6c8441086" +content-hash = "424e72767c3058d1b6ee29dae2bee026fc2c01762c2b57734c271419c8aa72b7" diff --git a/pyproject.toml b/pyproject.toml index c449537..9af51b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,7 @@ black = "^25.1.0" coverage = "^7.4.4" flake8 = "^7.0.0" flake8-pyproject = "^1.2.3" +isort = "^6.0.1" mypy = "^1.2.0" poethepoet = "^0.25.0" pytest = "^7.1.2" @@ -48,7 +49,10 @@ pytest = "^7.1.2" [tool.poe.tasks.fix] help = "format source code" -cmd = "black ${args}" +sequence = [ + {cmd="isort ${args}"}, + {cmd="black ${args}"}, +] args = [ {name="args", help="target folders", positional=true, multiple=true, default="src tests"}, ] @@ -56,6 +60,7 @@ args = [ [tool.poe.tasks.lint] help = "lint source code" sequence = [ + {cmd="isort --check ${args}"}, {cmd="black --check --quiet ${args}"}, {cmd="flake8 ${args}"}, {cmd="mypy ${args}"}, @@ -89,6 +94,10 @@ show_missing = true [tool.flake8] ignore = ["E203", "E501", "E704", "W503"] +[tool.isort] +profile = "black" +force_sort_within_sections = true + [tool.mypy] disable_error_code = "import-untyped" diff --git a/src/git_draft/__main__.py b/src/git_draft/__main__.py index e0103e8..e27c3f8 100644 --- a/src/git_draft/__main__.py +++ b/src/git_draft/__main__.py @@ -8,7 +8,7 @@ import sys from .bots import Operation, load_bot -from .common import Config, PROGRAM, UnreachableError, ensure_state_home +from .common import PROGRAM, Config, UnreachableError, ensure_state_home from .drafter import Drafter from .editor import open_editor from .prompt import TemplatedPrompt diff --git a/src/git_draft/bots/common.py b/src/git_draft/bots/common.py index a6f30f4..3b95c72 100644 --- a/src/git_draft/bots/common.py +++ b/src/git_draft/bots/common.py @@ -5,7 +5,7 @@ from pathlib import Path, PurePosixPath from typing import Callable, Sequence -from ..common import ensure_state_home, JSONObject +from ..common import JSONObject, ensure_state_home class Toolbox: diff --git a/src/git_draft/bots/openai.py b/src/git_draft/bots/openai.py index 31494b7..39e9dcf 100644 --- a/src/git_draft/bots/openai.py +++ b/src/git_draft/bots/openai.py @@ -14,15 +14,15 @@ import json import logging -import openai import os from pathlib import PurePosixPath from typing import Any, Mapping, Self, Sequence, TypedDict, override +import openai + from ..common import JSONObject, reindent from .common import Action, Bot, Goal, Toolbox - _logger = logging.getLogger(__name__) diff --git a/src/git_draft/common.py b/src/git_draft/common.py index 33df3ce..ace2b6f 100644 --- a/src/git_draft/common.py +++ b/src/git_draft/common.py @@ -11,8 +11,8 @@ import textwrap import tomllib from typing import Any, Mapping, Self, Sequence -import xdg_base_dirs +import xdg_base_dirs PROGRAM = "git-draft" diff --git a/src/git_draft/drafter.py b/src/git_draft/drafter.py index a4f60af..b9eb12d 100644 --- a/src/git_draft/drafter.py +++ b/src/git_draft/drafter.py @@ -1,7 +1,6 @@ from __future__ import annotations import dataclasses -import git import json import logging from pathlib import PurePosixPath @@ -11,12 +10,13 @@ import time from typing import Match, Sequence, override +import git + from .bots import Bot, Goal, OperationHook, Toolbox from .common import random_id from .prompt import PromptRenderer, TemplatedPrompt from .store import Store, sql - _logger = logging.getLogger(__name__) diff --git a/src/git_draft/editor.py b/src/git_draft/editor.py index 0cc148c..7327b61 100644 --- a/src/git_draft/editor.py +++ b/src/git_draft/editor.py @@ -6,7 +6,6 @@ import sys import tempfile - _default_editors = ["vim", "emacs", "nano"] diff --git a/src/git_draft/prompt.py b/src/git_draft/prompt.py index c776708..1cb4076 100644 --- a/src/git_draft/prompt.py +++ b/src/git_draft/prompt.py @@ -1,13 +1,13 @@ """Prompt templating support""" import dataclasses +from typing import Mapping, Self + import git import jinja2 -from typing import Mapping, Self from .common import Config, package_root - _prompt_root = package_root / "prompts" diff --git a/src/git_draft/store.py b/src/git_draft/store.py index 614c246..0b12e9c 100644 --- a/src/git_draft/store.py +++ b/src/git_draft/store.py @@ -8,7 +8,6 @@ from .common import ensure_state_home, package_root - sqlite3.register_adapter(datetime, lambda d: d.isoformat()) sqlite3.register_converter( "timestamp", lambda v: datetime.fromisoformat(v.decode()) diff --git a/tests/git_draft/bots/__init___test.py b/tests/git_draft/bots/__init___test.py index f9749eb..3fa76fc 100644 --- a/tests/git_draft/bots/__init___test.py +++ b/tests/git_draft/bots/__init___test.py @@ -1,5 +1,6 @@ import importlib import sys + import pytest import git_draft.bots as sut diff --git a/tests/git_draft/bots/common_test.py b/tests/git_draft/bots/common_test.py index 95dc794..052307a 100644 --- a/tests/git_draft/bots/common_test.py +++ b/tests/git_draft/bots/common_test.py @@ -1,7 +1,8 @@ from pathlib import PurePosixPath -import pytest import unittest.mock +import pytest + import git_draft.bots.common as sut diff --git a/tests/git_draft/common_test.py b/tests/git_draft/common_test.py index 042dc7c..7cd44f6 100644 --- a/tests/git_draft/common_test.py +++ b/tests/git_draft/common_test.py @@ -1,8 +1,9 @@ import logging from pathlib import Path -import pytest import textwrap +import pytest + import git_draft.common as sut diff --git a/tests/git_draft/conftest.py b/tests/git_draft/conftest.py index f3b58f5..bb2e43d 100644 --- a/tests/git_draft/conftest.py +++ b/tests/git_draft/conftest.py @@ -1,5 +1,6 @@ from pathlib import Path from typing import Iterator + import git import pytest diff --git a/tests/git_draft/drafter_test.py b/tests/git_draft/drafter_test.py index db2e988..fcf432c 100644 --- a/tests/git_draft/drafter_test.py +++ b/tests/git_draft/drafter_test.py @@ -1,8 +1,9 @@ -import git from pathlib import Path, PurePosixPath -import pytest from typing import Sequence +import git +import pytest + from git_draft.bots import Action, Bot, Goal, Toolbox import git_draft.drafter as sut from git_draft.prompt import TemplatedPrompt @@ -183,6 +184,12 @@ def test_revert_restores_worktree(self) -> None: assert self._read("p1.txt") == "a1" assert self._read("p2.txt") == "b1" + def test_revert_discards_unused_files(self) -> None: + self._drafter.generate_draft("hello", FakeBot()) + assert self._read("PROMPT") is None + self._drafter.revert_draft() + assert self._read("PROMPT") is None + def test_revert_keeps_untouched_files(self) -> None: class CustomBot(Bot): def act(self, _goal: Goal, toolbox: Toolbox) -> Action: diff --git a/tests/git_draft/editor_test.py b/tests/git_draft/editor_test.py index f6dd556..5ff6278 100644 --- a/tests/git_draft/editor_test.py +++ b/tests/git_draft/editor_test.py @@ -1,7 +1,8 @@ -import pytest import shutil import subprocess +import pytest + import git_draft.editor as sut