-
Notifications
You must be signed in to change notification settings - Fork 434
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
feat: adds tutor config edit
#1099
base: nightly
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import os.path | ||
import subprocess | ||
import typing as t | ||
|
||
import click | ||
import click.shell_completion | ||
|
||
from shutil import which | ||
|
||
from tutor import config as tutor_config | ||
from tutor import env, exceptions, fmt | ||
from tutor import interactive as interactive_config | ||
|
@@ -230,8 +234,31 @@ def patches_list(context: Context) -> None: | |
renderer.print_patches_locations() | ||
|
||
|
||
@click.command(name="edit", help="Edit config.yml of the current environment") | ||
@click.pass_obj | ||
def edit(context: Context) -> None: | ||
config_file = tutor_config.config_path(context.root) | ||
|
||
if not os.path.isfile(config_file): | ||
raise exceptions.TutorError(f"Missing config file at {config_file}") | ||
|
||
open_cmd = None | ||
|
||
if which("open"): # MacOS & linux distributions that ship `open`. eg., Ubuntu | ||
open_cmd = ["open", config_file] | ||
elif which("xdg-open"): # Linux | ||
open_cmd = ["xdg-open", config_file] | ||
elif which("start"): # Windows | ||
open_cmd = ["start", '""', config_file] | ||
else: | ||
raise exceptions.TutorError(f"Failed to find utility to launch an editor.") | ||
|
||
subprocess.call(open_cmd) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This command will do something funky if the file or its directory does not exist. I suggest the command should fail if the config file does not exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch! The |
||
|
||
|
||
config_command.add_command(save) | ||
config_command.add_command(printroot) | ||
config_command.add_command(printvalue) | ||
patches_command.add_command(patches_list) | ||
config_command.add_command(patches_command) | ||
config_command.add_command(edit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the error message, we can specify which utilities are used by the command internally so that user can install them on the system if needed (not all the users of Tutor are dev, some are operators who might not want to delve into code to see what is happening under the hood).