Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release'
Browse files Browse the repository at this point in the history
  • Loading branch information
Overhang.IO committed Dec 6, 2024
2 parents e944dbb + dd731c0 commit 00648b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Feature] Adds `tutor config edit`. This opens the active tutor environment's config.yaml in an editor for manual editing. (by @tecoholic)
33 changes: 32 additions & 1 deletion tutor/commands/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from __future__ import annotations

import json
import os.path
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
from tutor import serialize
from tutor import serialize, utils
from tutor.commands.context import Context
from tutor.commands.params import ConfigLoaderParam
from tutor.types import Config, ConfigValue
Expand Down Expand Up @@ -255,9 +258,37 @@ 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 = []
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]
else:
raise exceptions.TutorError(
f"Failed to find utility to launch an editor. Edit {config_file} with the editor of your choice."
)

utils.execute(*open_cmd)


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)

0 comments on commit 00648b9

Please sign in to comment.