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

tool.poetry.scripts fails because of a space in path to env #3643

Open
3 tasks done
mklengel opened this issue Feb 4, 2021 · 3 comments · May be fixed by #9802
Open
3 tasks done

tool.poetry.scripts fails because of a space in path to env #3643

mklengel opened this issue Feb 4, 2021 · 3 comments · May be fixed by #9802
Assignees
Labels
area/scripts Related tool.poetry.scripts kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@mklengel
Copy link

mklengel commented Feb 4, 2021

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

I followed two articles of Jonathan Bowman:
https://dev.to/bowmanjd/getting-started-with-python-poetry-3ica
https://dev.to/bowmanjd/build-command-line-tools-with-python-poetry-4mnc

In my case the project folder contains a space, which most likely is the reason for the problem.
The entry in pyproject.toml is:

[tool.poetry.scripts]
greet = "greet.location:cli"

The result of calling "greet" is:

(.venv) ➜  pygreet greet                   
zsh: /Volumes/Macintosh SR0/Users/mklengel/Development/pygreet/.venv/bin/greet: bad interpreter: /Volumes/Macintosh: no such file or directory

Having a look in the shebang line of greet shows of course the space in the path:

(.venv) ➜  pygreet head  -1  .venv/bin/greet
#!/Volumes/Macintosh SR0/Users/mklengel/Development/pygreet/.venv/bin/python

The shebang line is created by poetry.

A possible workaround with a symlink to eliminate the space fails:

(.venv) ➜  ~ pwd
/Users/mklengel
(.venv) ➜  ~ ls -l Development 
lrwxr-xr-x  1 mklengel  staff  49 Jan 15 22:03 Development -> /Volumes/Macintosh SR0/Users/mklengel/Development
(.venv) ➜  ~ cd Development/pygreet 
(.venv) ➜  pygreet pwd
/Users/mklengel/Development/pygreet
(.venv) ➜  pygreet poetry shell
Virtual environment already activated: /Volumes/Macintosh SR0/Users/mklengel/Development/pygreet/.venv

poetry "sees" the path but ignores the symbolic link.

@mklengel mklengel added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 4, 2021
@bowmanjd
Copy link

bowmanjd commented Feb 4, 2021

Possibly related clues (in other words, this may be much bigger than Poetry, but hopefully workarounds exist):

@mklengel mklengel changed the title poetry script fails because of a space in path to env tool.poetry.scripts fails because of a space in path to env Feb 4, 2021
@mklengel
Copy link
Author

mklengel commented Feb 5, 2021

Using the default virtualenv folder instead of the project's root directory works.
So may be this is the bug in poetry: the shebang line is not the symbolic one if the virtualenv folder is in the project's root directory.

➜  pygreet ls -ld $HOME/Development/pygreet
drwxr-xr-x  8 mklengel  staff  256  5 Feb 13:38 /Users/mklengel/Development/pygreet

Create the virtualenv inside the project's root directory leads to:

➜  pygreet head -1 .venv/bin/greet
#!/Volumes/Macintosh SR0/Users/mklengel/Development/pygreet/.venv/bin/python

Using the default virtualenv folder looks much better:

➜  pygreet poetry config virtualenvs.in-project false

➜  pygreet poetry config --list
cache-dir = "/Users/mklengel/Library/Caches/pypoetry"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /Users/mklengel/Library/Caches/pypoetry/virtualenvs

➜  pygreet poetry install
Creating virtualenv greet-hlYPq_3g-py3.9 in /Users/mklengel/Library/Caches/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 24 installs, 0 updates, 0 removals

  • Installing pyparsing (2.4.7)
  • Installing six (1.15.0)
  • Installing appdirs (1.4.4)
  • Installing attrs (20.3.0)
  • Installing click (7.1.2)
  • Installing mccabe (0.6.1)
  • Installing more-itertools (8.6.0)
  • Installing mypy-extensions (0.4.3)
  • Installing packaging (20.9)
  • Installing pathspec (0.8.1)
  • Installing pluggy (0.13.1)
  • Installing py (1.10.0)
  • Installing pycodestyle (2.6.0)
  • Installing pyflakes (2.2.0)
  • Installing python-dateutil (2.8.1)
  • Installing regex (2020.11.13)
  • Installing toml (0.10.2)
  • Installing typed-ast (1.4.2)
  • Installing typing-extensions (3.7.4.3)
  • Installing wcwidth (0.2.5)
  • Installing arrow (0.17.0)
  • Installing black (20.8b1)
  • Installing flake8 (3.8.4)
  • Installing pytest (5.4.3)

Installing the current project: greet (0.1.0)
➜  pygreet head -1 ~/Library/Caches/pypoetry/virtualenvs/greet-hlYPq_3g-py3.9/bin/greet
#!/Users/mklengel/Library/Caches/pypoetry/virtualenvs/greet-hlYPq_3g-py3.9/bin/python

➜  pygreet poetry shell
Spawning shell within /Users/mklengel/Library/Caches/pypoetry/virtualenvs/greet-hlYPq_3g-py3.9

➜  pygreet . /Users/mklengel/Library/Caches/pypoetry/virtualenvs/greet-hlYPq_3g-py3.9/bin/activate

(greet-hlYPq_3g-py3.9) ➜  pygreet greet Africa/Addis_Ababa
Hello, Addis Ababa! The time is 4:50 pm.

@sco1
Copy link

sco1 commented Sep 24, 2021

I've also encountered this issue on Windows using a virtualenv local to a project directory with space(s) in the pathname

Files to reproduce here, along with the resulting Script entries: https://gist.github.com/sco1/7429d50142960e375e81c0d9d8103fc9

I've also included a sample setup.py/cfg that successfully installs the entry point (with pyproject.toml deleted), along with the resulting hello-script.py Scripts output

$ hello
bash: /c/dir with space/.venv/Scripts/hello: C:\dir: bad interpreter: No such file or directory

@Secrus Secrus self-assigned this Sep 25, 2024
@Secrus Secrus linked a pull request Oct 27, 2024 that will close this issue
1 task
@finswimmer finswimmer added the area/scripts Related tool.poetry.scripts label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scripts Related tool.poetry.scripts kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants