How poetry run
should handle non-installed scripts?
#7599
Replies: 4 comments 23 replies
-
I was checking the feasibility to accomplish "Install the script in the virtualenv when poetry detects a script is not installed". It is much trickier than I thought. Because the only guarantee we have in the To install the script to the file system, first I would need to know which kind of env, this is completely out of scope of |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, I'm on Poetry (version 1.6.1) and in poetry lock \
-vvv \
--no-ansi \
--no-interaction
poetry install -vvv \
--extras mystuff \
--no-ansi \
--no-interaction In [tool.poetry.scripts]
myscript = 'myscript.cli:command' The rest of the ENTRYPOINT [ "poetry", "run", "myscript" ]
CMD ["--help"] And I'm getting the warning when running the script:
It's not clear what's the problem so far, given that I'm doing |
Beta Was this translation helpful? Give feedback.
-
i think the support should stay. it's ok for it to log a warning, but it's terribly useful to run in "dev mode" without requiring an installation every time that you might forget you did, and now wind up testing the wrong thing. honestly, i loathe installation of dev packages while working. it just leads to errors. for ci/cd it makes sense (its important), but for coding, it's bad. |
Beta Was this translation helpful? Give feedback.
-
oh, ok. i did add a script recently. not sure why that matters (it's easy to override arg0), but that's not too bad. |
Beta Was this translation helpful? Give feedback.
-
TL;DR
Roughly there are 3 options for
poetry run
handling non-installed scripts, in the order of my preference:I think option (1) is the best because would only enhance Poetry without introducing any incompatibility. To be honest, I think no one is relying on the broken
sys.argv[0]
poetry emits when script is not installed.Background
The command
poetry run
is able to execute any command in the virtualenv, but has a special behavior with entry points (the ones defined at[tool.poetry.scripts]
).Currently
poetry run
can execute entry points even though they are uninstalled, i.e. they don't exist physically in the file system. But this, inadvertently, is confusing the users due to how poetry historically fillssys.argv[0]
, which led to several issues created in the past (#480, #965, #2435, #7528).For instance, using latest poetry version, with the following entry point,
poetry run dev
may result in a differentsys.argv[0]
depending if the script is installed or no.sys.argv = ['dev']
if script is not installed.sys.argv = ['/home/wagner/.cache/pypoetry/virtualenvs/my_package-Iqs9p7vq-py3.7/bin/dev']
if script is installed.Important quotes from issue #7528 which shows how confusing this is for users
Originally posted by @delucca in #7528 (comment)
Originally posted by @delucca in #7528 (comment)
Originally posted by @wagnerluis1982 in #7528 (comment)
Originally posted by @radoering in #7528 (comment)
Beta Was this translation helpful? Give feedback.
All reactions