Skip to content

Commit

Permalink
Merge pull request #1355 from dandi/no-dirsep
Browse files Browse the repository at this point in the history
find_files: Simplify check for VCS and DataLad paths
  • Loading branch information
yarikoptic authored Nov 16, 2023
2 parents 7dd2a1b + 56b1003 commit 3253e1f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions dandi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,7 @@ def load_jsonl(filename: AnyPath) -> list:
return list(map(json.loads, f))


_encoded_dirsep = re.escape(os.sep)
_VCS_REGEX = (
rf"{_encoded_dirsep}\.(?:git|gitattributes|svn|bzr|hg)(?:{_encoded_dirsep}|$)"
)
_DATALAD_REGEX = rf"{_encoded_dirsep}\.(?:datalad)(?:{_encoded_dirsep}|$)"
_VCS_NAMES = {".git", ".gitattributes", ".svn", ".bzr", ".hg"}


def find_files(
Expand Down Expand Up @@ -293,9 +289,10 @@ def exclude_path(path: str) -> bool:
path = path.rstrip(op.sep)
if exclude and re.search(exclude, path):
return True
if exclude_vcs and re.search(_VCS_REGEX, path):
parts = Path(path).parts
if exclude_vcs and any(p in _VCS_NAMES for p in parts):
return True
if exclude_datalad and re.search(_DATALAD_REGEX, path):
if exclude_datalad and any(p == ".datalad" for p in parts):
return True
return False

Expand Down

0 comments on commit 3253e1f

Please sign in to comment.