Skip to content

Commit

Permalink
Merge branch 'run-id' into '0.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Sep 9, 2015
2 parents 50d1024 + 384046b commit 3ef8d58
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 33 deletions.
8 changes: 5 additions & 3 deletions docs/packing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ The first part of the configuration file gives general information with respect
version: <reprozip-version>
runs:
# Run 0
- architecture: <machine-architecture>
- id: <run-id>
architecture: <machine-architecture>
argv: <command-line-arguments>
binary: <command-line-binary>
distribution: <linux-distribution>
Expand All @@ -58,9 +59,10 @@ The first part of the configuration file gives general information with respect
workingdir: <working-directory>
# Run 1
- ...
- id: ...
...

If necessary, users may change command line parameters by editing ``argv``, and add or remove environment variables by editing ``environ``. Other attributes should not be changed in general.
If necessary, users may change command line parameters by editing ``argv``, and add or remove environment variables by editing ``environ``. Users may also give a more meaningful and user-friendly identifier for a run by changing ``id``. Other attributes should not be changed in general.

The next section brings information about input and output files, including their original paths and which runs read and/or wrote them. These are the files that `reprozip` identified as the main input or result of the experiment, which `reprounzip` will later be able to replace and extract from the experiment when reproducing it. You may add, remove, or edit these files in case `reprozip` fails in recognizing any important information, as well as give meaningful names to them by editing ``name``::

Expand Down
12 changes: 9 additions & 3 deletions reprounzip/reprounzip/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def read_packages(packages, File=File, Package=Package):
# 0.5: no change
# 0.6: no change
# 0.7: moves input_files and output_files from run to global scope
# 0.8: adds 'id' field to run


