Skip to content

Commit

Permalink
change to --auto, write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bpinsard committed Nov 15, 2024
1 parent 03e81af commit c905746
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
14 changes: 7 additions & 7 deletions datalad/distribution/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ def _get_targetpaths(ds, content, refds_path, source, jobs, data):
(data == 'auto-if-wanted') and
ds_repo.get_preferred_content('wanted', 'here')
):
lgr.debug("Invoking get --want-get")
get_opts.append('--want-get')
lgr.debug("Invoking get --auto")
get_opts.append('--auto')

try:
results = ds_repo.get(
Expand Down Expand Up @@ -872,12 +872,12 @@ class Get(Interface):
data=Parameter(
args=("--data",),
doc="""what to do with (annex'ed) data. 'anything' would cause
transfer of all annexed content, 'nothing' would avoid call to
`git annex copy` altogether. 'auto' would use 'git annex copy' with
'--auto' thus transferring only data which would satisfy "wanted"
or "numcopies" settings for the remote (thus "nothing" otherwise).
fetching of all annexed content, 'nothing' would avoid call to
`git annex get` altogether. 'auto' would use 'git annex get' with
'--auto' thus fetching only data which would satisfy "wanted"
or "numcopies" settings for the local copy (thus "nothing" otherwise).
'auto-if-wanted' would enable '--auto' mode only if there is a
"wanted" setting for the remote, and transfer 'anything' otherwise.
"wanted" setting for the remote, and fetching 'anything' otherwise.
""",
constraints=EnsureChoice(
'anything', 'nothing', 'auto', 'auto-if-wanted')),
Expand Down
43 changes: 43 additions & 0 deletions datalad/distribution/tests/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
known_failure_githubci_win,
known_failure_windows,
ok_,
nok_,
serve_path_via_http,
skip_if_adjusted_branch,
skip_if_on_windows,
Expand Down Expand Up @@ -823,3 +824,45 @@ def test_get_non_existing(origin_path=None, clone_path=None):

assert_result_count(res, 1, status="impossible",
message="path does not exist")


@with_tree(tree={'file1.txt': 'whatever 1',
'file2.txt': 'whatever 2',
'file3.txt': 'whatever 3',
'file4.txt': 'whatever 4'})
@with_tempfile(mkdir=True)
def test_get_data_auto_wanted_anything(path=None, ds_dir=None):
from os import listdir
file_list = [f for f in listdir(path) if not f.startswith('.')]
# prepare origin
origin = Dataset(path).create(force=True)
origin.save(file_list, message="initial")

ds = install(
ds_dir, source=path,
result_xfm='datasets', return_type='item-or-list')

# no content present:
ok_(not any(ds.repo.file_has_content(file_list)))

ds.repo.set_preferred_content('wanted', 'exclude=file[3-4].txt', 'here')
result = ds.get('.', data='auto')

eq_(set([basename(item.get('path')) for item in result]),
{'file1.txt', 'file2.txt'})
ok_(all(ds.repo.file_has_content(['file1.txt', 'file2.txt'])))
nok_(any(ds.repo.file_has_content(['file3.txt', 'file4.txt'])))

ds.drop('.')

result = ds.get('.', data='auto-if-wanted')

eq_(set([basename(item.get('path')) for item in result]),
{'file1.txt', 'file2.txt'})
ok_(all(ds.repo.file_has_content(['file1.txt', 'file2.txt'])))
nok_(any(ds.repo.file_has_content(['file3.txt', 'file4.txt'])))

result = ds.get('.', data='anything')
eq_(set([basename(item.get('path')) for item in result]),
{'file3.txt', 'file4.txt'})
ok_(all(ds.repo.file_has_content(file_list)))

0 comments on commit c905746

Please sign in to comment.