Skip to content

Commit

Permalink
Support providing directory in file list (NVIDIA#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
edknv authored Dec 10, 2024
1 parent 81ef3e7 commit 0023693
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 7 additions & 8 deletions client/src/nv_ingest_client/util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,13 @@ def generate_matching_files(file_sources):
It yields each matching file path, allowing for efficient processing of potentially large
sets of files.
"""
files = [
file_path
for pattern in file_sources
for file_path in glob.glob(pattern, recursive=True)
if os.path.isfile(file_path)
]
for file_path in files:
yield file_path
for pattern in file_sources:
if os.path.isdir(pattern):
pattern = os.path.join(pattern, "*")

for file_path in glob.glob(pattern, recursive=True):
if os.path.isfile(file_path):
yield file_path


def create_job_specs_for_batch(files_batch: List[str]) -> List[JobSpec]:
Expand Down
11 changes: 11 additions & 0 deletions tests/nv_ingest_client/util/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ def test_generate_matching_files(patterns, mock_files, expected):
assert list(generate_matching_files(patterns)) == expected


def test_generate_matching_directory():
patterns = ["docs"]
mock_files = ["docs/README.md", "docs/CHANGES.md"]
expected = ["docs/README.md", "docs/CHANGES.md"]
with patch("glob.glob", return_value=mock_files), patch(
"os.path.isfile", side_effect=lambda path: path in mock_files
), patch("os.path.isdir", side_effect=lambda path: path == "docs"):

assert list(generate_matching_files(patterns)) == expected


def test_filter_function_kwargs_with_matching_kwargs():
def sample_func(a, b, c):
pass
Expand Down

0 comments on commit 0023693

Please sign in to comment.