You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
Poetry version:
1.7.1
Python version:
3.12.1
OS version and name:
macOS Sonoma 14.2.1
pyproject.toml: https://github.com/kojiromike/example-poetry-optional-script-bug/blob/main/pyproject.toml
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
Summary
The documentation says
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:...and attempt to run that script:
This is not what I expect.
What I expect
I expect the output of the script at
example/hi_decouple.py
, which looks like:This does work as expected with the non-optional script
hello
included in the example:Other surprising things
There are a few other surprising things happening:
Invalid Python
The installed optional script is not valid python:
Indeed, I get a syntax error if I run it directly:
Whereas when poetry generates a non-optional script, it does so correctly:
poetry run
does not run the installed scriptpoetry 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.
I would expect the script not to be installed. Barring that, I'd expect an import error.
The text was updated successfully, but these errors were encountered: