Skip to content

Commit

Permalink
Merge pull request #4504 from kyleam/addurls-dotslash-confusion
Browse files Browse the repository at this point in the history
addurls: Don't trip over "./" in the file name format
  • Loading branch information
yarikoptic committed May 14, 2020
2 parents f03c67a + 0dd7cb8 commit debd468
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions datalad/plugin/addurls.py
Expand Up @@ -865,10 +865,9 @@ def __call__(dataset, urlfile, urlformat, filenameformat,
if row["subpath"]:
ds_current = Dataset(os.path.join(ds.path,
row["subpath"]))
ds_filename = os.path.relpath(filename_abs, ds_current.path)
else:
ds_current = ds
ds_filename = row["filename"]
ds_filename = os.path.relpath(filename_abs, ds_current.path)
row.update({"filename_abs": filename_abs,
"ds": ds_current,
"ds_filename": ds_filename})
Expand Down
18 changes: 11 additions & 7 deletions datalad/plugin/tests/test_addurls.py
Expand Up @@ -466,25 +466,29 @@ def get_annex_commit_counts():

@with_tempfile(mkdir=True)
def test_addurls_unbound_dataset(self, path):
ds = Dataset(path).create(force=True)

def check(subpath, dataset_arg, url_file):
subdir = op.join(path, subpath)
def check(ds, dataset_arg, url_file, fname_format):
subdir = op.join(ds.path, "subdir")
os.mkdir(subdir)
with chpwd(subdir):
shutil.copy(self.json_file, "in.json")
addurls(dataset_arg, url_file, "{url}", "{name}")
addurls(dataset_arg, url_file, "{url}", fname_format)
# Files specified in the CSV file are always relative to the
# dataset.
for fname in ["a", "b", "c"]:
ok_exists(op.join(ds.path, fname))

# The input file is relative to the current working directory, as
# with other commands.
check("subdir0", None, "in.json")
ds0 = Dataset(op.join(path, "ds0")).create()
check(ds0, None, "in.json", "{name}")
# Likewise the input file is relative to the current working directory
# if a string dataset argument is given.
check("subdir1", ds.path, "in.json")
ds1 = Dataset(op.join(path, "ds1")).create()
check(ds1, ds1.path, "in.json", "{name}")
# A leading "./" doesn't confuse addurls() into downloading the file
# into the subdirectory.
ds2 = Dataset(op.join(path, "ds2")).create()
check(ds2, None, "in.json", "./{name}")

@with_tempfile(mkdir=True)
def test_addurls_create_newdataset(self, path):
Expand Down

0 comments on commit debd468

Please sign in to comment.