-
Notifications
You must be signed in to change notification settings - Fork 3.1k
More robust shebang manipulation #12599
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
Comments
Note that pip already has access to the shell script hack via vendored distlib. So we can maybe reuse that logic to minimise things to implement. |
Today I learned that although the shebang hack in distlib does in fact allow a script with spaces in the interpreter path to be executed by bash:
I don't yet understand why the subprocess invocation is unable to honor the sh+exec hack. Note, I generated that header with:
|
Oh. The issue seems to be related to me using
It took only a small amount of investigation to determine the cause - for whatever reason, under xonsh when launched as the user's default shell, |
OMG, I really hope people doesn't have to use and resort to these kinds of hacks:
It breaks all portability possible! |
Reading through the history of this it's not clear to me what is being reported as a pip bug? Does someone have a MRE where pip is producing the wrong shebang? |
@Gitznik implies it’s installing something on macOS, but I can’t trivially reproduce that: pypa/pipx#1327 (comment) @Gitznik can you provide a MRE? |
This has been discussed before, and people have pointed to Unix systems (freebsd?) that don't support multiple arguments in shebang lines. If you look at Wikipedia, it states under "Argument splitting":
I don't have details, and I don't really have much interest in what we end up doing here, but basically the answer is "because no-one is able to confirm that it won't break someone". |
So if the pipx maintainers can provide a MRE where pip’s approach breaks and we can’t fix it using only POSIX stuff, the only possible solutions that I can think of would be
|
or:
|
Absolutely not accepting this, we should have moved past this 40 years ago as a profession. In the last 12 years, I had exactly one very minor problem while having my dev directory contain a space: Chrome didn’t build, which officially makes it the most crusty build system I’ve encountered in that whole time. Like, I did a lot of very experimental things in there, trying to build many many venerable projects with old build systems. No problem, except with Chrome. Only pipx suddenly complaining to me made me aware that somehow something still hasn’t solved this very basic problem. Not solving it is not an option for me. PS: I dimly recall that once or twice, something broke, but a 2-character-diff PR by me that was merged within a few days fixed the problem forever. I’m not counting these. Only Chrome was so bad that it wasn’t fixed immediately. |
Agreed. Tell the Unix systems that don't handle shebangs with spaces in the path. On a more practical note, if anyone can provide a solution that doesn't break systems that have limited shebang support, we'll gladly accept a PR (or more likely, a new release of distlib that contains such a PR, as I think we just inherit distlib's behaviour here). Personally, I'd even be willing to accept a sufficiently compelling argument that we don't need to support such limited systems - although I'd be likely to just revert the change if it turned out that we did break someone's environment. |
As said:
Which one do you think makes more sense to pursue, or do you have any other ideas? PS: I really don’t see why “just don’t use spaces” is being brought up here at all. That’s a user-side workaround. Users have been informed that it exists as a crutch until the bug is fixed. Isn’t an issue tracker about actually fixing the bug? |
Personally I think (2) is the only reasonable option. I don’t believe “tell people to bully their OS1” is productive or helpful. Speaking as a Windows user, I don’t like (3), and I wish Windows had shebang support in the OS. Bullying Microsoft to add it wouldn’t work, though… Footnotes
|
IIRC arguments did not even work on macOS back when this was reported. Maybe this had changed, but compatibility is still a thing. I also think 2 is the only practical option. |
OK, so Linux actually came last.
|
What are you referring to here? Are you talking about the So, suppose you have
There are operating system kernels out there which will treat that as a request to run the executable |
Totally missed that, sorry. OK, let me get this straight, please correct me if I misunderstood anything:
Footnotes
|
The "sh triple-quote" hack is implemented by distlib, which we use. Non-console scripts aren't acually a thing on Unix (which is the only place the sh trick is used) are they? Why would you use If you want distlib to use the sh trick for GUI scripts on Unix, then you should open an issue there. Ultimately, this is nothing to do with pip, it's all implemented by distlib. (We could override distlib's behaviour, but as a matter of policy we avoid doing that). |
As far as I can tell, the OP's problem was actually related to xonsh. I'm not sure why pipx got brought into the discussion, or how it's relevant. I suggest that if there is a problem in pipx (the linked comment makes a claim about how pip behaves, but I'm not sure it's accurate based on this thread) then someone should open a new issue, with a reproducible example, and explaining clearly why it's a pip issue and not a distlib issue (given what's been said here about pip simply inheriting distlib's behaviour). Closing this, as the original issue seems to have been resolved. |
OK, I re-filed the bug after creating a reproducer and making sure that it’s really a pip bug: #13389 |
Uh oh!
There was an error while loading. Please reload this page.
What's the problem this feature will solve?
When pip installs (non-"console script") scripts to an environment with spaces in the pathname, it supplies the interpreter name in the script but doesn't escape the space(s) in any way, leading to failures:
Although the root cause is a long-standing problem with Unix itself, some shells like xonsh do support them:
Moreover, the Python launcher for Windows also supports them.
Lack of support for spaces in filenames leads to problems like pypa/pipx#1198 when applications attempt to install to the platform-recommended directories.
Describe the solution you'd like
When rewriting the shebangs for scripts during install, wrap the interpreter in quotes when it contains spaces.
Other shells like bash and zsh will still choke on the space, but at least they'll have the opportunity to potentially honor them, and in the meantime, users of shells like xonsh can enjoy a working executable. It's one small step toward honoring valid pathnames and strengthening a precedent for a workable solution that those shells could honor.
Alternative Solutions
One might be tempted to suggest that users should just avoid paths with spaces in filenames, and although that kind of bullying is the norm in Linux, on other platforms like Windows and macOS, the platform guidance itself specifies to install scripts and applications and other things in paths with spaces (e.g.
C:\Program Files
,~/Library/Application Support
).Another option might be to apply the somewhat wonky exec wrapper used for console scripts:
Additional context
none
Code of Conduct
The text was updated successfully, but these errors were encountered: