For python library development, it’s highly recommended to use [poetry](https://python-poetry.org/) as it provides a one-stop solution for dependency-management, build and distribution

I am obsessed with it recently and I really hope it can become the default python packaging and dependency management system.

For basic poetry setup please reference Poetry Documentations.

curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

Today I’d like to talk about how I iron out some hiccups with poetry.

Compatible with other traditional projects.

Editable mode

One thing that a lot of folks are asking is how to keep the editable mode in pip:

pip install -e /path/to/your/project

This way your code change will be reflected immediately without the need for re-packaging.

This issue shows that there is no native support to do so.

According to the response, I use the statement below to generate the setup:

export ARTIFACT=$(poetry version | sed "s/ /-/g") && tar xvOf "dist/$ARTIFACT.tar.gz" "$ARTIFACT/setup.py" > setup.py

After that, you can do the same pip install -e /path/to/your/project anywhere else. But do remember that if you have made any changes to your pyproject.toml/poetry.lock, you need to regenerate the setup.py again. This includes dependencies, entry_points, etc.

Note that you don’t need this if you are developing in the poetry project itself. poetry install has already but the current project in the editable mode for you.

Requirements

Again, sometimes people will need to use the requirements.txt instead for no matter what reason.

poetry export --without-hashes -f requirements.txt -o requirements.txt

With hashes, it’s deterministic, so you won’t have problems if your library did something nasty, it’s almost like your poetry.lock. But it’s less readable.

#python #practice #compatible

Best Practice for using Poetry
21.40 GEEK