'How to install scripts from pyproject.toml?
I have this snippet in my pyproject.toml
[tool.poetry.scripts]
devel = "uvicorn api:app --reload"
prod = "uvicorn api:app"
I install it as mentioned in poetry documentation
(wowtcg-tracker-api-dIKBwUYp-py3.10) bastakka@Karel-NTB:/m/c/U/b/D/P/I/w/wowtcg-tracker-api (main↓2|✚9…9)
» poetry install
Installing dependencies from lock file
Package operations: 38 installs, 0 updates, 0 removals
• Installing idna (3.3)
...
• Installing yapf (0.32.0)
(wowtcg-tracker-api-dIKBwUYp-py3.10) bastakka@Karel-NTB:/m/c/U/b/D/P/I/w/wowtcg-tracker-api (main↓2|✚9…9)
»
But there were no scripts generated from this command.
Poetry can't run them
…-tracker-api-dIKBwUYp-py3.10) bastakka@Karel-NTB:/m/c/U/b/D/P/I/w/wowtcg-tracker-api (main↓2|✚9…9)
» poetry run prod
ModuleOrPackageNotFound
No file/folder found for package wowtcg-tracker-api
at ~/.poetry/lib/poetry/_vendor/py3.10/poetry/core/masonry/utils/module.py:63 in __init__
59│ "from": str(src.relative_to(self._path)),
60│ }
61│ ]
62│ else:
→ 63│ raise ModuleOrPackageNotFound(
64│ "No file/folder found for package {}".format(name)
65│ )
66│
67│ for package in packages:
…-tracker-api-dIKBwUYp-py3.10) bastakka@Karel-NTB:/m/c/U/b/D/P/I/w/wowtcg-tracker-api (main↓2|✚9…9)
»
And there are none in the venv bin either
…-tracker-api-dIKBwUYp-py3.10) bastakka@Karel-NTB:/m/c/U/b/D/P/I/w/wowtcg-tracker-api (main↓2|✚9…9)
» ls /home/bastakka/.cache/pypoetry/virtualenvs/wowtcg-tracker-api-dIKBwUYp-py3.10/bin
activate dotenv* pip* pyreverse* watchgod*
activate.csh epylint* pip3* python@ wheel*
activate.fish get_objgraph* pip-3.10* python3@ wheel3*
activate.nu httpx* pip3.10* python3.10@ wheel-3.10*
activate.ps1 isort* prisma* symilar* wheel3.10*
activate_this.py isort-identify-imports* prisma-client-py* undill* yapf*
deactivate.nu normalizer* pylint* uvicorn* yapf-diff*
…-tracker-api-dIKBwUYp-py3.10) bastakka@Karel-NTB:/m/c/U/b/D/P/I/w/wowtcg-tracker-api (main↓2|✚9…9)
»
Am I missing something needed or doing something wrong?
Solution 1:[1]
tool.poetry.scripts is used for "scripts or executables that will be installed when installing the package". You'd have to drop the poetry run prefix to run them.
For development scripts I'd recommend something like taskipy. e.g.
# pyproject.toml
[tool.taskipy.tasks]
devel = "uvicorn api:app --reload"
prod = "uvicorn api:app"
Then you can run something like poetry run task devel
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | con-- |
