本文整理汇总了Python中datalad.distribution.dataset.Dataset.annotate_paths方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.annotate_paths方法的具体用法?Python Dataset.annotate_paths怎么用?Python Dataset.annotate_paths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.distribution.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.annotate_paths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_annotate_paths
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import annotate_paths [as 别名]
def test_annotate_paths(dspath, nodspath):
# this test doesn't use API`remove` to avoid circularities
ds = make_demo_hierarchy_datasets(dspath, demo_hierarchy)
ds.save(recursive=True)
ok_clean_git(ds.path)
with chpwd(dspath):
# with and without an explicitly given path the result is almost the
# same inside a dataset
without_path = annotate_paths(on_failure='ignore')
pwd_res = annotate_paths(path='.', on_failure='ignore')
assert_result_count(
without_path, 1, type='dataset', path=dspath)
assert_result_count(
pwd_res, 1, type='dataset', path=dspath, orig_request='.',
raw_input=True)
# make sure going into a subdataset vs giving it as a path has no
# structural impact
eq_(
[{k: v for k, v in ap.items()
if k not in ('registered_subds', 'raw_input', 'orig_request', 'refds')}
for ap in annotate_paths(path='b', recursive=True)],
[{k: v for k, v in ap.items()
if k not in ('registered_subds', 'raw_input', 'orig_request', 'refds')}
for ap in annotate_paths(dataset='b', recursive=True)])
# now do it again, pointing to the ds directly
res = ds.annotate_paths(on_failure='ignore')
# no request, no refds, but otherwise the same
eq_(len(res), len(pwd_res))
eq_({k: pwd_res[0][k] for k in pwd_res[0]
if k in ('path', 'type', 'action', 'status')},
{k: res[0][k] for k in res[0]
if k not in ('refds',)})
# will refuse a path that is not a dataset as refds
res = annotate_paths(dataset=nodspath, on_failure='ignore')
assert_result_count(
res, 1, status='error', path=nodspath,
message='given reference dataset is not a dataset')
# recursion with proper base dataset
parentds = Dataset(opj(dspath, 'a'))
base_res = parentds.annotate_paths(recursive=True)
# needs to find 'aa' and the base
assert_result_count(base_res, 2)
assert_result_count(base_res, 2, type='dataset')
assert_result_count(
base_res, 1, type='dataset', parentds=parentds.path,
path=opj(parentds.path, 'aa'), status='')
# same recursion but without a base dataset
res = annotate_paths(path=opj(dspath, 'a'), recursive=True)
# needs to find 'aa' and 'a' again
assert_result_count(res, 2)
eq_(res[-1],
{k: base_res[-1][k] for k in base_res[-1]
if k not in ('refds',)})
assert_result_count(
res, 1, type='dataset', status='',
# it does not auto-discover parent datasets without force or a refds
#parentds=parentds.path,
path=parentds.path)
# but we can force parent discovery
res = parentds.annotate_paths(
path=opj(dspath, 'a'), recursive=True, force_parentds_discovery=True)
assert_result_count(res, 2)
assert_result_count(
res, 1, type='dataset', status='', parentds=dspath,
path=parentds.path)
# recursion with multiple disjoint seeds, no common base
eq_([basename(p) for p in annotate_paths(
path=[opj(dspath, 'a'), opj(dspath, 'b', 'bb', 'bba')], recursive=True,
result_xfm='paths')],
['a', 'aa', 'bba', 'bbaa'])
# recursion with partially overlapping seeds, no duplicate results
eq_([basename(p) for p in annotate_paths(
path=[opj(dspath, 'b'), opj(dspath, 'b', 'bb', 'bba')], recursive=True,
result_xfm='paths')],
['b', 'ba', 'bb', 'bba', 'bbaa'])
# get straight from a file
fpath = opj('a', 'aa', 'file_aa')
res = ds.annotate_paths(fpath)
assert_result_count(res, 1)
assert_result_count(
res, 1, orig_request=fpath, raw_input=True, type='file',
path=opj(ds.path, fpath), parentds=opj(ds.path, 'a', 'aa'), status='')
# now drop it
dropres = ds.drop(fpath, check=False)
assert_result_count(dropres, 1, path=res[0]['path'], status='ok')
# ask for same file again, use 'notneeded' for unavailable to try trigger
# any difference
droppedres = ds.annotate_paths(fpath, unavailable_path_status='notneeded')
# but we get the same result
eq_(res, droppedres)
# now try the same on an uninstalled dataset
subdspath = opj('b', 'bb')
# before
#.........这里部分代码省略.........