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

Support Editor env with options in config edit #7391

Closed
wants to merge 1 commit into from

Conversation

haooodev
Copy link

@haooodev haooodev commented Nov 22, 2019

Generally the EDITOR env is a single string referring to a program but
nothing prevents user from attaching options within it. To fully conform
to the convention pip config edit should split the env first.

Fixes #7392.

Generally Eidtor env is a single string referring to a program but
nothing prevents user from attaching options within it. To fully conform
to the convention `pip config edit` should split the env first.
@uranusjr
Copy link
Member

uranusjr commented Nov 22, 2019

Could you provide reference whether this is the right thing to do? I briefly searched, but all references I found to the EDITOR environ only mentions setting it to a command, not command + arguments. The current implementation also wouldn’t work well on Windows, where editors are usually installed with a space in the path (e.g. C:\Program Files).

Copy link
Member

@chrahunt chrahunt left a comment

Choose a reason for hiding this comment

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

This could be a reasonable approach that addresses the point raised by @uranusjr:

def get_editor_cmd():
    editor = os.environ["EDITOR"]
    result = shutil.which(editor)
    if result:
        return [result]
    if os.path.exists(editor):
        return [editor]
    return shlex.split(editor)

Then if we want to deprecate non-shell-syntax in the future we could warn if os.path.exists(editor) and ([editor] != shlex.split(editor)).

We would also need tests for this.

(discussion on whether to do this is on #7392).

@pradyunsg
Copy link
Member

Thanks for experimenting with this @chrahunt! So, we should do this.

I think we should pass shell=True into the subprocess call, instead of trying to figure out what to invoke directly -- it'll be the responsibility of the user to do the escaping properly, but at least, the invocation would be similar to how svn seems to be doing it.

@pfmoore
Copy link
Member

pfmoore commented Dec 21, 2019

Be careful to test shell=True on Windows. Cross platform argv handling is very tricky, and switching from shell=False to shell=True could easily trigger regressions.

I'm not saying don't use shell=True, just that unless there's a good reason to change, it may not be worth the risk. I'd rather we split the EDITOR variable and passed it as arguments, rather than pass it uninterpreted to the shell.

Actually, there may be other issues too - has anyone considered how switching to shell=True would handle EDITOR='vi $(rm -rf /)' for example?

@chrahunt
Copy link
Member

I think we should pass shell=True into the subprocess call, instead of trying to figure out what to invoke directly -- it'll be the responsibility of the user to do the escaping properly, but at least, the invocation would be similar to how svn seems to be doing it.

This would be backwards-incompatible and may be less obvious for users who just want to set their editor path directly. I updated my previous comment with an example implementation in case that makes it clearer how much code we're talking about.

Actually, there may be other issues too - has anyone considered how switching to shell=True would handle EDITOR='vi $(rm -rf /)' for example?

I don't think using shell=True changes the risk. With the current implementation that only accepts a path to a single executable, someone could set EDITOR=/script/that/has/rm-rf-slash for example.

@uranusjr
Copy link
Member

@chrahunt’s suggestion looks good to me, except shutil.which is not available on 2.7 :(

@chrahunt
Copy link
Member

chrahunt commented Mar 4, 2020

It has been some time without movement on this, so I will close it. I've left a comment on #7392 with details for anyone that wants to pick this back up.

@chrahunt chrahunt closed this Mar 4, 2020
@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Apr 4, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pip config and $EDITOR containing arguments
5 participants