本文整理汇总了Python中datalad.support.gitrepo.GitRepo.is_valid_repo方法的典型用法代码示例。如果您正苦于以下问题:Python GitRepo.is_valid_repo方法的具体用法?Python GitRepo.is_valid_repo怎么用?Python GitRepo.is_valid_repo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.support.gitrepo.GitRepo
的用法示例。
在下文中一共展示了GitRepo.is_valid_repo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_git_submodules
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def _parse_git_submodules(ds, paths):
"""All known ones with some properties"""
if not (ds.pathobj / ".gitmodules").exists():
# easy way out. if there is no .gitmodules file
# we cannot have (functional) subdatasets
return
if paths:
paths = [
p.relative_to(ds.pathobj)
for p in paths
if ds.pathobj == p or ds.pathobj in p.parents]
if not paths:
# we had path contraints, but none matched this dataset
return
for path, props in iteritems(ds.repo.get_content_info(
paths=paths,
ref=None,
untracked='no',
eval_file_type=False)):
if props.get('type', None) != 'dataset':
continue
if ds.pathobj != ds.repo.pathobj:
props['path'] = ds.pathobj / path.relative_to(ds.repo.pathobj)
else:
props['path'] = path
if not path.exists() or not GitRepo.is_valid_repo(text_type(path)):
props['state'] = 'absent'
# TODO kill this after some time. We used to do custom things here
# and gitshasum was called revision. Be nice and duplicate for a bit
# wipe out when patience is gone
props['revision'] = props['gitshasum']
yield props
示例2: test_install_simple_local
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_install_simple_local(src, path):
origin = Dataset(path)
# now install it somewhere else
ds = install(path, source=src, description='mydummy')
eq_(ds.path, path)
ok_(ds.is_installed())
if not isinstance(origin.repo, AnnexRepo):
# this means it is a GitRepo
ok_(isinstance(origin.repo, GitRepo))
# stays plain Git repo
ok_(isinstance(ds.repo, GitRepo))
ok_(not isinstance(ds.repo, AnnexRepo))
ok_(GitRepo.is_valid_repo(ds.path))
eq_(set(ds.repo.get_indexed_files()),
{'test.dat', 'INFO.txt'})
ok_clean_git(path, annex=False)
else:
# must be an annex
ok_(isinstance(ds.repo, AnnexRepo))
ok_(AnnexRepo.is_valid_repo(ds.path, allow_noninitialized=False))
eq_(set(ds.repo.get_indexed_files()),
{'test.dat', 'INFO.txt', 'test-annex.dat'})
ok_clean_git(path, annex=True)
# no content was installed:
ok_(not ds.repo.file_has_content('test-annex.dat'))
uuid_before = ds.repo.uuid
eq_(ds.repo.get_description(), 'mydummy')
# installing it again, shouldn't matter:
res = install(path, source=src, result_xfm=None, return_type='list')
assert_status('notneeded', res)
ok_(ds.is_installed())
if isinstance(origin.repo, AnnexRepo):
eq_(uuid_before, ds.repo.uuid)
示例3: test_submodule_deinit
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_submodule_deinit(path):
from datalad.support.annexrepo import AnnexRepo
top_repo = AnnexRepo(path, create=False)
eq_({'subm 1', '2'}, {s.name for s in top_repo.get_submodules()})
# note: here init=True is ok, since we are using it just for testing
with swallow_logs(new_level=logging.WARN) as cml:
top_repo.update_submodule('subm 1', init=True)
assert_in('Do not use update_submodule with init=True', cml.out)
top_repo.update_submodule('2', init=True)
# ok_(all([s.module_exists() for s in top_repo.get_submodules()]))
# TODO: old assertion above if non-bare? (can't use "direct mode" in test_gitrepo)
# Alternatively: New testrepo (plain git submodules) and have a dedicated
# test for annexes in addition
ok_(all([GitRepo.is_valid_repo(op.join(top_repo.path, s.path))
for s in top_repo.get_submodules()]))
# modify submodule:
with open(op.join(top_repo.path, 'subm 1', 'file_ut.dat'), "w") as f:
f.write("some content")
assert_raises(CommandError, top_repo.deinit_submodule, 'sub1')
# using force should work:
top_repo.deinit_submodule('subm 1', force=True)
ok_(not top_repo.repo.submodule('subm 1').module_exists())
示例4: _discover_subdatasets_recursively
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def _discover_subdatasets_recursively(
discovered, top, trace, recursion_limit):
# this beast walks the directory tree from a give `top` directory
# and discovers valid repos that are scattered around, regardless
# of whether they are already subdatasets or not
# `trace` must be a list that has at least one element (the base
# dataset)
if recursion_limit is not None and len(trace) > recursion_limit:
return
if not isdir(top):
return
if not op.islink(top) and GitRepo.is_valid_repo(top):
if top in discovered:
# this was found already, assume everything beneath it too
return
discovered[top] = dict(
path=top,
# and its content
process_content=True,
type='dataset',
parentds=trace[-1])
# new node in the trace down
trace = trace + [top]
for path in listdir(top):
path = opj(top, path)
if not isdir(path):
continue
# next level down
_discover_subdatasets_recursively(
discovered, path, trace, recursion_limit)
示例5: _install_necessary_subdatasets
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def _install_necessary_subdatasets(
ds, path, reckless, refds_path, description=None):
"""Installs subdatasets of `ds`, that are necessary to obtain in order
to have access to `path`.
Gets the subdataset containing `path` regardless of whether or not it was
already installed. While doing so, installs everything necessary in between
the uppermost installed one and `path`.
Note: `ds` itself has to be installed.
Parameters
----------
ds: Dataset
path: str
reckless: bool
"""
# figuring out what dataset to start with, --contains limits --recursive
# to visit only subdataset on the trajectory to the target path
subds_trail = ds.subdatasets(contains=path, recursive=True)
if not subds_trail:
# there is not a single known subdataset (installed or not)
# for this path -- job done
return
# otherwise we start with the one deepest down
cur_subds = subds_trail[-1]
while not GitRepo.is_valid_repo(cur_subds['path']):
# install using helper that give some flexibility regarding where to
# get the module from
try:
sd = _install_subds_from_flexible_source(
Dataset(cur_subds['parentds']),
relpath(cur_subds['path'], start=cur_subds['parentds']),
cur_subds['gitmodule_url'],
reckless,
description=description)
except Exception as e:
# skip all of downstairs, if we didn't manage to install subdataset
yield get_status_dict(
'install', path=cur_subds['path'], type='dataset',
status='error', logger=lgr, refds=refds_path,
message=("Installation of subdatasets %s failed with exception: %s",
cur_subds['path'], exc_str(e)))
return
# report installation, whether it helped or not
yield get_status_dict(
'install', ds=sd, status='ok', logger=lgr, refds=refds_path,
message=("Installed subdataset in order to get %s", path))
# now check whether the just installed subds brought us any closer to
# the target path
subds_trail = sd.subdatasets(contains=path, recursive=False)
if not subds_trail:
# no (newly available) subdataset get's us any closer
return
# next round
cur_subds = subds_trail[-1]
示例6: test_clone_dataset_from_just_source
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_clone_dataset_from_just_source(url, path):
with chpwd(path, mkdir=True):
ds = clone(url, result_xfm='datasets', return_type='item-or-list')
ok_startswith(ds.path, path)
ok_(ds.is_installed())
ok_(GitRepo.is_valid_repo(ds.path))
ok_clean_git(ds.path, annex=None)
assert_in('INFO.txt', ds.repo.get_indexed_files())
示例7: test_install_dataset_from_just_source
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_install_dataset_from_just_source(url, path):
with chpwd(path, mkdir=True):
ds = install(source=url)
ok_startswith(ds.path, path)
ok_(ds.is_installed())
ok_(GitRepo.is_valid_repo(ds.path))
ok_clean_git(ds.path, annex=None)
assert_in('INFO.txt', ds.repo.get_indexed_files())
示例8: test_install_dataset_from_instance
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_install_dataset_from_instance(src, dst):
origin = Dataset(src)
clone = install(source=origin, path=dst)
assert_is_instance(clone, Dataset)
ok_startswith(clone.path, dst)
ok_(clone.is_installed())
ok_(GitRepo.is_valid_repo(clone.path))
ok_clean_git(clone.path, annex=None)
assert_in('INFO.txt', clone.repo.get_indexed_files())
示例9: test_install_dataset_from_just_source_via_path
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_install_dataset_from_just_source_via_path(url, path):
# for remote urls only, the source could be given to `path`
# to allows for simplistic cmdline calls
# Q (ben): remote urls only? Sure? => TODO
with chpwd(path, mkdir=True):
ds = install(url)
ok_startswith(ds.path, path)
ok_(ds.is_installed())
ok_(GitRepo.is_valid_repo(ds.path))
ok_clean_git(ds.path, annex=None)
assert_in('INFO.txt', ds.repo.get_indexed_files())
示例10: __call__
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def __call__(
path=None,
dataset=None,
fulfilled=None,
recursive=False,
recursion_limit=None,
contains=None,
bottomup=False,
set_property=None,
delete_property=None):
# no constraints given -> query subdatasets under curdir
if not path and dataset is None:
path = os.curdir
paths = [rev_resolve_path(p, dataset) for p in assure_list(path)] \
if path else None
ds = require_dataset(
dataset, check_installed=False, purpose='subdataset reporting/modification')
lgr.debug('Query subdatasets of %s', dataset)
if paths is not None:
lgr.debug('Query subdatasets underneath paths: %s', paths)
refds_path = ds.path
# XXX this seems strange, but is tested to be the case -- I'd rather set
# `check_installed` to true above and fail
if not GitRepo.is_valid_repo(refds_path):
return
# return as quickly as possible
if isinstance(recursion_limit, int) and (recursion_limit <= 0):
return
if set_property:
for k, v in set_property:
if valid_key.match(k) is None:
raise ValueError(
"key '%s' is invalid (alphanumeric plus '-' only, must "
"start with a letter)" % k)
if contains:
contains = [rev_resolve_path(c, dataset) for c in assure_list(contains)]
for r in _get_submodules(
ds, paths, fulfilled, recursive, recursion_limit,
contains, bottomup, set_property, delete_property,
refds_path):
# a boat-load of ancient code consumes this and is ignorant of
# Path objects
r['path'] = text_type(r['path'])
# without the refds_path cannot be rendered/converted relative
# in the eval_results decorator
r['refds'] = refds_path
yield r
示例11: _adj2subtrees
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def _adj2subtrees(base, adj, subs):
# given a set of parent-child mapping, compute a mapping of each parent
# to all its (grand)children of any depth level
subtrees = dict(adj)
subs = set(subs)
# from bottom up
for ds in sorted(adj, reverse=True):
subtree = []
for sub in subtrees[ds]:
subtree.append(sub)
subtree.extend(subtrees.get(sub, []))
subtrees[ds] = subtree
# give each leaf dataset an entry too
for sub in subs:
if sub not in subtrees and GitRepo.is_valid_repo(sub):
subtrees[sub] = []
return subtrees
示例12: _discover_subdatasets_recursively
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def _discover_subdatasets_recursively(top, trace, spec, recursion_limit):
# this beast walks the directory tree from a give `top` directory
# and discovers valid repos that are scattered around, regardless
# of whether they are already subdatasets or not
# for all found datasets it puts an entry into the SPEC and also
# and entry with the path in the SPEC of the parent dataset
if recursion_limit is not None and len(trace) > recursion_limit:
return
if not isdir(top):
return
if GitRepo.is_valid_repo(top):
# found a repo, add the entire thing
spec[top] = spec.get(top, []) + [top]
# and to the parent
if trace:
spec[trace[-1]] = spec.get(trace[-1], []) + [top]
trace = trace + [top]
for path in listdir(top):
path = opj(top, path)
if not isdir(path):
continue
_discover_subdatasets_recursively(path, trace, spec, recursion_limit)
示例13: __call__
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def __call__(
dataset=None,
fulfilled=None,
recursive=False,
recursion_limit=None,
contains=None,
bottomup=False,
set_property=None,
delete_property=None):
dataset = require_dataset(
dataset, check_installed=False, purpose='subdataset reporting/modification')
refds_path = dataset.path
# XXX this seems strange, but is tested to be the case -- I'd rather set
# `check_installed` to true above and fail
if not GitRepo.is_valid_repo(refds_path):
return
# return as quickly as possible
if isinstance(recursion_limit, int) and (recursion_limit <= 0):
return
if set_property:
for k, v in set_property:
if valid_key.match(k) is None:
raise ValueError(
"key '%s' is invalid (alphanumeric plus '-' only, must start with a letter)",
k)
if contains:
contains = resolve_path(contains, dataset)
for r in _get_submodules(
dataset.path, fulfilled, recursive, recursion_limit,
contains, bottomup, set_property, delete_property,
refds_path):
# without the refds_path cannot be rendered/converted relative
# in the eval_results decorator
r['refds'] = refds_path
yield r
示例14: _parse_git_submodules
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def _parse_git_submodules(dspath):
"""All known ones with some properties"""
if not exists(opj(dspath, ".gitmodules")):
# easy way out. if there is no .gitmodules file
# we cannot have (functional) subdatasets
return
# this will not work in direct mode, need better way #1422
cmd = ['git', 'ls-files', '--stage', '-z']
# need to go rogue and cannot use proper helper in GitRepo
# as they also pull in all of GitPython's magic
try:
stdout, stderr = GitRunner(cwd=dspath).run(
cmd,
log_stderr=True,
log_stdout=True,
# not sure why exactly, but log_online has to be false!
log_online=False,
expect_stderr=False,
shell=False,
# we don't want it to scream on stdout
expect_fail=True)
except CommandError as e:
raise InvalidGitRepositoryError(exc_str(e))
for line in stdout.split('\0'):
if not line or not line.startswith('160000'):
continue
sm = {}
props = submodule_full_props.match(line)
sm['revision'] = props.group(2)
subpath = _path_(dspath, props.group(4))
sm['path'] = subpath
if not exists(subpath) or not GitRepo.is_valid_repo(subpath):
sm['state'] = 'absent'
yield sm
示例15: test_install_simple_local
# 需要导入模块: from datalad.support.gitrepo import GitRepo [as 别名]
# 或者: from datalad.support.gitrepo.GitRepo import is_valid_repo [as 别名]
def test_install_simple_local(src, path):
origin = Dataset(path)
# now install it somewhere else
ds = install(path, source=src)
eq_(ds.path, path)
ok_(ds.is_installed())
if not isinstance(origin.repo, AnnexRepo):
# this means it is a GitRepo
ok_(isinstance(origin.repo, GitRepo))
# stays plain Git repo
ok_(isinstance(ds.repo, GitRepo))
ok_(not isinstance(ds.repo, AnnexRepo))
ok_(GitRepo.is_valid_repo(ds.path))
eq_(set(ds.repo.get_indexed_files()),
{'test.dat', 'INFO.txt'})
ok_clean_git(path, annex=False)
else:
# must be an annex
ok_(isinstance(ds.repo, AnnexRepo))
ok_(AnnexRepo.is_valid_repo(ds.path, allow_noninitialized=False))
eq_(set(ds.repo.get_indexed_files()),
{'test.dat', 'INFO.txt', 'test-annex.dat'})
ok_clean_git(path, annex=True)
# no content was installed:
ok_(not ds.repo.file_has_content('test-annex.dat'))
uuid_before = ds.repo.uuid
# installing it again, shouldn't matter:
with swallow_logs(new_level=logging.INFO) as cml:
ds = install(path, source=src)
cml.assert_logged(msg="{0} was already installed from".format(ds),
regex=False, level="INFO")
ok_(ds.is_installed())
if isinstance(origin.repo, AnnexRepo):
eq_(uuid_before, ds.repo.uuid)