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

feat: adds tutor config edit #1099

Open
wants to merge 5 commits into
base: nightly
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions tutor/commands/config.py
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, hooks
from tutor import interactive as interactive_config
Expand Down Expand Up @@ -255,9 +259,41 @@ def patches_show(context: Context, name: str) -> None:
print(rendered)


@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}. Have you run 'tutor local launch' yet?"
)

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
# Calling "start" on a regular file opens it with the default editor.
# The second argument "" just means "don't give the window a custom title".
open_cmd = ["start", '""', config_file]
tecoholic marked this conversation as resolved.
Show resolved Hide resolved
else:
raise exceptions.TutorError(
f"Failed to find utility to launch an editor. Edit {config_file} with the editor of your choice."
)

subprocess.call(open_cmd)
kdmccormick marked this conversation as resolved.
Show resolved Hide resolved
click.echo(
"Remember to run 'tutor config save' after editing, to apply the changes to your environment."
)

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about adding a message at the end here along the lines of Remember to run 'tutor config save' in order to apply configuration edits to your environment.


config_command.add_command(save)
config_command.add_command(printroot)
config_command.add_command(printvalue)
patches_command.add_command(patches_list)
patches_command.add_command(patches_show)
config_command.add_command(patches_command)
config_command.add_command(edit)
Loading