Skip to content

Commit 3bb32db

Browse files
authored
refactor: modularize assistants (#12)
1 parent 452f9ea commit 3bb32db

File tree

11 files changed

+233
-114
lines changed

11 files changed

+233
-114
lines changed

poetry.lock

Lines changed: 34 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1+
[project]
2+
name = 'git-draft'
3+
description = 'Version-controlled code assistant'
4+
authors = [{name='Matthieu Monsch', email='[email protected]'}]
5+
license = 'MIT'
6+
readme = 'README.md'
7+
dynamic = ['version']
8+
requires-python = '>=3.12'
9+
dependencies = [
10+
'gitpython >=3.1.44,<4',
11+
]
12+
13+
[project.optional-dependencies]
14+
openai = ['openai >=1.64.0,<2']
15+
16+
[project.scripts]
17+
git-draft = 'git_draft.__main__:main'
18+
19+
[project.urls]
20+
repository = 'https://github.com/mtth/git-draft'
21+
documentation = 'https://mtth.github.io/git-draft'
22+
123
[build-system]
224
requires = ['poetry-core']
325
build-backend = 'poetry.core.masonry.api'
426

27+
# Poetry
28+
529
[tool.poetry]
6-
name = 'git-draft'
730
version = '0.0.0' # Set programmatically
8-
description = 'Version-controlled code assistant'
9-
authors = ['Matthieu Monsch <[email protected]>']
10-
readme = 'README.md'
11-
repository = 'https://github.com/mtth/git-draft'
12-
packages = [{include = 'git_draft', from = 'src'}]
13-
14-
[tool.poetry.scripts]
15-
git-draft = 'git_draft.__main__:main'
31+
packages = [{include='git_draft', from='src'}]
1632

1733
[tool.poetry.dependencies]
18-
gitpython = '^3.1.44'
19-
openai = '^1.64.0'
2034
python = '>=3.12,<4'
2135

2236
[tool.poetry.group.dev.dependencies]
@@ -27,15 +41,7 @@ mypy = '^1.2.0'
2741
poethepoet = '^0.25.0'
2842
pytest = '^7.1.2'
2943

30-
[tool.black]
31-
line-length = 79
32-
include = '\.py$'
33-
34-
[tool.flake8]
35-
ignore = ['E203', 'E501', 'E704', 'W503']
36-
37-
[tool.mypy]
38-
disable_error_code = 'import-untyped'
44+
# Poe
3945

4046
[tool.poe.tasks.fix]
4147
help = 'format source code'
@@ -55,5 +61,17 @@ args = [
5561
{name='args', help='target folders', positional=true, multiple=true, default='src tests'},
5662
]
5763

64+
# Other tools
65+
66+
[tool.black]
67+
line-length = 79
68+
include = '\.py$'
69+
70+
[tool.flake8]
71+
ignore = ['E203', 'E501', 'E704', 'W503']
72+
73+
[tool.mypy]
74+
disable_error_code = 'import-untyped'
75+
5876
[tool.pytest.ini_options]
5977
log_level = 'DEBUG'

src/git_draft/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
from .assistant import Assistant, OpenAIAssistant
2-
from .common import open_editor
3-
from .manager import Manager, enclosing_repo
1+
from .assistants import Assistant, Session, Toolbox
42

53
__all__ = [
64
"Assistant",
7-
"OpenAIAssistant",
8-
"Manager",
9-
"enclosing_repo",
10-
"open_editor",
5+
"Session",
6+
"Toolbox",
117
]

src/git_draft/__main__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import sys
66
import textwrap
77

8-
from . import Manager, OpenAIAssistant, enclosing_repo, open_editor
8+
from .assistants import load_assistant
9+
from .common import open_editor
10+
from .manager import Manager, enclosing_repo
911

1012

1113
EPILOG = """\
@@ -39,6 +41,12 @@ def callback(_option, _opt, _value, parser) -> None:
3941
add_command("finalize", help="apply the current draft to the original branch")
4042
add_command("generate", help="draft a new change from a prompt")
4143

44+
parser.add_option(
45+
"-a",
46+
"--assistant",
47+
dest="ASSISTANT",
48+
help="assistant key",
49+
)
4250
parser.add_option(
4351
"-d",
4452
"--delete",
@@ -65,20 +73,21 @@ def callback(_option, _opt, _value, parser) -> None:
6573

6674

6775
def main() -> None:
68-
(opts, args) = parser.parse_args()
76+
(opts, _args) = parser.parse_args()
6977

7078
repo = enclosing_repo()
7179
manager = Manager(repo)
7280

7381
command = getattr(opts, "command", "generate")
7482
if command == "generate":
83+
assistant = load_assistant(opts.assistant, {})
7584
prompt = opts.prompt
7685
if not prompt:
7786
if sys.stdin.isatty():
7887
prompt = open_editor(textwrap.dedent(EDITOR_PLACEHOLDER))
7988
else:
8089
prompt = sys.stdin.read()
81-
manager.generate_draft(prompt, OpenAIAssistant(), reset=opts.reset)
90+
manager.generate_draft(prompt, assistant, reset=opts.reset)
8291
elif command == "finalize":
8392
manager.finalize_draft(delete=opts.delete)
8493
elif command == "discard":

src/git_draft/assistant.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)