Repository navigation
py.exe launcher ignores [commands] from py.ini #100247
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Dec 14, 2022 Thinking about it some more, I question whether the call to
_findCommand()should be inside the loop overshebangTemplatesat all. That means that with a configuration of[commands] something/apython=C:\something\a\python.exe /usr/bin/something/apython=C:\something\b\python.exe
a script with shebang line
#!/usr/bin/something/apythonwill match the first line and be executed witha\python.exe. I see nothing of that sort specified in PEP 397. I would expect it to match the second line and chooseb\python.exe. To me, the order of bullet points in Shebang line parsing says that_findCommandshould come before before checking for virtual commands with one of the four known prefixes and should consider the entire command.(However it seems that this has already worked this way in the 3.9 and 3.10 launcher.)
I think what probably needs to happen here (writing my logic down so I can double check once this headache is over) is that the templates should require
python(i.e./usr/bin/python..., not/usr/bin/*), and then the fallback should check for custom commands before assuming it's an executable.I agree that the original PEP suggests the custom command should be checked first taking the entire first argument from the shebang, but as pointed out, that's not how it worked in the past. Implementation wins over the original propsal here (since the docs don't even mention this feature).
Thanks! I’ll give it a test when I’m back at my work Windows desktop, probably some time next week.
This bit worries me a little, though:
The name of the command must be a single argument (no spaces),
and the value substituted is the full path to the executable (no arguments
may be added).If that is true, then there may still be a regression compared to 3.11.0. The actual example we are using in our shipping product to make sure our scripts launch with our own Python installations on both Linux and Windows (which worked with the 3.9 launcher we ship but broke when users installed a 3.11.1 launcher) is
#!/opt/indel/bin/indel-python2 -uwith py.ini
[commands] /opt/indel/bin/indel-python2=C:\indel\share\python\python27\python.exe /opt/indel/bin/indel-pythonw2=C:\indel\share\python\python27\pythonw.exe /opt/indel/bin/indel-python3=C:\indel\share\python\python3\amd64\python.exe /opt/indel/bin/indel-pythonw3=C:\indel\share\python\python3\amd64\pythonw.exe /opt/indel/bin/indel-python=C:\indel\share\python\python3\amd64\python.exe /opt/indel/bin/indel-pythonw=C:\indel\share\python\python3\amd64\pythonw.exewhere on Linux /opt/indel/bin/indel-python* are symlinks to the appropriate interpreter while the Windows paths are the actual installation locations.
(I’m not 100% certain we really need the
-u, but it could be because some scripts relay output from other processes that may include progress indicators that should not be line-buffered.)Those are all fine. What it means is that you can't use
/opt/indel/bin/indel-python2 -uas the command name - it'll stop looking at the first space.Also, you can't use
C:\indel\share\python\python27\python.exe -uas the right-hand side of the setting, because the whole thing is passed as the executable name, and is quoted when put into the command line.Ah, OK. That makes sense. “name of the command” refers to the the py.ini entry, not to the shebang line.
I have tested it now and it works perfectly for our purposes. Thanks again!
It even fixes the paradoxical behavior I mentioned in #100247 (comment), which makes me happy.
Reacted by Steve Dower
Bug report
This is a regression between Python 3.11.0 and 3.11.1. Since 46a3cf4 (88297e2, #98692), py.exe no longer observes the “custom commands” mapping under
[commands]in py.ini defining additional “virtual commands” (unless the virtual command starts with the same prefix as one of the four predefined virtual commands), but directly tries to launch the virtual command as an executable.Steps to reproduce:
%WINDIR%\py.ini:
test.py:
Expected result (and actual up to 3.11.0):
Actual result:
I seem to be able to fix this as follows, which satisfies the existing tests, however this code is such a complex tangle of special cases that I have no idea whether it is the right thing to do. (The idea is that the loop over
shebangTemplatesshould always find exactly one match, which was previously (before the regression) ensured by the empty template, so that_findCommand()is always called. Checking fortmpl != &shebangTemplates[0]is needed to satisfytest_recursive_search_path, however it might exclude too much – maybesearchPath()should instead report explicitly that it skipped a recursive call.)Your environment
Linked PRs