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

poetry incorrectly installs an optional script #8841

Closed
4 tasks done
kojiromike opened this issue Jan 3, 2024 · 2 comments
Closed
4 tasks done

poetry incorrectly installs an optional script #8841

kojiromike opened this issue Jan 3, 2024 · 2 comments
Labels
kind/bug Something isn't working as expected

Comments

@kojiromike
Copy link

Issue

Summary

The documentation says

To specify a script that depends on an extra, you may provide an entry as an inline table:

I think this means that I should be able to specify a script that only works when the dependencies specified in the extra are installed. However, poetry does not behave as I expect.

What actually happens

Given the project at https://github.com/kojiromike/example-poetry-optional-script-bug…

Note that there is a script hello-decouple specified according to the documentation as a script that depends on an extra. When I install the project with that extra:

$ poetry install -E cfg
Installing dependencies from lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing python-decouple (3.8)

Installing the current project: bug-example (0.1.0)

...and attempt to run that script:

$ poetry run hello-decouple

'callable'

This is not what I expect.

What I expect

I expect the output of the script at example/hi_decouple.py, which looks like:

$ ./example/hi_decouple.py
Hello, decouple

This does work as expected with the non-optional script hello included in the example:

$ poetry run hello
Hello world

Other surprising things

There are a few other surprising things happening:

Invalid Python

The installed optional script is not valid python:

$ cat $(poetry run type -P hello-decouple)
#!/Users/michael/Library/Caches/pypoetry/virtualenvs/bug-example-XQQKIwQM-py3.12/bin/python
import sys
from example.hi_decouple import main[cfg]

if __name__ == '__main__':
    sys.exit(main[cfg]())

Indeed, I get a syntax error if I run it directly:

$ /Users/michael/Library/Caches/pypoetry/virtualenvs/bug-example-XQQKIwQM-py3.12/bin/hello-decouple
  File "/Users/michael/Library/Caches/pypoetry/virtualenvs/bug-example-XQQKIwQM-py3.12/bin/hello-decouple", line 3
    from example.hi_decouple import main[cfg]
                                        ^
SyntaxError: invalid syntax

Whereas when poetry generates a non-optional script, it does so correctly:

$ cat $(poetry run type -P hello)
#!/Users/michael/Library/Caches/pypoetry/virtualenvs/bug-example-XQQKIwQM-py3.12/bin/python
import sys
from example.hi import main

if __name__ == '__main__':
    sys.exit(main())

poetry run does not run the installed script

poetry run hello-decouple outputs \n'callable' instead of the above syntax error. It must be doing something besides running the script.

the script is always "installed"

(This is perhaps the least surprising thing, but still worth mentioning.) Even when the optional dependencies are not installed, the script is installed.

$ poetry install
Installing dependencies from lock file

Package operations: 0 installs, 0 updates, 1 removal

  • Removing python-decouple (3.8)

Installing the current project: bug-example (0.1.0)
$ poetry run hello-decouple

'callable'

I would expect the script not to be installed. Barring that, I'd expect an import error.

@kojiromike kojiromike added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jan 3, 2024
@dimbleby
Copy link
Contributor

dimbleby commented Jan 3, 2024

duplicate #6892 please close

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 Feb 29, 2024
@abn abn removed the status/triage This issue needs to be triaged label Mar 2, 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
Projects
None yet
Development

No branches or pull requests

3 participants