Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new yaml files to ramble workspace edit #803

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/ramble/ramble/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,15 @@ def workspace_list(args):

def workspace_edit_setup_parser(subparser):
"""edit workspace config or template"""
subparser.add_argument(
"-f",
"--file",
dest="filename",
default=None,
help="Open a single file by filename",
required=False,
)

subparser.add_argument(
"-c",
"--config_only",
Expand Down Expand Up @@ -866,6 +875,14 @@ def workspace_edit_setup_parser(subparser):
required=False,
)

subparser.add_argument(
"--all",
dest="all_files",
action="store_true",
help="Open all yaml and template files in workspace config directory",
required=False,
)

subparser.add_argument(
"-p", "--print-file", action="store_true", help="print the file name that would be edited"
)
Expand All @@ -883,15 +900,20 @@ def workspace_edit(args):
config_file = ramble.workspace.config_file(ramble_ws)
template_files = ramble.workspace.all_template_paths(ramble_ws)

edit_files = [config_file] + template_files
edit_files = [config_file]
edit_files.extend(template_files)

if args.config_only:
if args.filename:
edit_files = [ramble.workspace.get_yaml_filepath(ramble_ws, args.filename)]
dapomeroy marked this conversation as resolved.
Show resolved Hide resolved
elif args.config_only:
edit_files = [config_file]
elif args.template_only:
edit_files = template_files
elif args.license_only:
licenses_file = [ramble.workspace.licenses_file(ramble_ws)]
edit_files = licenses_file
elif args.all_files:
edit_files = ramble.workspace.all_config_files(ramble_ws) + template_files

if args.print_file:
for f in edit_files:
Expand Down
4 changes: 4 additions & 0 deletions lib/ramble/ramble/test/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,10 @@ def test_edit_edits_correct_paths():
default_template_path = ws.template_path("execute_experiment")

ws_args = ["-w", "test"]
assert (
workspace("edit", "-f", "ramble.yaml", "--print-file", global_args=ws_args).strip()
== config_file
)
assert workspace("edit", "-c", "--print-file", global_args=ws_args).strip() == config_file
assert (
workspace("edit", "-t", "--print-file", global_args=ws_args).strip()
Expand Down
4 changes: 4 additions & 0 deletions lib/ramble/ramble/workspace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
exists,
is_workspace_dir,
get_workspace_path,
get_yaml_filepath,
config_file,
config_file_name,
all_config_files,
licenses_file,
licenses_file_name,
metadata_file_name,
Expand Down Expand Up @@ -70,8 +72,10 @@
"exists",
"is_workspace_dir",
"get_workspace_path",
"get_yaml_filepath",
"config_file",
"config_file_name",
"all_config_files",
"licenses_file",
"licenses_file_name",
"metadata_file_name",
Expand Down
12 changes: 12 additions & 0 deletions lib/ramble/ramble/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ def licenses_file(path):
return get_yaml_filepath(path, licenses_file_name)


def all_config_files(path):
"""Returns path to all yaml files in workspace config directory"""
config_files = []

config_path = os.path.join(path, workspace_config_path)
for f in os.listdir(config_path):
if f.endswith(".yaml"):
dapomeroy marked this conversation as resolved.
Show resolved Hide resolved
config_files.append(os.path.join(config_path, f))

return config_files


def template_path(ws_path, requested_template_name):
"""Returns the path to a workspace's template file"""
config_path = os.path.join(ws_path, workspace_config_path)
Expand Down
2 changes: 1 addition & 1 deletion share/ramble/ramble-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ _ramble_workspace_info() {
}

_ramble_workspace_edit() {
RAMBLE_COMPREPLY="-h --help -c --config_only -t --template_only -l --license_only -p --print-file"
RAMBLE_COMPREPLY="-h --help -f --file -c --config_only -t --template_only -l --license_only --all -p --print-file"
}

_ramble_workspace_mirror() {
Expand Down
Loading