本文整理汇总了Python中datalad.distribution.dataset.Dataset.run方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.run方法的具体用法?Python Dataset.run怎么用?Python Dataset.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datalad.distribution.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rerun_just_one_commit
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_just_one_commit(path):
ds = Dataset(path).create()
# Check out an orphan branch so that we can test the "one commit
# in a repo" case.
ds.repo.checkout("orph", options=["--orphan"])
ds.repo.repo.git.reset("--hard")
ds.repo.config.reload()
ds.run('echo static-content > static')
assert_result_count(ds.repo.repo.git.rev_list("HEAD").split(), 1)
# Rerunning with just one commit doesn't raise an error ...
ds.rerun()
# ... but we're still at one commit because the content didn't
# change.
assert_result_count(ds.repo.repo.git.rev_list("HEAD").split(), 1)
# We abort rather than trying to do anything when --onto='' and
# --since='' are given together and the first commit contains a
# run command.
ds.repo.commit(msg="empty", options=["--allow-empty"])
assert_raises(IncompleteResultsError, ds.rerun, since="", onto="")
# --script propagates the error.
with swallow_outputs():
assert_raises(IncompleteResultsError,
ds.rerun, since="", onto="", script="-")
# --dry-run propagates the error.
assert_raises(IncompleteResultsError,
ds.rerun, since="", onto="",
report=True, return_type="list")
示例2: test_run_from_subds
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_run_from_subds(path):
if 'APPVEYOR' in os.environ:
raise SkipTest('test causes appveyor (only) to crash, reason unknown')
subds = Dataset(path).create().create("sub")
subds.run("cd .> foo")
assert_repo_status(subds.path)
示例3: test_rerun_script
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_script(path):
ds = Dataset(path).create()
ds.run("echo a >foo")
ds.run(["touch", "bar"], message='BAR', sidecar=True)
# a run record sidecar file was added with the last commit
assert(any(d['path'].startswith(opj(ds.path, '.datalad', 'runinfo'))
for d in ds.rerun(report=True, return_type='item-or-list')['diff']))
bar_hexsha = ds.repo.get_hexsha()
script_file = opj(path, "commands.sh")
ds.rerun(script=script_file)
ok_exists(script_file)
with open(script_file) as sf:
lines = sf.readlines()
assert_in("touch bar\n", lines)
# The commit message is there too.
assert_in("# BAR\n", lines)
assert_in("# (record: {})\n".format(bar_hexsha), lines)
assert_not_in("echo a >foo\n", lines)
ds.rerun(since="", script=script_file)
with open(script_file) as sf:
lines = sf.readlines()
assert_in("touch bar\n", lines)
# Automatic commit messages aren't included.
assert_not_in("# echo a >foo\n", lines)
assert_in("echo a >foo\n", lines)
# --script=- writes to stdout.
with patch("sys.stdout", new_callable=StringIO) as cmout:
ds.rerun(script="-")
assert_in("touch bar",
cmout.getvalue().splitlines())
示例4: test_rerun_ambiguous_revision_file
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_ambiguous_revision_file(path):
ds = Dataset(path).create()
ds.run('echo ambig > ambig')
ds.repo.tag("ambig")
# Don't fail when "ambig" refers to both a file and revision.
ds.rerun(since="", revision="ambig", branch="rerun")
eq_(len(ds.repo.repo.git.rev_list("rerun").split()),
len(ds.repo.repo.git.rev_list("ambig", "--").split()))
示例5: test_rerun_cherry_pick
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_cherry_pick(path):
ds = Dataset(path).create()
ds.repo.tag("prerun")
ds.run('echo abc > runfile')
with open(opj(path, "nonrun-file"), "w") as f:
f.write("foo")
ds.add("nonrun-file")
for onto, action in [("HEAD", "skip"), ("prerun", "pick")]:
results = ds.rerun(since="prerun", onto=onto)
assert_in_results(results, status='ok', rerun_action=action)
示例6: test_rerun_outofdate_tree
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_outofdate_tree(path):
ds = Dataset(path).create()
input_file = opj(path, "foo")
output_file = opj(path, "out")
with open(input_file, "w") as f:
f.write("abc\ndef")
ds.add("foo", to_git=True)
# Create inital run.
ds.run('grep def foo > out')
eq_('def\n', open(output_file).read())
# Change tree so that it is no longer compatible.
ds.remove("foo")
# Now rerunning should fail because foo no longer exists.
assert_raises(CommandError, ds.rerun, revision="HEAD~")
示例7: test_py2_unicode_command
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_py2_unicode_command(path):
# Avoid OBSCURE_FILENAME to avoid windows-breakage (gh-2929).
ds = Dataset(path).create()
touch_cmd = "import sys; open(sys.argv[1], 'w').write('')"
cmd_str = u"{} -c \"{}\" {}".format(sys.executable,
touch_cmd,
u"bβ0.dat")
ds.run(cmd_str)
assert_repo_status(ds.path)
ok_exists(op.join(path, u"bβ0.dat"))
if not on_windows: # FIXME
ds.run([sys.executable, "-c", touch_cmd, u"bβ1.dat"])
assert_repo_status(ds.path)
ok_exists(op.join(path, u"bβ1.dat"))
# Send in a list of byte-strings to mimic a py2 command-line
# invocation.
ds.run([s.encode("utf-8")
for s in [sys.executable, "-c", touch_cmd, u" β1 "]])
assert_repo_status(ds.path)
ok_exists(op.join(path, u" β1 "))
with assert_raises(CommandError), swallow_outputs():
ds.run(u"bβ2.dat")
示例8: test_rerun_branch
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_branch(path):
ds = Dataset(path).create()
ds.repo.tag("prerun")
outfile = opj(path, "run-file")
ds.run('echo x$(cat run-file) > run-file')
ds.rerun()
eq_('xx\n', open(outfile).read())
with open(opj(path, "nonrun-file"), "w") as f:
f.write("foo")
ds.add("nonrun-file")
# Rerun the commands on a new branch that starts at the parent
# commit of the first run.
ds.rerun(since="prerun", onto="prerun", branch="rerun")
eq_(ds.repo.get_active_branch(), "rerun")
eq_('xx\n', open(outfile).read())
# NOTE: This test depends on the non-run commit above following a run
# commit. Otherwise, all the metadata (e.g., author date) aside from the
# parent commit that is used to generate the commit ID may be set when
# running the tests, which would result in two commits rather than three.
for revrange in ["rerun..master", "master..rerun"]:
assert_result_count(
ds.repo.repo.git.rev_list(revrange).split(), 3)
eq_(ds.repo.get_merge_base(["master", "rerun"]),
ds.repo.get_hexsha("prerun"))
# Start rerun branch at tip of current branch.
ds.repo.checkout("master")
ds.rerun(since="prerun", branch="rerun2")
eq_(ds.repo.get_active_branch(), "rerun2")
eq_('xxxx\n', open(outfile).read())
assert_result_count(
ds.repo.repo.git.rev_list("master..rerun2").split(), 2)
assert_result_count(
ds.repo.repo.git.rev_list("rerun2..master").split(), 0)
# Using an existing branch name fails.
ds.repo.checkout("master")
assert_raises(IncompleteResultsError,
ds.rerun, since="prerun", branch="rerun2")
示例9: test_rerun_chain
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_chain(path):
ds = Dataset(path).create()
commits = []
grow_file = opj(path, "grows")
ds.run('echo x$(cat grows) > grows')
ds.repo.tag("first-run")
for _ in range(3):
commits.append(ds.repo.get_hexsha())
ds.rerun()
_, info = get_run_info(ds, ds.repo.format_commit("%B"))
assert info["chain"] == commits
ds.rerun(revision="first-run")
_, info = get_run_info(ds, ds.repo.format_commit("%B"))
assert info["chain"] == commits[:1]
示例10: test_basics
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_basics(path, nodspath):
ds = Dataset(path).create()
direct_mode = ds.repo.is_direct_mode()
last_state = ds.repo.get_hexsha()
# run inside the dataset
with chpwd(path), \
swallow_outputs():
# provoke command failure
with assert_raises(CommandError) as cme:
ds.run('7i3amhmuch9invalid')
# let's not speculate that the exit code is always 127
ok_(cme.code > 0)
eq_(last_state, ds.repo.get_hexsha())
# now one that must work
res = ds.run('touch empty', message='TEST')
ok_clean_git(ds.path)
assert_result_count(res, 2)
# TODO 'state' is still untracked!!!
assert_result_count(res, 1, action='add', path=opj(ds.path, 'empty'), type='file')
assert_result_count(res, 1, action='save', path=ds.path)
commit_msg = ds.repo.format_commit("%B")
ok_(commit_msg.startswith('[DATALAD RUNCMD] TEST'))
# crude test that we have a record for the PWD
assert_in('"pwd": "."', commit_msg)
last_state = ds.repo.get_hexsha()
# now run a command that will not alter the dataset
res = ds.run('touch empty', message='NOOP_TEST')
# When in direct mode, check at the level of save rather than add
# because the annex files show up as typechanges and adding them won't
# necessarily have a "notneeded" status.
assert_result_count(res, 1, action='save' if direct_mode else 'add',
status='notneeded')
eq_(last_state, ds.repo.get_hexsha())
# We can also run the command via a single-item list because this is
# what the CLI interface passes in for quoted commands.
res = ds.run(['touch empty'], message='NOOP_TEST')
assert_result_count(res, 1, action='save' if direct_mode else 'add',
status='notneeded')
# run outside the dataset, should still work but with limitations
with chpwd(nodspath), \
swallow_outputs():
res = ds.run(['touch', 'empty2'], message='TEST')
assert_result_count(res, 1, action='add', path=opj(ds.path, 'empty2'), type='file',
status='ok')
assert_result_count(res, 1, action='save', status='ok')
# running without a command is a noop
with chpwd(path):
with swallow_logs(new_level=logging.WARN) as cml:
ds.run()
assert_in("No command given", cml.out)
示例11: test_inputs_quotes_needed
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_inputs_quotes_needed(path):
ds = Dataset(path).create(force=True)
ds.save()
cmd = "import sys; open(sys.argv[-1], 'w').write('!'.join(sys.argv[1:]))"
# The string form of a command works fine when the inputs/outputs have
# spaces ...
cmd_str = "{} -c \"{}\" {{inputs}} {{outputs[0]}}".format(
sys.executable, cmd)
ds.run(cmd_str, inputs=["*.t*"], outputs=["out0"], expand="inputs")
expected = u"!".join(
list(sorted([OBSCURE_FILENAME + u".t", "bar.txt", "foo blah.txt"])) +
["out0"])
with open(op.join(path, "out0")) as ifh:
eq_(assure_unicode(ifh.read()), expected)
# ... but the list form of a command does not. (Don't test this failure
# with the obscure file name because we'd need to know its composition to
# predict the failure.)
cmd_list = [sys.executable, "-c", cmd, "{inputs}", "{outputs[0]}"]
ds.run(cmd_list, inputs=["*.txt"], outputs=["out0"])
ok_file_has_content(op.join(path, "out0"), "bar.txt foo!blah.txt!out0")
示例12: test_rerun_subdir
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_subdir(path):
# Note: Using with_tree rather than with_tempfile is matters. The latter
# calls realpath on the path, which masks a failure in the
# TMPDIR="/var/tmp/sym link" test case
ds = Dataset(path).create(force=True)
subdir = opj(path, 'subdir')
with chpwd(subdir):
run("touch test.dat")
ok_clean_git(ds.path)
# FIXME: A plain ok_file_under_git call doesn't properly resolve the file
# in the TMPDIR="/var/tmp/sym link" test case. Temporarily call realpath.
def ok_file_under_git_kludge(path, basename):
ok_file_under_git(opj(op.realpath(path), basename), annexed=True)
ok_file_under_git_kludge(subdir, "test.dat")
rec_msg, runinfo = get_run_info(ds, ds.repo.format_commit("%B"))
eq_(runinfo['pwd'], 'subdir')
# now, rerun within root of the dataset
with chpwd(ds.path):
ds.rerun()
ok_clean_git(ds.path)
ok_file_under_git_kludge(subdir, "test.dat")
# and not on top
assert_raises(AssertionError, ok_file_under_git, opj(ds.path, "test.dat"), annexed=True)
# but if we run ds.run -- runs within top of the dataset
with chpwd(subdir):
ds.run("touch test2.dat")
ok_clean_git(ds.path)
ok_file_under_git_kludge(ds.path, "test2.dat")
rec_msg, runinfo = get_run_info(ds, ds.repo.format_commit("%B"))
eq_(runinfo['pwd'], '.')
# now, rerun within subdir -- smoke for now
with chpwd(subdir):
ds.rerun()
示例13: test_run_explicit
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_run_explicit(path):
ds = Dataset(path)
assert_false(ds.repo.file_has_content("test-annex.dat"))
create_tree(ds.path, {"dirt_untracked": "untracked",
"dirt_modified": "modified"})
ds.save("dirt_modified", to_git=True)
with open(op.join(path, "dirt_modified"), "a") as ofh:
ofh.write(", more")
# We need explicit=True to run with dirty repo.
assert_status("impossible",
ds.run("cat test-annex.dat test-annex.dat >doubled.dat",
inputs=["test-annex.dat"],
on_failure="ignore"))
hexsha_initial = ds.repo.get_hexsha()
# If we specify test-annex.dat as an input, it will be retrieved before the
# run.
ds.run("cat test-annex.dat test-annex.dat >doubled.dat",
inputs=["test-annex.dat"], explicit=True)
ok_(ds.repo.file_has_content("test-annex.dat"))
# We didn't commit anything because outputs weren't specified.
assert_false(ds.repo.file_has_content("doubled.dat"))
eq_(hexsha_initial, ds.repo.get_hexsha())
# If an input doesn't exist, we just show the standard warning.
with swallow_logs(new_level=logging.WARN) as cml:
with swallow_outputs():
ds.run("ls", inputs=["not-there"], explicit=True)
assert_in("Input does not exist: ", cml.out)
remove(op.join(path, "doubled.dat"))
hexsha_initial = ds.repo.get_hexsha()
ds.run("cat test-annex.dat test-annex.dat >doubled.dat",
inputs=["test-annex.dat"], outputs=["doubled.dat"],
explicit=True)
ok_(ds.repo.file_has_content("doubled.dat"))
assert_repo_status(ds.path, modified=["dirt_modified"], untracked=['dirt_untracked'])
neq_(hexsha_initial, ds.repo.get_hexsha())
# Saving explicit outputs works from subdirectories.
subdir = op.join(path, "subdir")
mkdir(subdir)
with chpwd(subdir):
run("echo insubdir >foo", explicit=True, outputs=["foo"])
ok_(ds.repo.file_has_content(op.join("subdir", "foo")))
示例14: test_rerun_old_flag_compatibility
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_rerun_old_flag_compatibility(path):
ds = Dataset(path).create()
ds.run("echo x$(cat grows) > grows")
# Deprecated `datalad --rerun` still runs the last commit's
# command.
ds.run(rerun=True)
eq_("xx\n", open(opj(path, "grows")).read())
# Running with --rerun and a command ignores the command.
with swallow_logs(new_level=logging.WARN) as cml:
ds.run(rerun=True, cmd="ignored")
assert_in("Ignoring provided command in --rerun mode", cml.out)
eq_("xxx\n", open(opj(path, "grows")).read())
示例15: test_sidecar
# 需要导入模块: from datalad.distribution.dataset import Dataset [as 别名]
# 或者: from datalad.distribution.dataset.Dataset import run [as 别名]
def test_sidecar(path):
ds = Dataset(path).create()
# Simple sidecar message checks.
ds.run("cd .> dummy0", message="sidecar arg", sidecar=True)
assert_not_in('"cmd":', ds.repo.format_commit("%B"))
ds.config.set("datalad.run.record-sidecar", "false", where="local")
ds.run("cd .> dummy1", message="sidecar config")
assert_in('"cmd":', ds.repo.format_commit("%B"))
ds.config.set("datalad.run.record-sidecar", "true", where="local")
ds.run("cd .> dummy2", message="sidecar config")
assert_not_in('"cmd":', ds.repo.format_commit("%B"))
# Don't break when config.get() returns multiple values. Here it's two
# values in .gitconfig, but a more realistic scenario is a value in
# $repo/.git/config that overrides a setting in ~/.config/git/config.
ds.config.add("datalad.run.record-sidecar", "false", where="local")
ds.run("cd .> dummy3", message="sidecar config")
assert_in('"cmd":', ds.repo.format_commit("%B"))