Paths and Files¶
resolve
¶
Resolve a logical location to a filesystem path.
Relative locations are resolved below root. Absolute locations are
returned unchanged, which lets callers pass explicit local paths when they
already have them.
Parameters:
-
location(str | Path | None, default:None) –Relative or absolute path-like location. If omitted, the store root is returned.
Returns:
-
str–Resolved filesystem path as a string.
Source code in batgrad/storage/local.py
create_dir
¶
Create a directory, including missing parents.
Parameters:
Source code in batgrad/storage/local.py
delete_dir
¶
Delete a directory tree.
Parameters:
-
location(str | Path) –Relative or absolute directory location to delete.
-
missing_ok(bool, default:True) –Return silently when the directory does not exist.
Raises:
-
FileNotFoundError–If the directory is missing and
missing_okis false. -
NotADirectoryError–If the resolved location exists but is not a directory.
Source code in batgrad/storage/local.py
delete_file
¶
Delete a file.
Parameters:
-
location(str | Path) –Relative or absolute file location to delete.
-
missing_ok(bool, default:True) –Return silently when the file does not exist.
Raises:
-
FileNotFoundError–If the file is missing and
missing_okis false. -
IsADirectoryError–If the resolved location exists but is not a file.
Source code in batgrad/storage/local.py
list_files
¶
List non-hidden files below a store location.
Files are matched with pathlib.Path.rglob, returned as sorted POSIX
paths relative to root, and skipped when any path component below
location starts with ..
Parameters:
-
location(str | Path | None, default:None) –Directory to search. Defaults to the store root.
-
pattern(str, default:'*') –Recursive glob pattern, such as
"*.xlsx"or"**/*.parquet".
Returns:
Raises:
-
FileNotFoundError–If
locationis missing or is not a directory.
Examples:
Use the dataset ingest spec to find Pozzato raw Excel files while
excluding paths such as README.xlsx:
>>> paths = []
>>> for pattern in raw_spec.included_file_patterns:
... paths.extend(
... path
... for path in store.list_files(raw_root, pattern=pattern)
... if raw_spec.is_included_file(path)
... )
Source code in batgrad/storage/local.py
local_file
¶
Yield a concrete local path for a logical store location.
Parameters:
Yields:
-
Path–Resolved local
pathlib.Path.
Examples:
The Pozzato raw adapter uses this to pass a local Excel path to
fastexcel: