Skip to content

Commit

Permalink
- added check for sources in --module-dir (old --source), suggesting a
Browse files Browse the repository at this point in the history
  subdirectory if no sources are found, to make it harder to use it wrong;
  • Loading branch information
jaltmayerpizzorno committed Aug 3, 2024
1 parent e66ecfe commit 5de606f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/coverup/coverup.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ def positive_int(value):
if not args.model:
ap.error('Specify the model to use with --model')

if not list(args.module_dir.glob("*.py")):
sources = sorted(args.module_dir.glob("**/*.py"), key=lambda p: len(p.parts))
suggestion = sources[0].parent if sources else None

try:
args.module_dir = args.module_dir.relative_to(Path.cwd())
suggestion = suggestion.relative_to(Path.cwd()) if suggestion else None
except ValueError:
pass

ap.error(f'No Python sources found in "{args.module_dir}"' +
(f'; did you mean "{suggestion}"?' if suggestion else '.'))

return args


Expand Down
1 change: 1 addition & 0 deletions tests/test_coverup_25.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ def test_parse_args_with_source_files(tmp_path):
tests_dir.mkdir()
source_dir = tmp_path / "source"
source_dir.mkdir()
(source_dir / "m.py").touch()
args = parse_args([str(source_file), '--tests-dir', str(tests_dir), '--source-dir', str(source_dir), '--model', 'gpt-4'])
assert args.source_files[0] == source_file.resolve()
2 changes: 2 additions & 0 deletions tests/test_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_gpt4_v1_relative_file_name(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

(tmp_path / "lib" / "ansible").mkdir(parents=True)
(tmp_path / "lib" / "ansible" / "__init__.py").touch()
(tmp_path / "tests").mkdir(parents=True)

from coverup.coverup import parse_args
Expand Down Expand Up @@ -42,6 +43,7 @@ def test_claude_relative_file_name(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

(tmp_path / "lib" / "ansible").mkdir(parents=True)
(tmp_path / "lib" / "ansible" / "__init__.py").touch()
(tmp_path / "tests").mkdir(parents=True)

from coverup.coverup import parse_args
Expand Down

0 comments on commit 5de606f

Please sign in to comment.