Skip to content

Commit

Permalink
Merge pull request #259 from datalad/issue-256-subpath-error
Browse files Browse the repository at this point in the history
Fix traverser-error on unresolved top_level_dir path argument
  • Loading branch information
christian-monch authored Jun 22, 2022
2 parents 64b7270 + 481d8f5 commit 34c2e6e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datalad_metalad/pipeline/provider/datasettraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self,
raise ValueError(f"{item_type.lower()} is not a known item_type. "
f"Known types are: {', '.join(known_types)}")

self.top_level_dir = Path(top_level_dir).absolute()
self.top_level_dir = Path(top_level_dir).absolute().resolve()
self.item_set = self.name_to_item_set[item_type.lower()]
self.traverse_sub_datasets = traverse_sub_datasets
self.root_dataset = require_dataset(self.top_level_dir,
Expand Down
14 changes: 13 additions & 1 deletion datalad_metalad/pipeline/provider/tests/test_datasettraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,32 @@


@with_tempfile(mkdir=True)
def test_relative_top_level_dir(temp_dir: str):
def test_relative_and_unresolved_top_level_dir(temp_dir: str):
relative_path_str = "./some/path/dataset_0"
unresolved_path = "./some/path/../path/dataset_0"

dataset_path = Path(temp_dir) / relative_path_str
dataset_path.mkdir(parents=True)
create_dataset_proper(dataset_path)

old_path = Path.cwd()
os.chdir(str(temp_dir))

# check relative paths
traverser = DatasetTraverser(
top_level_dir=relative_path_str,
item_type="both"
)
assert_equal(traverser.fs_base_path, dataset_path)

# check unresolved paths
traverser = DatasetTraverser(
top_level_dir=Path(temp_dir) / unresolved_path,
item_type="both"
)

tuple(traverser.next_object())
assert_equal(traverser.fs_base_path, dataset_path.resolve())

# prevent teardown error due to modified working directory
os.chdir(str(old_path))
Empty file.

0 comments on commit 34c2e6e

Please sign in to comment.