Skip to content

Commit

Permalink
skip root dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
aulemahal committed Oct 21, 2024
1 parent 62fe16f commit b4dc0de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ New features and enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* ``xs.io.make_toc`` now includes the global attributes of the dataset after the information about the variables. (:pull:`473`).
* New function ``xs.get_warming_level_from_period`` to get the warming level associated with a given time horizon. (:pull:`474`).
* Added ability to skip whole folders to ``xs.parse_directory`` with argument ``skip_dirs``.
* Added ability to skip whole folders to ``xs.parse_directory`` with argument ``skip_dirs``. (:pull:`478`, :pull:`479`).

Breaking changes
^^^^^^^^^^^^^^^^
Expand Down
13 changes: 10 additions & 3 deletions src/xscen/catutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ def _find_assets(
# Split zarr subdirectories from next iteration
zarrs = []
for dr in deepcopy(alldirs):
fdr = Path(top).joinpath(dr)
if dr.endswith(".zarr"):
zarrs.append(dr)
alldirs.remove(dr)
if Path(top).joinpath(dr) in skip_dirs:
if fdr in skip_dirs:
logger.debug("Skipping %s", fdr)
alldirs.remove(dr)

if (
Expand Down Expand Up @@ -323,6 +325,12 @@ def _parse_dir( # noqa: C901
exts = {Path(patt).suffix for patt in patterns}
comp_patterns = list(map(_compile_pattern, patterns))
checks = checks or []
parsed = []

root = Path(root)
if any([(skd in root.parents) or (skd == root) for skd in skip_dirs]):
logger.debug("Skipping %s", root)
return parsed

# Multithread, communicating via FIFO queues.
# This thread walks the directory
Expand All @@ -334,7 +342,6 @@ def _parse_dir( # noqa: C901
# Usually, the walking is the bottleneck.
q_found = queue.Queue()
q_checked = queue.Queue()
parsed = []

def check_worker():
# Worker that processes the checks.
Expand Down Expand Up @@ -517,7 +524,7 @@ def parse_directory( # noqa: C901
A glob pattern for path matching to accelerate the parsing of a directory tree if only a subtree is needed.
Only folders matching the pattern are parsed to find datasets.
skip_dirs : list of str or Paths, optional
A list of folders that will be removed from the search.
A list of folders that will be removed from the search, should be absolute.
xr_open_kwargs: dict
If needed, arguments to send xr.open_dataset() when opening the file to read the attributes.
only_official_columns: bool
Expand Down

0 comments on commit b4dc0de

Please sign in to comment.