Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues: #274, #280 #282

Merged
merged 3 commits into from
Sep 19, 2023
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
6 changes: 6 additions & 0 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,13 @@ def count_files():

def iterate_files():
for directory, pattern in files:
p = pathlib.Path(directory)
if not p.exists() or not p.is_dir():
# fixes issue/274 - raise error if directory does not exist
raise click.UsageError(f"Invalid directory: {directory}")
for path in pathlib.Path(directory).glob(pattern):
if path.is_dir():
continue # fixed issue/280 - skip directories
relative = path.relative_to(directory)
content = None
if binary:
Expand Down
16 changes: 15 additions & 1 deletion tests/test_embed_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def test_embed_multi_files(multi_files, scenario):
("nested/two.txt", b"two"),
("nested/more/three.txt", b"three"),
# This tests the fallback to latin-1 encoding:
("nested/more/ignored.ini", b"Has weird \x96 character"),
("nested/more.txt/ignored.ini", b"Has weird \x96 character"),
):
path = pathlib.Path(files / filename)
path.parent.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -483,6 +483,20 @@ def test_embed_multi_files(multi_files, scenario):
]


@pytest.mark.parametrize(
"args,expected_error",
((["not-a-dir", "*.txt"], "Invalid directory: not-a-dir"),),
)
def test_embed_multi_files_errors(multi_files, args, expected_error):
runner = CliRunner()
result = runner.invoke(
cli,
["embed-multi", "files", "-m", "embed-demo", "--files"] + args,
)
assert result.exit_code == 2
assert expected_error in result.output


@pytest.mark.parametrize(
"extra_args,expected_error",
(
Expand Down