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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
55 changes: 54 additions & 1 deletion lib/ramble/ramble/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -866,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"
)
Expand All @@ -881,17 +916,35 @@ 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there potentially more such "include" files that we want to be able to edit? Would it make sense to have an --all option to open up all yaml files under the config directory, and then maybe another --name option to allow opening up specific ones (like ramble workspace edit --name applications to edit the applications.yaml file?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love some feedback from Bob/Doug here. Yes, users could definitely add more files than just these and I think your two suggestions are good additions. It might also be nice for '--all' to open included files as well.

And as I'm using Ramble myself, I don't want to have to type out all those chars, which don't tab complete, to open just the 'applications.yaml' file. I like the convenience of having '-a' short flag for it. Do you think that having all these individual flags and options is making the interface too complex, or is it ok?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I like and agree with all of the suggestion from both. I think --all is good idea too (but definitely don't want that to be the default behavior)

Slight preference for -a over --type applications personally, but am OK with either

My overall take is that we should make the top(n) operations quick and easy, but we do not have to solve complex or edge cases and the user should cd $RAMBLE_WORKSPACE; vim ... for that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Bob. The way it's written now, it keeps current behavior of opening ramble.yaml and templates by default. If they exist, it also opens applications, modifiers, and software. Adds flags for those 3 to support quick editing of them. Why don't I add in '--all' to cover cases where someone may use other filenames, and leave it there. Nothing changes in the workflow for existing users with just ramble.yaml, it works automatically if a user chooses to create app/mod/software files, and adds an easy option to open every yaml just in case someone wants it.

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:
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
8 changes: 8 additions & 0 deletions lib/ramble/ramble/test/cmd/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions lib/ramble/ramble/workspace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
get_workspace_path,
config_file,
config_file_name,
applications_file,
applications_file_name,
modifiers_file,
modifiers_file_name,
software_file,
software_file_name,
all_config_files,
licenses_file,
licenses_file_name,
metadata_file_name,
Expand Down Expand Up @@ -72,6 +79,13 @@
"get_workspace_path",
"config_file",
"config_file_name",
"applications_file",
"applications_file_name",
"modifiers_file",
"modifiers_file_name",
"software_file",
"software_file_name",
"all_config_files",
"licenses_file",
"licenses_file_name",
"metadata_file_name",
Expand Down
30 changes: 30 additions & 0 deletions lib/ramble/ramble/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -269,11 +272,38 @@ 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)


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 -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() {
Expand Down
Loading