poetry should report unrecognized package names
-
[x] I am on the latest Poetry version.
-
[X] I have searched the issues of this repo and believe that this is not a duplicate.
-
[x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption). -
OS version and name: macOS 11.2.3
-
Poetry version: Poetry version 1.1.6
Issue
I noticed that poetry wasn't installing the scripts listed in tool.poetry.scripts — no errors, the venv was created successfully, etc. but … no scripts. This turned out to be due to an undocumented interaction of how the package name and scripts are interpreted: I had renamed my project slightly and tool.poetry had a name which was had an extra component in it — roughly name = "my-new-project" while the Python code was in a directory named my_project.
I opened this as a bug because it feels like Poetry should toss a warning that an expected directory does not exist. It could also be resolved in documentation if https://python-poetry.org/docs/pyproject/#name indicated that the name has to be a, or transformable into, importable Python module in the current directory or https://python-poetry.org/docs/pyproject/#scripts had some note that the block is completely ignored if name doesn't match.
See #283
Confirming that I've run into this issue as well.
Note also that this makes creating a Dockerfile which wants to use the package's script command executable as an entrypoint break. For example, it is a best practice to only install dependencies toward the top of your Dockerfile with something like:
# Install python dependencies in /.venv
COPY pyproject.toml .
COPY poetry.lock .
RUN POETRY_VIRTUALENVS_IN_PROJECT=true poetry install --no-dev
and then toward the bottom, COPY the source code.
However, because the modules pointed to in [tool.poetry.scripts] haven't been copied over, poetry will not actually create the executable in the venv's bin directory. This took me a bit to figure out. A warning message would be great, but I also don't know what the best solution is for using [tool.poetry.scripts] and trying to adhere to Dockerfile best practices.
I've also run into this issue. There should at least be a warning if for some reason the script installation is skipped!
To the Poetry Devs, I don't understand why the following scripts are not installed if the package is not present. Is there any particular reason for this? It does create a lot of problems if we want to use poetry in docker multi-stage builds by copying only the virtual environment to the final build image. Please Explain!
@latacora-tomekr @Edumate696 you can use the --no-root option to install dependencies without the source code being copied yet. Once that is done, you can COPY the code and run a full poetry install, which will install scripts too. See
- https://github.com/orgs/python-poetry/discussions/1879
- https://medium.com/@albertazzir/blazing-fast-python-docker-builds-with-poetry-a78a66f5aed0