Skip to content

Commit

Permalink
Merge pull request #1188 from dandi/findtop
Browse files Browse the repository at this point in the history
RF/BF: make find_parent_directory_containing operate on absolute path
  • Loading branch information
yarikoptic committed Jan 26, 2023
2 parents 10921e3 + ffbe377 commit e2755fe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dandi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,20 @@ def find_parent_directory_containing(
) -> Optional[Path]:
"""Find a directory, on the path to 'path' containing filename
if no 'path' - path from cwd
Returns None if no such found, pathlib's Path to the directory if found
if no 'path' - path from cwd. If 'path' is not absolute, absolute path
is taken assuming relative to cwd.
Returns None if no such found, pathlib's Path (absolute) to the directory
if found.
"""
if not path:
path = Path.cwd()
else: # assure pathlib object
path = Path(path)

if not path.is_absolute():
path = path.absolute()

while True:
if (path / filename).exists():
return path
Expand Down

0 comments on commit e2755fe

Please sign in to comment.