Skip to content

Commit

Permalink
fix for cloud paths
Browse files Browse the repository at this point in the history
The _check_path_matches_patterns function was failing for cloud (e.g.
s3, gc3) URIs.

 1) the path.relative_to() function doesn't work for cloud URIs
(it just returns the original).
 2) combining Path('/') with the result of relative_to now also throws
an error when using cloud (or non-posix) paths.

This fix drops the uri prefix by using .path to get the posix-like
part of the path, so that the regex check works as expected.
  • Loading branch information
akhanf committed Oct 14, 2024
1 parent eb2f926 commit a9b32a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bids/layout/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,17 @@ def _extract_entities(bidsfile, entities):

def _check_path_matches_patterns(path, patterns, root=None):
"""Check if the path matches at least one of the provided patterns. """

if not patterns:
return False

path = path.absolute()
if root is not None:
path = Path("/") / path.relative_to(root)

if isinstance(path,Path):
path = Path("/") / Path(path.path).relative_to(Path(root.path))
else:
path = Path("/") / path.relative_to(root)

# Path now can be downcast to str
path = str(path)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import versioneer

setup(
version=versioneer.get_version(),
version="0.17.2-dev",
cmdclass=versioneer.get_cmdclass(),
)

0 comments on commit a9b32a1

Please sign in to comment.