Skip to content
Snippets Groups Projects
Commit d0dfdc7e authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

Added 'getexp' option to mkexp command line, re-generating setups from getexp -vv dumps

parent 8fb0072d
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ Global ...@@ -14,6 +14,7 @@ Global
* Changed rmexp to be compatible with Debian's /bin/sh (dash) * Changed rmexp to be compatible with Debian's /bin/sh (dash)
* Changed mkexp and expconfig to be compatible with python-2.6 * Changed mkexp and expconfig to be compatible with python-2.6
* Added 'mkexp' option to re-run using 'getexp -vv' output
Release 0.4.1 Release 0.4.1
============= =============
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
No preview for this file type
...@@ -81,7 +81,8 @@ class ExpConfig(ConfigObj): ...@@ -81,7 +81,8 @@ class ExpConfig(ConfigObj):
# Class constructor # Class constructor
def __init__(self, experiment_config_name, extra_dict={}, config_roots=['']): def __init__(self, experiment_config_name,
extra_dict={}, config_roots=[''], getexp=False):
'''Read experiment config to get basic settings '''Read experiment config to get basic settings
TODO: probably nicer if default experiment is given as argument TODO: probably nicer if default experiment is given as argument
...@@ -336,9 +337,10 @@ class ExpConfig(ConfigObj): ...@@ -336,9 +337,10 @@ class ExpConfig(ConfigObj):
# Read Environment # Read Environment
env_dict = dict(os.environ) env_dict = dict(os.environ)
# Mask literal dollar characters if not getexp:
for key, value in env_dict.iteritems(): # Mask literal dollar characters
env_dict[key] = value.replace('$', '$$') for key, value in env_dict.iteritems():
env_dict[key] = value.replace('$', '$$')
pre_config.merge({'DEFAULT': env_dict}) pre_config.merge({'DEFAULT': env_dict})
# Read experiment settings from library (default and type specific) # Read experiment settings from library (default and type specific)
...@@ -402,7 +404,8 @@ class ExpConfig(ConfigObj): ...@@ -402,7 +404,8 @@ class ExpConfig(ConfigObj):
pre_config['ENVIRONMENT'] = environment pre_config['ENVIRONMENT'] = environment
# Add complete versioning info # Add complete versioning info
pre_config['VERSIONS_'] = config_versions if not getexp:
pre_config['VERSIONS_'] = config_versions
# Re-read merged config with interpolation set. # Re-read merged config with interpolation set.
# This works around incomprehensible inheritance of interpolation with # This works around incomprehensible inheritance of interpolation with
...@@ -414,7 +417,8 @@ class ExpConfig(ConfigObj): ...@@ -414,7 +417,8 @@ class ExpConfig(ConfigObj):
pre_config = None pre_config = None
config_lines.seek(0) config_lines.seek(0)
pre_config = ConfigObj(config_lines, interpolation='template') pre_config = ConfigObj(config_lines,
interpolation=False if getexp else 'template')
# Extract experiment description from initial comment # Extract experiment description from initial comment
# if not set explicitly # if not set explicitly
......
...@@ -264,6 +264,8 @@ command_line.add_argument('--no-make-dirs', '-m', ...@@ -264,6 +264,8 @@ command_line.add_argument('--no-make-dirs', '-m',
command_line.add_argument('--quiet', '-q', command_line.add_argument('--quiet', '-q',
action='store_true', dest='quiet', action='store_true', dest='quiet',
help='suppress informative messages') help='suppress informative messages')
command_line.add_argument('--getexp', '-g', action='store_true',
help='load flat config (from getexp -vv)')
args = command_line.parse_args() args = command_line.parse_args()
...@@ -347,9 +349,12 @@ template_env.tests['set'] = lambda x: x.strip('.').lower().startswith('t') ...@@ -347,9 +349,12 @@ template_env.tests['set'] = lambda x: x.strip('.').lower().startswith('t')
extra_dict = ConfigObj(interpolation=False) extra_dict = ConfigObj(interpolation=False)
for assign in args.assigns: for assign in args.assigns:
extra_dict.merge(assign_to_dict(assign)) extra_dict.merge(assign_to_dict(assign))
extra_dict['mkexp_input'] = 'Generated by $$Id$$' extra_dict['mkexp_input'] = 'Generated by $Id$'
if not args.getexp:
extra_dict['mkexp_input'] = extra_dict['mkexp_input'].replace('$', '$$')
try: try:
config = ExpConfig(experiment_config_name, extra_dict, config_roots) config = ExpConfig(experiment_config_name, extra_dict, config_roots,
getexp=args.getexp)
except ExpConfigError as error: except ExpConfigError as error:
feedback.die(error.message, status=2) feedback.die(error.message, status=2)
...@@ -511,7 +516,7 @@ update_file.write('#! /bin/sh\n') ...@@ -511,7 +516,7 @@ update_file.write('#! /bin/sh\n')
update_file.write('#\n') update_file.write('#\n')
update_file.write('# Regenerate all files with identical configuration\n') update_file.write('# Regenerate all files with identical configuration\n')
update_file.write('#\n') update_file.write('#\n')
update_file.write('# ' + extra_dict['mkexp_input'] + '\n') update_file.write('# ' + extra_dict['mkexp_input'].replace('$$', '$') + '\n')
update_file.write('#\n') update_file.write('#\n')
update_file.write('cd ' + quote(os.getcwd()) + '\n') update_file.write('cd ' + quote(os.getcwd()) + '\n')
update_file.write('PATH=' + quote(os.environ.get('PATH', '')) + '\n') update_file.write('PATH=' + quote(os.environ.get('PATH', '')) + '\n')
......
...@@ -132,6 +132,18 @@ class CommandLineTestCase(MkexpTestCase): ...@@ -132,6 +132,18 @@ class CommandLineTestCase(MkexpTestCase):
result = readfile('test/experiments/test0001/test0001.run') result = readfile('test/experiments/test0001/test0001.run')
self.assertIn(expected, result) self.assertIn(expected, result)
def test_getexp_option(self):
script_getexp = script("""
mkexp test0001.config
mv experiments/test0001 experiments/test0001.orig
getexp -vv test0001.config MODEL_DIR=. > test0001.getexp
mkexp --getexp test0001.getexp
""")
ignore = output(script_getexp)
expected = readfile('test/experiments/test0001.orig/test0001.run')
result = readfile('test/experiments/test0001/test0001.run')
self.assertMultiLineEqual(expected, result)
class ContentTestCase(MkexpTestCase): class ContentTestCase(MkexpTestCase):
def test_job_override(self): def test_job_override(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment