-
Notifications
You must be signed in to change notification settings - Fork 443
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: main
Are you sure you want to change the base?
feat: adds tutor config edit
#1099
Conversation
tutor/commands/config.py
Outdated
@click.command(name="edit", help="Edit config.yml of the current environment") | ||
@click.pass_obj | ||
def edit(context: Context) -> None: | ||
config_file = os.path.join(context.root, "config.yml") |
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.
Use config.config_path(context.root)
instead.
tutor/commands/config.py
Outdated
elif which("start"): # Windows | ||
open_cmd = ["start", '""', config_file] | ||
else: | ||
click.echo( |
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.
This command should fail if neither open commands are available. You could for instance raise exceptions.TutorError
.
tutor/commands/config.py
Outdated
open_cmd = ["start", '""', config_file] | ||
else: | ||
click.echo( | ||
"Cannot find a way to open the editor automatically. Kindly open the file manually: " |
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.
Let's rephrase that along the lines of: "Failed to detect an adequate text file editor". (mode concise, no need for "kindly")
@regisb Hi, Thanks for the review comments. I hoped to have addressed them by now. Somehow haven't found the time. I will handle the comments this week. |
I have nothing to add beyond Regis's review--just want to say that this is a great idea and thank you for the contribution 👍🏻 |
ecf0b53
to
853e51e
Compare
853e51e
to
c095e45
Compare
Hi @tecoholic . I'm looking forward to this change! Looks like there are just a couple minor change requests left, and then we're good to merge this. |
@kdmccormick Hi, thanks for the ping. I was waiting on @regisb for more details about read only editor. Can we skip that scenario for now? |
@kdmccormick I am less interested in this feature than you seem to be -- mostly because (IMHO) it doesn't bring anything more than a .bashrc alias. E.g: |
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.
Thanks for the patience @tecoholic . If you can rebase and address these comments, I'll be happy to merge this.
c095e45
to
2b00211
Compare
@kdmccormick Thank you for your comments and your patience with this PR. I have addressed your comments to my best. Kindly take another look when you can. |
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.
Please add a changelog entry for this change.
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.
I tested locally, works great on Ubuntu! I also commented out the which("open")
block in order to confirm that xdg-open
also works.
In addition to Dawoud's request to add a changelog entry, I have just one more change request and one optional suggestion ⬇️
@@ -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") |
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.
Optional: What do you think about adding a -s/--save
flag here? If supplied, then instead of reminding the user to run tutor config save
, it would just save config automatically.
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.
This was something I thought of adding later based on user feedback. Now that you have pointed it out, I have taken it as the feeback and added 2 features I think are QOL improvments.
-s
automatically updating the environment after a successful save. The caveat here is "successful save". More on them below.-e
to specify an editor of choice. The annoying thing about desktop systems is, installing new software somehow messes up file associations. I discovered after installing KDE that my YAML files now open in Kate Editor. Now I dotutor config edit -e (vim|emacs|..)
to open the file in a specific editor.
Save caveats:
- Sometimes, when I do
:wq
in Neovim (Lazyvim config), it returns a non-zero error code. This prevents the "save" from happening. - When the file gets opened in a GUI editor like Kate, it opens it as an independent process, instead of subprocess. So the
utils.execute()
returns as soon as the editor is launched instead of return after the editor is closed. So, the environment is updated with config before editing.
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.
Thank you for spelling out those caveats.
Sometimes, when I do :wq in Neovim (Lazyvim config), it returns a non-zero error code. This prevents the "save" from happening.
Could you catch this error, and if --save
was provided, warn the user that the editor exited non-zero and thus their config changes were not applied?
When the file gets opened in a GUI editor like Kate, it opens it as an independent process, instead of subprocess. So the utils.execute() returns as soon as the editor is launched instead of return after the editor is closed. So, the environment is updated with config before editing.
Ah, this one is a bit worrying. Visual editors often will accept a flag that blocks the command until the editor is exited, e.g. subl --wait
for Sublime Text. That would be useful for this particular scenario, e.g.,:
tutor config edit -s -e 'subl --wait'
This will fail with your current code, but could be fixed by running shlex.split
on the -e
argument.
All that said, with all details and nuances that these new flags make us consider, I feel that we are delaying the tutor config edit
feature more than we need to. It would be nice to have the base command Sumac. @tecoholic how would you feel about omitting -s
and -e
for now, and opening a follow-up PR to add them?
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.
@kdmccormick Thanks for taking another look. I agree with your assessment about the flags being a bit suboptimal. That's the reason, I initially only considered them as future improvements.
So, I will roll back those bits and leave the bare command alone in this PR.
Quickly launch the default YAML editor for editing the config.yml file.
Co-authored-by: Kyle McCormick <[email protected]>
Co-authored-by: Kyle McCormick <[email protected]>
00565bb
to
d3cd4c0
Compare
@kdmccormick Thank you for the feedback. I added a changelog entry, new options |
changelog.d/20241114_115534_arunmozhi_add_config_edit_command.md
Outdated
Show resolved
Hide resolved
changelog.d/20241114_115534_arunmozhi_add_config_edit_command.md
Outdated
Show resolved
Hide resolved
@DawoudSheraz I have addressed your comments about the docs and updated the PR. |
tutor/commands/config.py
Outdated
click.echo( | ||
click.style( | ||
"💡 You can automatically update the environment after editing by setting the flag -s.\n" | ||
"e.g., `tutor config edit -s`", | ||
fg="blue", | ||
) | ||
) |
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.
Since the command's helptext already explains this, and we do not want to overwhelm the user with information, I don't think this message is necessary.
click.echo( | |
click.style( | |
"💡 You can automatically update the environment after editing by setting the flag -s.\n" | |
"e.g., `tutor config edit -s`", | |
fg="blue", | |
) | |
) |
@@ -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") |
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.
Thank you for spelling out those caveats.
Sometimes, when I do :wq in Neovim (Lazyvim config), it returns a non-zero error code. This prevents the "save" from happening.
Could you catch this error, and if --save
was provided, warn the user that the editor exited non-zero and thus their config changes were not applied?
When the file gets opened in a GUI editor like Kate, it opens it as an independent process, instead of subprocess. So the utils.execute() returns as soon as the editor is launched instead of return after the editor is closed. So, the environment is updated with config before editing.
Ah, this one is a bit worrying. Visual editors often will accept a flag that blocks the command until the editor is exited, e.g. subl --wait
for Sublime Text. That would be useful for this particular scenario, e.g.,:
tutor config edit -s -e 'subl --wait'
This will fail with your current code, but could be fixed by running shlex.split
on the -e
argument.
All that said, with all details and nuances that these new flags make us consider, I feel that we are delaying the tutor config edit
feature more than we need to. It would be nice to have the base command Sumac. @tecoholic how would you feel about omitting -s
and -e
for now, and opening a follow-up PR to add them?
@kdmccormick Updated the PR with simpler version. P.S: I left a reply to the comment in the review. But, it doesn't show up here. So, adding a note here, just in case. |
Quickly launch the default YAML editor for editing the
config.yml
file.Background
As a developer working with multiple projects, I am constantly changing the tutor config and re-running the
tutor dev launch
to update the devstack. While it is as simple as runningvim $(tutor config printroot)/config.yml
, I often found myself wanting to simply express this better using tutor config edit. So this is an attempt at cross-platform solution doing the same. It might not be the best solution, but something to start with if someone else finds this useful and improves their DevEx.Caveat: I have only tested this on Linux (both open and
xdg-open
works in mine, so it could be said Unix).