From 59f8cc276aa693e5db7e415699f57625a5e4e172 Mon Sep 17 00:00:00 2001 From: David Pomeroy Date: Wed, 18 Dec 2024 16:46:42 +0000 Subject: [PATCH 1/2] Add new yaml files to `ramble workspace edit` Adds ability for `ramble workspace edit` to open applications.yaml, modifiers.yaml, and software.yaml within the workspace config directory. --- lib/ramble/ramble/cmd/workspace.py | 45 +++++++++++++++++++++++- lib/ramble/ramble/test/cmd/workspace.py | 8 +++++ lib/ramble/ramble/workspace/__init__.py | 12 +++++++ lib/ramble/ramble/workspace/workspace.py | 18 ++++++++++ share/ramble/ramble-completion.bash | 2 +- 5 files changed, 83 insertions(+), 2 deletions(-) diff --git a/lib/ramble/ramble/cmd/workspace.py b/lib/ramble/ramble/cmd/workspace.py index 76151431b..7a38a4c1e 100644 --- a/lib/ramble/ramble/cmd/workspace.py +++ b/lib/ramble/ramble/cmd/workspace.py @@ -848,6 +848,33 @@ def workspace_edit_setup_parser(subparser): required=False, ) + subparser.add_argument( + "-a", + "--applications_only", + dest="applications_only", + action="store_true", + help="Only open applications files", + required=False, + ) + + subparser.add_argument( + "-m", + "--modifiers_only", + dest="modifiers_only", + action="store_true", + help="Only open modifiers files", + required=False, + ) + + subparser.add_argument( + "-s", + "--software_only", + dest="software_only", + action="store_true", + help="Only open software files", + required=False, + ) + subparser.add_argument( "-t", "--template_only", @@ -881,12 +908,28 @@ def workspace_edit(args): ) config_file = ramble.workspace.config_file(ramble_ws) + applications_file = ramble.workspace.applications_file(ramble_ws) + modifiers_file = ramble.workspace.modifiers_file(ramble_ws) + software_file = ramble.workspace.software_file(ramble_ws) template_files = ramble.workspace.all_template_paths(ramble_ws) - edit_files = [config_file] + template_files + edit_files = [config_file] + optional_files = [applications_file, modifiers_file, software_file] + + for file in optional_files: + if file and os.path.exists(file): + edit_files.append(file) + + edit_files.extend(template_files) if args.config_only: edit_files = [config_file] + elif args.applications_only: + edit_files = [applications_file] + elif args.modifiers_only: + edit_files = [modifiers_file] + elif args.software_only: + edit_files = [software_file] elif args.template_only: edit_files = template_files elif args.license_only: diff --git a/lib/ramble/ramble/test/cmd/workspace.py b/lib/ramble/ramble/test/cmd/workspace.py index 5f267f47c..9629690ae 100644 --- a/lib/ramble/ramble/test/cmd/workspace.py +++ b/lib/ramble/ramble/test/cmd/workspace.py @@ -866,10 +866,18 @@ def test_edit_edits_correct_paths(): ws.write() config_file = ramble.workspace.config_file(ws.root) + applications_file = ramble.workspace.applications_file(ws.root) + modifiers_file = ramble.workspace.modifiers_file(ws.root) + software_file = ramble.workspace.software_file(ws.root) default_template_path = ws.template_path("execute_experiment") ws_args = ["-w", "test"] assert workspace("edit", "-c", "--print-file", global_args=ws_args).strip() == config_file + assert ( + workspace("edit", "-a", "--print-file", global_args=ws_args).strip() == applications_file + ) + assert workspace("edit", "-m", "--print-file", global_args=ws_args).strip() == modifiers_file + assert workspace("edit", "-s", "--print-file", global_args=ws_args).strip() == software_file assert ( workspace("edit", "-t", "--print-file", global_args=ws_args).strip() == default_template_path diff --git a/lib/ramble/ramble/workspace/__init__.py b/lib/ramble/ramble/workspace/__init__.py index 5a3cdad71..85992a07c 100644 --- a/lib/ramble/ramble/workspace/__init__.py +++ b/lib/ramble/ramble/workspace/__init__.py @@ -32,6 +32,12 @@ get_workspace_path, config_file, config_file_name, + applications_file, + applications_file_name, + modifiers_file, + modifiers_file_name, + software_file, + software_file_name, licenses_file, licenses_file_name, metadata_file_name, @@ -72,6 +78,12 @@ "get_workspace_path", "config_file", "config_file_name", + "applications_file", + "applications_file_name", + "modifiers_file", + "modifiers_file_name", + "software_file", + "software_file_name", "licenses_file", "licenses_file_name", "metadata_file_name", diff --git a/lib/ramble/ramble/workspace/workspace.py b/lib/ramble/ramble/workspace/workspace.py index 63452e143..5d4a2c775 100644 --- a/lib/ramble/ramble/workspace/workspace.py +++ b/lib/ramble/ramble/workspace/workspace.py @@ -104,6 +104,9 @@ config_schema = ramble.schema.workspace.schema config_section = "workspace" config_file_name = "ramble.yaml" +applications_file_name = "applications.yaml" +modifiers_file_name = "modifiers.yaml" +software_file_name = "software.yaml" licenses_file_name = "licenses.yaml" metadata_file_name = "workspace_metadata.yaml" @@ -269,6 +272,21 @@ def config_file(path): return get_yaml_filepath(path, config_file_name) +def applications_file(path): + """Returns the path to a workspace's applications.yaml""" + return get_yaml_filepath(path, applications_file_name) + + +def modifiers_file(path): + """Returns the path to a workspace's modifiers.yaml""" + return get_yaml_filepath(path, modifiers_file_name) + + +def software_file(path): + """Returns the path to a workspace's software.yaml""" + return get_yaml_filepath(path, software_file_name) + + def licenses_file(path): """Returns the path to a workspace's licenses.yaml""" return get_yaml_filepath(path, licenses_file_name) diff --git a/share/ramble/ramble-completion.bash b/share/ramble/ramble-completion.bash index 86d42b1ad..3ac5cbbe5 100755 --- a/share/ramble/ramble-completion.bash +++ b/share/ramble/ramble-completion.bash @@ -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 -c --config_only -a --applications_only -m --modifiers_only -s --software_only -t --template_only -l --license_only -p --print-file" } _ramble_workspace_mirror() { From 3809e5ac20400d3cb382c2fc66aafd4da7736384 Mon Sep 17 00:00:00 2001 From: David Pomeroy Date: Thu, 19 Dec 2024 18:43:22 +0000 Subject: [PATCH 2/2] Add `--all' option to open all yaml files Adds `--all` to open all yaml files in workspace config directory. --- lib/ramble/ramble/cmd/workspace.py | 10 ++++++++++ lib/ramble/ramble/workspace/__init__.py | 2 ++ lib/ramble/ramble/workspace/workspace.py | 12 ++++++++++++ share/ramble/ramble-completion.bash | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/ramble/ramble/cmd/workspace.py b/lib/ramble/ramble/cmd/workspace.py index 7a38a4c1e..46a81c47b 100644 --- a/lib/ramble/ramble/cmd/workspace.py +++ b/lib/ramble/ramble/cmd/workspace.py @@ -893,6 +893,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" ) @@ -935,6 +943,8 @@ def workspace_edit(args): 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: diff --git a/lib/ramble/ramble/workspace/__init__.py b/lib/ramble/ramble/workspace/__init__.py index 85992a07c..0eb66ea55 100644 --- a/lib/ramble/ramble/workspace/__init__.py +++ b/lib/ramble/ramble/workspace/__init__.py @@ -38,6 +38,7 @@ modifiers_file_name, software_file, software_file_name, + all_config_files, licenses_file, licenses_file_name, metadata_file_name, @@ -84,6 +85,7 @@ "modifiers_file_name", "software_file", "software_file_name", + "all_config_files", "licenses_file", "licenses_file_name", "metadata_file_name", diff --git a/lib/ramble/ramble/workspace/workspace.py b/lib/ramble/ramble/workspace/workspace.py index 5d4a2c775..db5ac755c 100644 --- a/lib/ramble/ramble/workspace/workspace.py +++ b/lib/ramble/ramble/workspace/workspace.py @@ -292,6 +292,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"): + 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) diff --git a/share/ramble/ramble-completion.bash b/share/ramble/ramble-completion.bash index 3ac5cbbe5..2b487a2c4 100755 --- a/share/ramble/ramble-completion.bash +++ b/share/ramble/ramble-completion.bash @@ -693,7 +693,7 @@ _ramble_workspace_info() { } _ramble_workspace_edit() { - RAMBLE_COMPREPLY="-h --help -c --config_only -a --applications_only -m --modifiers_only -s --software_only -t --template_only -l --license_only -p --print-file" + RAMBLE_COMPREPLY="-h --help -c --config_only -a --applications_only -m --modifiers_only -s --software_only -t --template_only -l --license_only --all -p --print-file" } _ramble_workspace_mirror() {