本文整理汇总了Python中datalad.distribution.dataset.Dataset.subdatasets方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.subdatasets方法的具体用法?Python Dataset.subdatasets怎么用?Python Dataset.subdatasets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.distribution.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.subdatasets方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nested_create
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_nested_create(path):
# to document some more organic usage pattern
ds = Dataset(path).create()
assert_repo_status(ds.path)
lvl2relpath = op.join('lvl1', 'lvl2')
lvl2path = op.join(ds.path, lvl2relpath)
os.makedirs(lvl2path)
os.makedirs(op.join(ds.path, 'lvl1', 'empty'))
with open(op.join(lvl2path, 'file'), 'w') as f:
f.write('some')
ok_(ds.save())
# Empty directories are filtered out.
assert_repo_status(ds.path, untracked=[])
# later create subdataset in a fresh dir
# WINDOWS FAILURE IS NEXT LINE
subds1 = ds.create(op.join('lvl1', 'subds'))
assert_repo_status(ds.path, untracked=[])
eq_(ds.subdatasets(result_xfm='relpaths'), [op.join('lvl1', 'subds')])
# later create subdataset in an existing empty dir
subds2 = ds.create(op.join('lvl1', 'empty'))
assert_repo_status(ds.path)
# later try to wrap existing content into a new subdataset
# but that won't work
assert_in_results(
ds.create(lvl2relpath, **raw),
status='error',
message=(
'collision with content in parent dataset at %s: %s',
ds.path, [op.join(lvl2path, 'file')]))
# even with force, as to do this properly complicated surgery would need to
# take place
# MIH disable shaky test till proper dedicated upfront check is in-place in `create`
# gh-1725
#assert_in_results(
# ds.create(lvl2relpath, force=True,
# on_failure='ignore', result_xfm=None, result_filter=None),
# status='error', action='add')
# only way to make it work is to unannex the content upfront
ds.repo._run_annex_command('unannex', annex_options=[op.join(lvl2relpath, 'file')])
# nothing to save, git-annex commits the unannex itself, but only on v5
ds.repo.commit()
# still nothing without force
# "err='lvl1/lvl2' already exists in the index"
assert_in_results(
ds.create(lvl2relpath, **raw),
status='error',
message='will not create a dataset in a non-empty directory, use `force` option to ignore')
# XXX even force doesn't help, because (I assume) GitPython doesn't update
# its representation of the Git index properly
ds.create(lvl2relpath, force=True)
assert_in(lvl2relpath, ds.subdatasets(result_xfm='relpaths'))
示例2: test_dirty
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_dirty(path):
for mode in _dirty_modes:
# does nothing without a dataset
handle_dirty_dataset(None, mode)
# placeholder, but not yet created
ds = Dataset(path)
# unknown mode
assert_raises(ValueError, handle_dirty_dataset, ds, 'MADEUP')
# not yet created is very dirty
assert_raises(RuntimeError, handle_dirty_dataset, ds, 'fail')
handle_dirty_dataset(ds, 'ignore')
assert_raises(RuntimeError, handle_dirty_dataset, ds, 'save-before')
# should yield a clean repo
ds.create()
orig_state = ds.repo.get_hexsha()
_check_all_clean(ds, orig_state)
# tainted: untracked
with open(opj(ds.path, 'something'), 'w') as f:
f.write('some')
# we don't want to auto-add untracked files by saving (anymore)
assert_raises(AssertionError, _check_auto_save, ds, orig_state)
# tainted: staged
ds.repo.add('something', git=True)
orig_state = _check_auto_save(ds, orig_state)
# tainted: submodule
# not added to super on purpose!
subds = ds.create('subds')
_check_all_clean(subds, subds.repo.get_hexsha())
ok_clean_git(ds.path)
# subdataset must be added as a submodule!
assert_equal(ds.subdatasets(result_xfm='relpaths'), ['subds'])
示例3: test_create_sub
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_create_sub(path):
ds = Dataset(path)
ds.create()
# 1. create sub and add to super:
subds = ds.create(op.join("some", "what", "deeper"))
ok_(isinstance(subds, Dataset))
ok_(subds.is_installed())
assert_repo_status(subds.path, annex=True)
assert_in(
'submodule.some/what/deeper.datalad-id={}'.format(
subds.id),
ds.repo._git_custom_command(
'',
['git', 'config', '--file', '.gitmodules', '--list'])[0]
)
# subdataset is known to superdataset:
assert_in(op.join("some", "what", "deeper"),
ds.subdatasets(result_xfm='relpaths'))
# and was committed:
assert_repo_status(ds.path)
# subds finds superdataset
ok_(subds.get_superdataset() == ds)
# 2. create sub without adding to super:
subds2 = Dataset(op.join(path, "someother")).create()
ok_(isinstance(subds2, Dataset))
ok_(subds2.is_installed())
assert_repo_status(subds2.path, annex=True)
# unknown to superdataset:
assert_not_in("someother", ds.subdatasets(result_xfm='relpaths'))
# 3. create sub via super:
subds3 = ds.create("third", no_annex=True)
ok_(isinstance(subds3, Dataset))
ok_(subds3.is_installed())
assert_repo_status(subds3.path, annex=False)
assert_in("third", ds.subdatasets(result_xfm='relpaths'))
示例4: test_gh1597
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_gh1597(path):
if 'APPVEYOR' in os.environ:
# issue only happens on appveyor, Python itself implodes
# cannot be reproduced on a real windows box
raise SkipTest(
'this test causes appveyor to crash, reason unknown')
ds = Dataset(path).create()
sub = ds.create('sub')
res = ds.subdatasets()
assert_result_count(res, 1, path=sub.path)
# now modify .gitmodules with another command
ds.subdatasets(contains=sub.path, set_property=[('this', 'that')])
# now modify low-level
with open(op.join(ds.path, '.gitmodules'), 'a') as f:
f.write('\n')
assert_repo_status(ds.path, modified=['.gitmodules'])
ds.save('.gitmodules')
# must not come under annex mangement
assert_not_in(
'key',
ds.repo.annexstatus(paths=['.gitmodules']).popitem()[1])
示例5: __call__
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
#.........这里部分代码省略.........
reported_paths[path] = res
yield res
continue
# check that we only got SUBdatasets
if refds_path and not path_startswith(dspath, refds_path):
res = get_status_dict(**dict(res_kwargs, **path_props))
res['status'] = nondataset_path_status
res['message'] = \
('path not part of the reference dataset at %s', refds_path)
reported_paths[path] = res
yield res
continue
if path_props.get('type', None) == 'file':
# nothing else we can learn about this
res = get_status_dict(**dict(res_kwargs, **path_props))
if 'status' not in res:
res['status'] = ''
reported_paths[path] = res
yield res
continue
containing_ds = None
path_type = path_props.get('type', None)
if parent and force_subds_discovery and (
(path_type == 'dataset' and 'registered_subds' not in path_props) or
path_type == 'directory' or
not lexists(path)):
# if the path doesn't exist, or is labeled a directory, or a dataset even
# a dataset (without this info) -> record whether this is a known subdataset
# to its parent
containing_ds = Dataset(parent)
subdss = containing_ds.subdatasets(
fulfilled=None, recursive=False,
result_xfm=None, result_filter=None, return_type='list')
if path in [s['path'] for s in subdss]:
if path_type == 'directory' or not lexists(path):
# first record that it isn't here, if just a dir or not here at all
path_props['state'] = 'absent'
# this must be a directory, and it is not installed
path_props['type'] = 'dataset'
path_props['registered_subds'] = True
if not lexists(path) or \
(path_props.get('type', None) == 'dataset' and
path_props.get('state', None) == 'absent'):
# not there (yet)
message = unavailable_path_msg if unavailable_path_msg else None
if message and '%s' in message:
message = (message, path)
path_props['message'] = message
res = get_status_dict(**dict(res_kwargs, **path_props))
# assign given status, but only if the props don't indicate a status
# already
res['status'] = path_props.get(
'status', unavailable_path_status)
reported_paths[path] = res
yield res
continue
# we know everything we can, report
res = get_status_dict(**dict(res_kwargs, **path_props))
if 'status' not in res:
res['status'] = ''
reported_paths[path] = res
示例6: test_get_subdatasets
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_get_subdatasets(path):
ds = Dataset(path)
# one more subdataset with a name that could ruin config option parsing
dots = text_type(Path('subdir') / '.lots.of.dots.')
ds.create(dots)
eq_(ds.subdatasets(recursive=True, fulfilled=False, result_xfm='relpaths'), [
'sub dataset1'
])
ds.get('sub dataset1')
eq_(ds.subdatasets(recursive=True, fulfilled=False, result_xfm='relpaths'), [
'sub dataset1/2',
'sub dataset1/sub sub dataset1',
'sub dataset1/subm 1',
])
# obtain key subdataset, so all leaf subdatasets are discoverable
ds.get(opj('sub dataset1', 'sub sub dataset1'))
eq_(ds.subdatasets(result_xfm='relpaths'), ['sub dataset1', dots])
eq_([(r['parentds'], r['path']) for r in ds.subdatasets()],
[(path, opj(path, 'sub dataset1')),
(path, opj(path, dots))])
eq_(ds.subdatasets(recursive=True, result_xfm='relpaths'), [
'sub dataset1',
'sub dataset1/2',
'sub dataset1/sub sub dataset1',
'sub dataset1/sub sub dataset1/2',
'sub dataset1/sub sub dataset1/subm 1',
'sub dataset1/subm 1',
dots,
])
# redo, but limit to specific paths
eq_(
ds.subdatasets(
path=['sub dataset1/2', 'sub dataset1/sub sub dataset1'],
recursive=True, result_xfm='relpaths'),
[
'sub dataset1/2',
'sub dataset1/sub sub dataset1',
'sub dataset1/sub sub dataset1/2',
'sub dataset1/sub sub dataset1/subm 1',
]
)
with chpwd(text_type(ds.pathobj / 'subdir')):
# imitate cmdline invocation w/ no dataset argument
# -> curdir limits the query, when no info is given
eq_(subdatasets(dataset=None,
path=[],
recursive=True,
result_xfm='paths'),
[text_type(ds.pathobj / dots)]
)
# but with a dataset explicitly given, even if just as a path,
# curdir does no limit the query
eq_(subdatasets(dataset=os.pardir,
path=None,
recursive=True,
result_xfm='relpaths'),
['sub dataset1',
'sub dataset1/2',
'sub dataset1/sub sub dataset1',
'sub dataset1/sub sub dataset1/2',
'sub dataset1/sub sub dataset1/subm 1',
'sub dataset1/subm 1',
dots]
)
# uses slow, flexible query
eq_(ds.subdatasets(recursive=True, bottomup=True, result_xfm='relpaths'), [
'sub dataset1/2',
'sub dataset1/sub sub dataset1/2',
'sub dataset1/sub sub dataset1/subm 1',
'sub dataset1/sub sub dataset1',
'sub dataset1/subm 1',
'sub dataset1',
dots,
])
eq_(ds.subdatasets(recursive=True, fulfilled=True, result_xfm='relpaths'), [
'sub dataset1',
'sub dataset1/sub sub dataset1',
dots,
])
eq_([(relpath(r['parentds'], start=ds.path), relpath(r['path'], start=ds.path))
for r in ds.subdatasets(recursive=True)], [
(os.curdir, 'sub dataset1'),
('sub dataset1', 'sub dataset1/2'),
('sub dataset1', 'sub dataset1/sub sub dataset1'),
('sub dataset1/sub sub dataset1', 'sub dataset1/sub sub dataset1/2'),
('sub dataset1/sub sub dataset1', 'sub dataset1/sub sub dataset1/subm 1'),
('sub dataset1', 'sub dataset1/subm 1'),
(os.curdir, dots),
])
# uses slow, flexible query
eq_(ds.subdatasets(recursive=True, recursion_limit=0),
[])
# uses slow, flexible query
eq_(ds.subdatasets(recursive=True, recursion_limit=1, result_xfm='relpaths'),
['sub dataset1', dots])
# uses slow, flexible query
eq_(ds.subdatasets(recursive=True, recursion_limit=2, result_xfm='relpaths'),
[
'sub dataset1',
'sub dataset1/2',
#.........这里部分代码省略.........
示例7: test_recursive_save
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_recursive_save(path):
ds = Dataset(path).create()
# nothing to save
assert_status('notneeded', ds._save())
subds = ds.create('sub')
# subdataset presence already saved
ok_clean_git(ds.path)
subsubds = subds.create('subsub')
assert_equal(
ds.subdatasets(recursive=True, fulfilled=True, result_xfm='paths'),
[subds.path, subsubds.path])
newfile_name = opj(subsubds.path, 'test')
with open(newfile_name, 'w') as f:
f.write('some')
# saves the status change of the subdataset due to the subsubdataset addition
assert_result_values_equal(
ds._save(result_filter=is_ok_dataset),
'path',
[ds.path])
# make the new file known to its dataset
ds.add(newfile_name, save=False)
# but remains dirty because of the uncommited file down below
assert ds.repo.dirty
# auto-add will save nothing deep down without recursive
assert_status('notneeded', ds._save())
assert ds.repo.dirty
# with recursive pick up the change in subsubds
assert_result_values_equal(
ds._save(recursive=True, result_filter=is_ok_dataset),
'path',
[subsubds.path, subds.path, ds.path])
# at this point the entire tree is clean
ok_clean_git(ds.path)
states = [d.repo.get_hexsha() for d in (ds, subds, subsubds)]
# now we save recursively, nothing should happen
res = ds._save(recursive=True)
# we do not get any report from a subdataset, because we detect at the
# very top that the entire tree is clean
assert_result_count(res, 1)
assert_result_count(res, 1, status='notneeded', action='save', path=ds.path)
# now we introduce new files all the way down
create_tree(subsubds.path, {"mike1": 'mike1'})
# because we cannot say from the top if there is anything to do down below,
# we have to traverse and we will get reports for all dataset, but there is
# nothing actually saved
res = ds._save(recursive=True)
assert_result_count(res, 3)
assert_status('notneeded', res)
subsubds_indexed = subsubds.repo.get_indexed_files()
assert_not_in('mike1', subsubds_indexed)
assert_equal(states, [d.repo.get_hexsha() for d in (ds, subds, subsubds)])
unlink(opj(subsubds.path, 'mike1'))
ok_clean_git(ds.path)
# modify content in subsub and try saving
testfname = newfile_name
subsubds.unlock(testfname)
with open(opj(ds.path, testfname), 'w') as f:
f.write('I am in here!')
# the following should all do nothing
# no auto_add
assert_status('notneeded', ds._save())
# no recursive
assert_status('notneeded', ds._save())
# an explicit target saves only the corresponding dataset
assert_result_values_equal(
save(path=[testfname]),
'path',
[subsubds.path])
# plain recursive without any files given will save the beast
assert_result_values_equal(
ds._save(recursive=True, result_filter=is_ok_dataset),
'path',
[subds.path, ds.path])
# there is nothing else to save
assert_status('notneeded', ds._save(recursive=True))
ok_clean_git(ds.path)
# one more time and check that all datasets in the hierarchy are not
# contaminated with untracked files
states = [d.repo.get_hexsha() for d in (ds, subds, subsubds)]
testfname = opj('sub', 'subsub', 'saveme2')
with open(opj(ds.path, testfname), 'w') as f:
f.write('I am in here!')
assert_status('notneeded', ds._save(recursive=True))
newstates = [d.repo.get_hexsha() for d in (ds, subds, subsubds)]
for old, new in zip(states, newstates):
assert_equal(old, new)
assert ds.repo.dirty
unlink(opj(ds.path, testfname))
ok_clean_git(ds.path)
# now let's check saving "upwards"
create_tree(subds.path, {"testnew": 'smth', "testadded": "added"})
subds.repo.add("testadded")
indexed_files = subds.repo.get_indexed_files()
assert subds.repo.dirty
assert ds.repo.dirty
#.........这里部分代码省略.........
示例8: test_create_raises
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import subdatasets [as 别名]
def test_create_raises(path, outside_path):
ds = Dataset(path)
# incompatible arguments (annex only):
assert_raises(ValueError, ds.create, no_annex=True, description='some')
with open(op.join(path, "somefile.tst"), 'w') as f:
f.write("some")
# non-empty without `force`:
assert_in_results(
ds.create(force=False, **raw),
status='error',
message='will not create a dataset in a non-empty directory, use `force` option to ignore')
# non-empty with `force`:
ds.create(force=True)
# create sub outside of super:
assert_in_results(
ds.create(outside_path, **raw),
status='error',
message=(
'dataset containing given paths is not underneath the reference '
'dataset %s: %s', ds, outside_path))
obscure_ds = u"ds-" + OBSCURE_FILENAME
# create a sub:
ds.create(obscure_ds)
# fail when doing it again
assert_in_results(
ds.create(obscure_ds, **raw),
status='error',
message=('collision with content in parent dataset at %s: %s',
ds.path,
[text_type(ds.pathobj / obscure_ds)]),
)
# now deinstall the sub and fail trying to create a new one at the
# same location
ds.uninstall(obscure_ds, check=False)
assert_in(obscure_ds, ds.subdatasets(fulfilled=False, result_xfm='relpaths'))
# and now should fail to also create inplace or under
assert_in_results(
ds.create(obscure_ds, **raw),
status='error',
message=('collision with content in parent dataset at %s: %s',
ds.path,
[text_type(ds.pathobj / obscure_ds)]),
)
assert_in_results(
ds.create(op.join(obscure_ds, 'subsub'), **raw),
status='error',
message=('collision with %s (dataset) in dataset %s',
text_type(ds.pathobj / obscure_ds),
ds.path)
)
os.makedirs(op.join(ds.path, 'down'))
with open(op.join(ds.path, 'down', "someotherfile.tst"), 'w') as f:
f.write("someother")
ds.save()
assert_in_results(
ds.create('down', **raw),
status='error',
message=('collision with content in parent dataset at %s: %s',
ds.path,
[text_type(ds.pathobj / 'down' / 'someotherfile.tst')]),
)