space character problem in shebang path when poetry creates a CLI executable
- Poetry version: Poetry (version 1.7.1)
- Python version:
Poetry
Version: 1.7.1
Python: 3.11.6
Virtualenv
Python: 3.11.4
Implementation: CPython
Path: /home/lelzin/Área de trabalho/Doky/.venv
Executable: /home/lelzin/Área de trabalho/Doky/.venv/bin/python
Valid: True
System
Platform: linux
OS: posix
Python: 3.11.4
Path: /home/lelzin/.pyenv/versions/3.11.4
Executable: /home/lelzin/.pyenv/versions/3.11.4/bin/python3.11
-
OS version and name: Linux Archcraft - rolling release
-
pyproject.toml: any pyproject containing a defined script entrypoint on
tool.poetry.scriptssession. -
[x] I am on the latest stable Poetry version, installed using a recommended method.
-
[x] I have searched the issues of this repo and believe that this is not a duplicate.
-
[x] I have consulted the FAQ and blog for any relevant entries or release notes.
-
[x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption) and have included the output below.
Issue
This issue is simillar to recent merged issue #7244, the same that I'm happily waiting for to arrive in the next release.
I have my project that works as CLI:
[tool.poetry.scripts]
doky = "doky.__main__:main"
I run poetry install for poetry creates my CLI executable file, nice.
Then, I run my CLI directly doky auth, but infortunely:
zsh: /home/lelzin/Área de trabalho/Doky/.venv/bin/doky: bad interpreter: /home/lelzin/Área: no such file or directory
And the saga of space characters strikes again 😁
My investigation:
$ which doky
/home/lelzin/Área de trabalho/Doky/.venv/bin/doky
$ cat "$(which doky)"
#!/home/lelzin/Área de trabalho/Doky/.venv/bin/python
import sys
from doky.__main__ import main
if __name__ == '__main__':
sys.exit(main())
And with this I concluded that the problem was the space in the shebang path, and this is my suggestion to solve this:
#!/{os.environ['SHELL'])}
PYTHON = "/home/lelzin/Área de trabalho/Doky/.venv/bin/python"
CODE = "
import sys
from doky.__main__ import main
if __name__ == '__main__':
sys.exit(main())
"
"$PYTHON" -c "$CODE" $@
Please, I ask you to work on this, I LOVE POETRY, but I don't want to always have to solve it manually :(
http://lists.gnu.org/archive/html/bug-bash/2008-05/msg00052.html says that this cannot be solved, but if you know better then please submit a merge request
@dimbleby in fact, there is no way to escape spaces in the path of a shebang, but as suggested above it is possible to call the terminal shell instead of the python interpreter, and this makes it possible to have the same result.
If there is someone who knows the poetry API, I would like that person to be able to do the PR in my place, but if no one is available I will be dedicating my free time to reading the code and trying to implement my suggested solution.
Thanks for answering!! 😅
I will say that I do not find your suggestion very attractive. What do other installers (pip, pipx etc) do with paths with spaces?
perhaps you are better off simply not exposing yourself to this: use paths without spaces.
I tested it with pip, and it did practically the same thing as I suggested, see below:
$ cat "/home/lelzin/Área de trabalho/xpto/.venv/bin/doky"
#!/bin/sh
'''exec' "/home/lelzin/Área de trabalho/xpto/.venv/bin/python" "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re
import sys
from doky.__main__ import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
I thought Poetry was taken with seriousness and commitment, it's not the first time I've seen contributors to this project making light of basic problems like this.
Asking me to simply avoid paths with spaces doesn't solve the problem, it just hides it under the rug.