Things under legendu
uv (implemented in Rust) is the new cool kid now and is prefer to poetry.
Tips and Traps¶
Python Poetry is current the best project management tool for Python!
Python Poetry supports Python package dependencies on GitHub. For example, if a Python package depends on https://
github .com /dclong /dsutil, then you can add it using the following. :::bash poetry add git+https://github.com/dclong/dsutil.gitOr
:::bash poetry add git+ssh://git@github.com/dclong/dsutil.gitFor more details, please refer to poetry add and git dependencies .
poetry installremoves non needed libraries. A tricky situation is that if you have dependency A which depends on dependency B, and you have specified both A and B inpyproject.toml. Removing dependency B frompyrpoject.tomland then runningpoetry installwon’t remove the library B from the virtual environment as B is still needed by A.Poetry has lots of issues in Windows currently. It is suggested that you avoid using poetry in Windows.
If you encounter the following error message when running
poetry install,[Errno 2] No such file or directory: ‘/path/to/readme.md’
it means that you have specified
tool.poetry.readmeto bereadme.mdinpyproject.tomlbutreadme.mddoes not exists under root directory of the project.
Install Python Poetry¶
Follow the official tutorial.
Using xinstall.
:::bash # install xinstall if it hasn't been installed sudo pip3 install -U git+https://github.com/dclong/xinstall@master # install poetry using xinstall xinstall pt -ic
Updating Python Poetry¶
Updating poetry to the latest stable version is as simple as calling the self:update command.
:::bash
poetry self:updateIf you want to install prerelease versions, you can use the --preview option.
:::bash
poetry self:update --previewUsage¶
Create/Initialize a New Project¶
Create a new Python project using poetry.
:::bash poetry new projInitialize an existing Python project using poetry.
:::bash poetry init
Install Dependencies¶
Installl all dependencies.
:::bash poetry installInstalll all but dev dependencies.
:::bash poetry install --no-dev
Export Dependencies¶
Export the lock file to
requirements.txtso that the dependency can be installed usingpip.:::bash poetry export -f requirements.txt > requirements.txt
Run Commands in the Virtual Environment¶
poetry run cmd is a quick to run cmd using the virtual environment managed by poetry. Another way is to manually set PATHbefore you invokecmd`.
For example,
:::bash
PATH=.venv/bin:$PATH cmdRun test suits using pytest.
:::bash poetry run pytestOr if you want to make it specific to collect test suits from the
testdirectory under the root directory of the project.:::bash poetry run pytest testRun pytype.
:::bash poetry run pytype .
User Tasks¶
Configuration¶
https://
https://
Pleaser refer to pyproject.toml for examples of configuration for Python Poetry.
Restrict Operating Systems in Python Poetry¶
How can I specify dependencies on operating system in Python Poetry?
[tool.poetry]
# ...
classifiers = [
"Operating System :: POSIX :: Linux",
]https://
References¶
https://
https://