Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

space character problem in shebang path when poetry creates a CLI executable #8967

Closed
4 tasks done
d3cryptofc opened this issue Feb 13, 2024 · 9 comments
Closed
4 tasks done
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@d3cryptofc
Copy link

d3cryptofc commented Feb 13, 2024

  • 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.scripts session.

  • I am on the latest stable Poetry version, installed using a recommended method.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • I have consulted the FAQ and blog for any relevant entries or release notes.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) 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 :(

@d3cryptofc d3cryptofc added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 13, 2024
@d3cryptofc d3cryptofc changed the title pyproject CLI scripts containing a shebang problem (space on path) after running poetry install and call my CLI without using poetry run space problem in shebang path when poetry creates a CLI executable Feb 13, 2024
@d3cryptofc d3cryptofc changed the title space problem in shebang path when poetry creates a CLI executable space character problem in shebang path when poetry creates a CLI executable Feb 13, 2024
@dimbleby
Copy link
Contributor

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

@d3cryptofc
Copy link
Author

@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!! 😅

@dimbleby
Copy link
Contributor

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.

@d3cryptofc
Copy link
Author

d3cryptofc commented Feb 13, 2024

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.

@ibeatty
Copy link

ibeatty commented Sep 11, 2024

This bug is biting me too. I'm counting on using poetry to distribute my package to other developers, recreating the appropriate virtual environment for each on their own system, so I can't rely on (a) manually editing the shell script that poetry generates, or (b) never having directories with space characters in the project's absolute file path.

Isn't portability between developers one of the main virtues of poetry?

@d3cryptofc
Copy link
Author

d3cryptofc commented Sep 14, 2024

@ibeatty It's true, but from the conversation above it seems like they don't care about this specific case.

But I'll keep the Issue open in case they change their mind..

@dimbleby
Copy link
Contributor

duplicate #3643, this one can be closed

@Secrus
Copy link
Member

Secrus commented Sep 25, 2024

Duplicate #3643

@Secrus Secrus closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants