The Python ecosystem has spawned a whole bunch of ways to manage dependencies in projects.
Right now, you can choose between setup.py, requirements.txt, setup.cfg, MANIFEST.in and Pipfile.
But all these methods did not suit the French python player Sébastien Eustace, and he wrote his piece for the management of the pitonet bags - Poetry . Why did he do it? To replace all these setup.py, requirements.txt, setup.cfg, MANIFEST.in and Pipfile with something simple and straightforward. Plus add something useful from above.
Poetry allows you to steer at once a bunch of things - the version of the language in your project, dependencies, plug-in paths, testing / development scripts, building and publishing builds. All the necessary paths, dependencies and scripts are described in a special pyproject.toml file.
Poetry works best with paenv , the management system for multiple versions of Python and virtual environments.
Roll up our sleeves and see how poetry works in business. First we install pyenv , following the official instructions at the docks.
# pyenv, $ pyenv update # Python $ pyenv install -l # , $ pyenv install 3.7.3 # zlib, # CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 3.7.3 # $ pyenv local 3.7.3 # poetry $ pip3 install poetry # $ poetry init # Poetry pyproject.toml, # . , . $ poetry add flask celery # Poetry pyproject.toml # , PIP (, ), $ poetry add my-package --path ../my-package/ # $ poetry show # Python $ poetry run python # Python , flask celery, .
The environment is installed and configured, dependencies are controlled by one finger, you can cut the code!
You, most likely, will appear in the project of the command to start the server, workers, deployment scripts and testing. You can put them in pyproject.toml and also steer them with one finger.
Add to file
my-script = "my_module:main"
and now you can run the script with the command
poetry run my-script
Having spent ten minutes to master this thing, you will save time and nerves on managing versions of a language and packages, tracking dependencies and setting up paths. This will especially help those who have ever tried to publish their work in pip :)
Poetry is very friendly with other virtual environment controllers, so integrating a new approach into old projects will be very easy.
Source: https://habr.com/ru/post/455335/
All Articles