Skip to content

Commit

Permalink
Merge pull request #376 from rfbgo/fix_template_create
Browse files Browse the repository at this point in the history
Ramble creates `execute_experiment.tpl` when a config and template are provided
  • Loading branch information
douglasjacobsen authored Jan 18, 2024
2 parents bb38c60 + cdc4bf5 commit cd61b83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
28 changes: 24 additions & 4 deletions lib/ramble/ramble/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,39 @@ def _workspace_create(name_or_path, dir=False,
create the workspace with
"""

# Sanity check file paths, to avoid half-creating an incomplete workspace
for filepath in [config, template_execute]:
if filepath and not os.path.isfile(filepath):
logger.die(f"{filepath} file path invalid")

read_default_template = True

# Disallow generation of default template when both a config and a template
# are specified
if config and template_execute:
read_default_template = False

if dir:
workspace = ramble.workspace.Workspace(name_or_path)
workspace.write()
workspace = ramble.workspace.Workspace(
name_or_path,
read_default_template=read_default_template)

logger.msg(f"Created workspace in {workspace.path}")
logger.msg("You can activate this workspace with:")
logger.msg(f" ramble workspace activate {workspace.path}")

else:
workspace = ramble.workspace.create(name_or_path)
workspace.write()
workspace = ramble.workspace.create(
name_or_path,
read_default_template=read_default_template)

workspace.read_default_template = read_default_template
logger.msg(f"Created workspace in {name_or_path}")
logger.msg("You can activate this workspace with:")
logger.msg(f" ramble workspace activate {name_or_path}")

workspace.write()

if config:
with open(config, 'r') as f:
workspace._read_config('workspace', f)
Expand Down
9 changes: 5 additions & 4 deletions lib/ramble/ramble/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,12 @@ def is_workspace_dir(path):
return ret_val


def create(name):
def create(name, read_default_template=True):
"""Create a named workspace in Ramble"""
validate_workspace_name(name)
if exists(name):
raise RambleWorkspaceError("'%s': workspace already exists" % name)
return Workspace(root(name))
return Workspace(root(name), read_default_template=read_default_template)


def config_dict(yaml_data):
Expand Down Expand Up @@ -448,13 +448,14 @@ class Workspace(object):
inventory_file_name = 'ramble_inventory.json'
hash_file_name = 'workspace_hash.sha256'

def __init__(self, root, dry_run=False):
def __init__(self, root, dry_run=False, read_default_template=True):
logger.debug(f'In workspace init. Root = {root}')
self.root = ramble.util.path.canonicalize_path(root)
self.txlock = lk.Lock(self._transaction_lock_path)
self.dry_run = dry_run
self.always_print_foms = False

self.read_default_template = read_default_template
self.configs = ramble.config.ConfigScope('workspace', self.config_dir)
self._templates = {}
self._auxiliary_software_files = {}
Expand Down Expand Up @@ -553,7 +554,7 @@ def _read(self):
with open(self.config_file_path) as f:
self._read_config(config_section, f)

read_default_script = True
read_default_script = self.read_default_template
ext_len = len(workspace_template_extension)
if os.path.exists(self.config_dir):
for filename in os.listdir(self.config_dir):
Expand Down

0 comments on commit cd61b83

Please sign in to comment.