Install source and version
Version: 26.2
Describe the bug
In scriptutils.py, _find_shebang_command uses pathlib.PurePath.match(), which performs right-aligned suffix matching. This inadvertently intercepts explicit absolute paths and feeds them into bare-name routing rules.
When installing certain packages via uv (specifically older packages using setup.py that drop .py scripts with absolute shebangs rather than .exe entry-point shims), or when a script utilizes its own local python.exe (such as in a venv), the absolute shebang is falsely intercepted. This prevents the path from reaching _find_on_path(). Instead:
- Paths ending in
python.exe trigger the is_default check, hijacking execution to the global environment.
- Paths ending in
python*.exe (e.g., python_test.exe) bypass the default check and fall through to the wildcard fallback, which slices the string ([6:-4]) and crashes while looking for a non-existent tag.
To Reproduce
Steps to reproduce the behavior:
- Create or install a script utilizing an isolated local environment (e.g., an older
setup.py package installed via uv that relies on a shebang, or a standard venv).
- Set the shebang to the absolute path of that isolated executable (e.g.,
#!C:\path\to\env\Scripts\python.exe).
NOTE: This is uv's default behavior for older packages.
- Execute the script via
pymanager (py.exe example_script.py) or directly if py files are already associated with it.
- Observe that the script ignores the absolute path shebang and falls back to the global default Python environment.
- (Optional) Rename the executable to
python_test.exe, update the shebang, and observe a crash during tag extraction.
Expected behavior
_find_shebang_command should only match bare alias names. Explicit paths containing directory separators should safely raise LookupError so _parse_shebang can natively delegate them to _find_on_path().
Additional context
As requested by @zooba in #345 this issue tracks the routing behavior observed with absolute shebangs prior to merging the fix. This alias-matching logic also contributes to the behaviors reported in #91 and #307.
Install source and version
Version:
26.2Describe the bug
In
scriptutils.py,_find_shebang_commandusespathlib.PurePath.match(), which performs right-aligned suffix matching. This inadvertently intercepts explicit absolute paths and feeds them into bare-name routing rules.When installing certain packages via
uv(specifically older packages usingsetup.pythat drop.pyscripts with absolute shebangs rather than.exeentry-point shims), or when a script utilizes its own localpython.exe(such as in avenv), the absolute shebang is falsely intercepted. This prevents the path from reaching_find_on_path(). Instead:python.exetrigger theis_defaultcheck, hijacking execution to the global environment.python*.exe(e.g.,python_test.exe) bypass the default check and fall through to the wildcard fallback, which slices the string ([6:-4]) and crashes while looking for a non-existent tag.To Reproduce
Steps to reproduce the behavior:
setup.pypackage installed viauvthat relies on a shebang, or a standardvenv).#!C:\path\to\env\Scripts\python.exe).pymanager(py.exe example_script.py) or directly ifpyfiles are already associated with it.python_test.exe, update the shebang, and observe a crash during tag extraction.Expected behavior
_find_shebang_commandshould only match bare alias names. Explicit paths containing directory separators should safely raiseLookupErrorso_parse_shebangcan natively delegate them to_find_on_path().Additional context
As requested by @zooba in #345 this issue tracks the routing behavior observed with absolute shebangs prior to merging the fix. This alias-matching logic also contributes to the behaviors reported in #91 and #307.