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
18 changes: 17 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -48,14 +49,18 @@ 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"},
]

[tool.poe.tasks.lint]
help = "lint source code"
sequence = [
{cmd="isort --check ${args}"},
{cmd="black --check --quiet ${args}"},
{cmd="flake8 ${args}"},
{cmd="mypy ${args}"},
Expand Down Expand Up @@ -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"

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


Expand Down
2 changes: 1 addition & 1 deletion src/git_draft/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/git_draft/drafter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import dataclasses
import git
import json
import logging
from pathlib import PurePosixPath
Expand All @@ -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__)


Expand Down
1 change: 0 additions & 1 deletion src/git_draft/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
import tempfile


_default_editors = ["vim", "emacs", "nano"]


Expand Down
4 changes: 2 additions & 2 deletions src/git_draft/prompt.py
Original file line number Diff line number Diff line change
@@ -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"


Expand Down
1 change: 0 additions & 1 deletion src/git_draft/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions tests/git_draft/bots/__init___test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib
import sys

import pytest

import git_draft.bots as sut
Expand Down
3 changes: 2 additions & 1 deletion tests/git_draft/bots/common_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import PurePosixPath
import pytest
import unittest.mock

import pytest

import git_draft.bots.common as sut


Expand Down
3 changes: 2 additions & 1 deletion tests/git_draft/common_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
from pathlib import Path
import pytest
import textwrap

import pytest

import git_draft.common as sut


Expand Down
1 change: 1 addition & 0 deletions tests/git_draft/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from typing import Iterator

import git
import pytest

Expand Down
11 changes: 9 additions & 2 deletions tests/git_draft/drafter_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion tests/git_draft/editor_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import shutil
import subprocess

import pytest

import git_draft.editor as sut


Expand Down