Config = optional_return_type(['runs', 'packages', 'other_files'],
Expand Down Expand Up @@ -214,8 +215,8 @@ def load_config(filename, canonical, File=File, Package=Package):
keys_ = set(config)
if 'version' not in keys_:
raise InvalidConfig("Missing version")
# Accepts versions from 0.2 to 0.7 inclusive
elif not LooseVersion('0.2') <= ver < LooseVersion('0.8'):
# Accepts versions from 0.2 to 0.8 inclusive
elif not LooseVersion('0.2') <= ver < LooseVersion('0.9'):
pkgname = (__package__ or __name__).split('.', 1)[0]
raise InvalidConfig("Loading configuration file in unknown format %s; "
"this probably means that you should upgrade "
Expand Down Expand Up @@ -245,6 +246,11 @@ def load_config(filename, canonical, File=File, Package=Package):
for n, f in iteritems(inputs_outputs)
if i in f.write_runs)

# reprozip < 0.8 compatibility: assign IDs to runs
for i, run in enumerate(runs):
if run.get('id') is None:
run['id'] = "run%d" % i

record_usage_package(runs, packages, other_files,
inputs_outputs,
pack_id=config.get('pack_id'))
Expand Down Expand Up @@ -312,7 +318,7 @@ def save_config(filename, runs, packages, other_files, reprozip_version,
""".format(pack_id=(('\npack_id: "%s"' % pack_id) if pack_id is not None
else ''),
version=escape(reprozip_version),
format='0.7',
format='0.8',
date=datetime.now().isoformat(),
what=("# It was generated by the packer and you shouldn't need to "
"edit it" if canonical
Expand Down
6 changes: 3 additions & 3 deletions reprounzip/reprounzip/pack_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def print_info(args):
print("Runs (%d):" % len(runs))
for i, run in enumerate(runs):
cmdline = ' '.join(shell_escape(a) for a in run['argv'])
if len(runs) > 1:
print(" %d: %s" % (i, cmdline))
else:
if len(runs) == 1 and run['id'] == "run0":
print(" %s" % cmdline)
else:
print(" %s: %s" % (run['id'], cmdline))
if args.verbosity >= 2:
print(" wd: %s" % run['workingdir'])
if 'signal' in run:
Expand Down
47 changes: 28 additions & 19 deletions reprounzip/reprounzip/unpackers/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ def get_runs(runs, selected_runs, cmdline):
Will return an iterable of run numbers. Might also fail loudly or exit
after printing the original command-line.
"""
name_map = dict((r['id'], i) for i, r in enumerate(runs) if 'id' in r)
run_list = []

if selected_runs is None:
if len(runs) == 1:
selected_runs = '0'
Expand All @@ -345,41 +348,47 @@ def parse_run(s):
try:
r = int(s)
except ValueError:
logging.critical("Error: Run is not a number")
logging.critical("Error: Unknown run %s", s)
raise UsageError
if r < 0 or r >= len(runs):
logging.critical("Error: Expected 0 <= run <= %d, got %d",
len(runs) - 1, r)
sys.exit(1)
return r

sep = selected_runs.find('-')
if sep == -1:
selected_runs = parse_run(selected_runs),
else:
if sep > 0:
first = parse_run(selected_runs[:sep])
else:
first = 0
if sep + 1 < len(selected_runs):
last = parse_run(selected_runs[sep + 1:])
for run_item in selected_runs.split(','):
run_item = run_item.strip()
if run_item in name_map:
run_list.append(name_map[run_item])
continue

sep = run_item.find('-')
if sep == -1:
run_list.append(parse_run(run_item))
else:
last = len(runs) - 1
if last <= first:
logging.critical("Error: Last run number should be greater than "
"the first")
sys.exit(1)
selected_runs = irange(first, last + 1)
if sep > 0:
first = parse_run(run_item[:sep])
else:
first = 0
if sep + 1 < len(run_item):
last = parse_run(run_item[sep + 1:])
else:
last = len(runs) - 1
if last <= first:
logging.critical("Error: Last run number should be greater "
"than the first")
sys.exit(1)
run_list.extend(irange(first, last + 1))

# --cmdline without arguments: display the original command-line
if cmdline == []:
print("Original command-lines:")
for run in selected_runs:
for run in run_list:
print(' '.join(shell_escape(arg)
for arg in runs[run]['argv']))
sys.exit(0)

return selected_runs
return run_list


def interruptible_call(*args, **kwargs):
Expand Down
12 changes: 9 additions & 3 deletions reprozip/reprozip/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def read_packages(packages, File=File, Package=Package):
# 0.5: no change
# 0.6: no change
# 0.7: moves input_files and output_files from run to global scope
# 0.8: adds 'id' field to run


Config = optional_return_type(['runs', 'packages', 'other_files'],
Expand Down Expand Up @@ -214,8 +215,8 @@ def load_config(filename, canonical, File=File, Package=Package):
keys_ = set(config)
if 'version' not in keys_:
raise InvalidConfig("Missing version")
# Accepts versions from 0.2 to 0.7 inclusive
elif not LooseVersion('0.2') <= ver < LooseVersion('0.8'):
# Accepts versions from 0.2 to 0.8 inclusive
elif not LooseVersion('0.2') <= ver < LooseVersion('0.9'):
pkgname = (__package__ or __name__).split('.', 1)[0]
raise InvalidConfig("Loading configuration file in unknown format %s; "
"this probably means that you should upgrade "
Expand Down Expand Up @@ -245,6 +246,11 @@ def load_config(filename, canonical, File=File, Package=Package):
for n, f in iteritems(inputs_outputs)
if i in f.write_runs)

# reprozip < 0.8 compatibility: assign IDs to runs
for i, run in enumerate(runs):
if run.get('id') is None:
run['id'] = "run%d" % i

record_usage_package(runs, packages, other_files,
inputs_outputs,
pack_id=config.get('pack_id'))
Expand Down Expand Up @@ -312,7 +318,7 @@ def save_config(filename, runs, packages, other_files, reprozip_version,
""".format(pack_id=(('\npack_id: "%s"' % pack_id) if pack_id is not None
else ''),
version=escape(reprozip_version),
format='0.7',
format='0.8',
date=datetime.now().isoformat(),
what=("# It was generated by the packer and you shouldn't need to "
"edit it" if canonical
Expand Down
3 changes: 2 additions & 1 deletion reprozip/reprozip/tracer/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ def write_configuration(directory, sort_packages, find_inputs_outputs,
envp = envp[:-1]
environ = dict(v.split('=', 1) for v in envp)

runs.append({'binary': r_name, 'argv': argv,
runs.append({'id': "run%d" % len(runs),
'binary': r_name, 'argv': argv,
'workingdir': unicode_(Path(r_workingdir)),
'architecture': platform.machine().lower(),
'distribution': distribution,
Expand Down
9 changes: 8 additions & 1 deletion tests/test_unpackers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def test_make_unique_name(self):
class TestMisc(unittest.TestCase):
def do_ok(self, arg, expected):
try:
runs = get_runs([{}, {}, {}, {}], arg, None)
runs = get_runs(
[{'id': 'one'}, {'id': 'two-heh'}, {'id': 'three'}, {}],
arg, None)
except (SystemExit, UsageError):
self.fail("get_runs(<4 runs>, %r) raised" % arg)
self.assertEqual(list(runs), expected)
Expand Down Expand Up @@ -60,5 +62,10 @@ def test_get_runs(self):
self.do_fail('0-8')
self.do_fail('0-4')
self.do_ok('0-3', [0, 1, 2, 3])
self.do_ok('one', [0])
self.do_ok('two-heh', [1]),
self.do_ok('one,three', [0, 2])
self.do_ok('1,three', [1, 2])
self.do_ok('2-3,two-heh', [2, 3, 1])
finally:
print(">>>>> get_runs tests", file=sys.stderr)

0 comments on commit 3ef8d58

Please sign in to comment.