[issue41965] distutils.spawn.find_executable() fails to find .py files on Windows
Alexander Todorov
report at bugs.python.org
Wed Oct 7 04:39:18 EDT 2020
New submission from Alexander Todorov <atodorov at otb.bg>:
As part of installing python-bugzilla via pip it searches for `rst2man` or `rst2man.py`, see:
https://github.com/python-bugzilla/python-bugzilla/blob/master/setup.py#L81
on Windows venvs there is venv\Scripts\rst2man.py (no .exe or without suffix) and when you call find_executable('rst2man.py') if doesn't find it.
The trouble is in this code snippet:
```
_, ext = os.path.splitext(executable)
if (sys.platform == 'win32') and (ext != '.exe'):
executable = executable + '.exe'
```
`ext` here is `.py` and the if condition executes its body so the executable to search for becomes `rst2man.py.exe` which doesn't exist.
The extension check has been like that for more than 20 years:
https://github.com/python/cpython/commit/69628b0ad10f89a65902f5b911d1040ed9ae1ca2
but IMO it should be
```
if (sys.platform == 'win32') and (ext == ''):
executable = executable + '.exe'
```
i.e. add `.exe` only if the file we're looking for doesn't already have an extension.
Let me know what you think? I can submit a PR for this.
Related issues:
- https://bugs.python.org/issue2200
- https://bugs.python.org/issue39260
----------
components: Distutils
messages: 378150
nosy: Alexander.Todorov, dstufft, eric.araujo
priority: normal
severity: normal
status: open
title: distutils.spawn.find_executable() fails to find .py files on Windows
type: behavior
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41965>
_______________________________________
More information about the Python-bugs-list
mailing list