Skip to content

Commit

Permalink
Add option to process all files in a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Dec 13, 2024
1 parent de374e8 commit d970cfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/too/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ def process(
list[pathlib.Path] | None,
typer.Argument(
exists=True,
dir_okay=False,
help="The list of files to process.",
dir_okay=True,
help="The list of files to process. If a directory is passed, all the "
"files in the directory will be processed.",
),
] = None,
verbose: Annotated[
Expand Down Expand Up @@ -121,9 +122,17 @@ def process(
)

if files is not None and len(files) > 0:
log.debug("Reading input files.")
targets = polars.DataFrame({}, schema=too_dtypes)
process_files: list[pathlib.Path] = []
for file in files:
if file.is_dir():
process_files.extend(file.glob("*.csv"))
process_files.extend(file.glob("*.parquet"))
else:
process_files.append(file)

log.debug(f"Reading {len(files)} input file(s).")
targets = polars.DataFrame({}, schema=too_dtypes)
for file in process_files:
targets = targets.vstack(read_too_file(file, cast=True))

log.info("Loading targets into the database.")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def test_cli_update(files_path: pathlib.Path, too_mock: polars.DataFrame):
"sdss5db_too_test",
"--write-log",
str(files_path / "too.log"),
str(files_path / "too2.csv"),
str(files_path / "too3.parquet"),
str(files_path),
],
)

Expand Down

0 comments on commit d970cfe

Please sign in to comment.