diff --git a/src/coverup/coverup.py b/src/coverup/coverup.py index 06d26a9..8955237 100644 --- a/src/coverup/coverup.py +++ b/src/coverup/coverup.py @@ -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 diff --git a/tests/test_coverup_25.py b/tests/test_coverup_25.py index f38fb1d..fc22d18 100644 --- a/tests/test_coverup_25.py +++ b/tests/test_coverup_25.py @@ -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() diff --git a/tests/test_prompt.py b/tests/test_prompt.py index 82ea33e..189167c 100644 --- a/tests/test_prompt.py +++ b/tests/test_prompt.py @@ -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 @@ -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