If you have not installed poetry already on your local machine:
python3 -m pip install pipx
python3 -m pipx ensurepath
pipx install poetry
In order to publish to PyPi, your CI environment will need access to creds - either a username/password combo or an API key.
Open your CI environment config and add the following as secrets:
PYPI_USER
- the identity to use when auth-ing with PyPiPYPI_SECRET
- the secret key or password used for PyPi
- If you have not already done so, open a new branch on your repo (for example:
feature/poetry
). - From the root of the repo, run
poetry init
and answer the one-time prompts. If you have asetup.py
file, it may be helpful to open that file before starting the process. (You will later be able to change these answers inpyproject.toml
.)- When asked for a version number, do not accept the default (
0.1.0
), but instead consult yourVERSION
file (if applicable) and provide a version that is (at least) a minor version up from that starting version. - When asked for python compatibility, be sure to use
^3.6
(or earlier) if you want to keep support for early python versions. (You might find prior version support definitions insetup.py
.) - When asked for the dependencies, consult your
requirements.txt
file (if applicable). Also consult yoursetup.py
file for any additional requirements not listed inrequirements.txt
. - When asked for development dependencies, consult your
setup.py
file for any reference totests_require
.
- When asked for a version number, do not accept the default (
- Check your
setup.py
file for any references toentry_points
orconsole_scripts
, which are the executable CLI commands of the package.- If applicable, add the followiing section to your
pyproject.toml
file:[tool.poetry.scripts] runme = "mylibrary.cli_file:main_func"
- If applicable, add the followiing section to your
- Check your
setup.py
file for any references toextras_require
- which represent optional features which require additional upstream dependencies. If applicable:- If you have not already done so, add the optional packages in the same way as you normally would, either by declaring them during
poetry init
or withpoetry add package1 package2 etc
. - After all optional packages have been added, update the following section to your
pyproject.toml
file, using the "optional = true" syntax and referencing the optional packages in theextras
section:[tool.poetry.dependencies] # These packages are mandatory and form the core of this package’s distribution. mandatory = "^1.0" # A list of all of the optional dependencies, some of which are included in the # below `extras`. They can be opted into by apps. psycopg2 = { version = "^2.7", optional = true } mysqlclient = { version = "^1.3", optional = true } [tool.poetry.extras] mysql = ["mysqlclient"] pgsql = ["psycopg2"]
- Important: extras must be defined in in
pyproject.toml
using all lowercase or they will not work properly. However, during installation these are equivalent:pip install mypackage[mysql]
is the same aspip install mypackage[MySQL]
.
- If you have not already done so, add the optional packages in the same way as you normally would, either by declaring them during
The following files are replaced by pyproject.toml
and should be deleted from your repo:
MANIFEST.in
requirements.txt
setup.cfg
setup.py
VERSION