Linux: shutil.which fails to find executable in current working directory/cwd when PATH unset (subprocess works)
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
On Linux, executables from the cwd are used when PATH is unset:
$ PATH= python -V
Python 3.13.7
subprocess.run also works in this case:
$ PATH= python -q
>>> from subprocess import run
... run(['python', '-V'])
...
Python 3.13.7
CompletedProcess(args=['python', '-V'], returncode=0)
>>>
But shutil.which returns None:
>>> from shutil import which
>>> which('python')
>>>
This is because when PATH is empty(""), the executable ("python") is passed to the kernel's execve directly, without resolving. execve then resolves the file relative to the cwd, I believe it's the case in both Linux and FreeBSD.
POSIX 2024 says this about the PATH environment variable:
If PATH is unset or is set to null, or if a path prefix in PATH contains a character ('%'), the path search is implementation-defined.
EDIT: PATH is empty, not unset
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo ponto de entrada shutil.which e reproduza o caso do Linux com PATH=, comparando-o com subprocess.run(['python', '-V']). Determine o comportamento pretendido para um PATH vazio, depois verifique se shutil.which o segue e cubra o caso com um teste de regressão.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- operating-systems
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 42/100