Code snippet to migrate setup.py to pyproject.toml
This code will run either on a non-archived gitlab project or a gitlab group (processing all its non-archived projects).
Workflow:
- Pull needed files
setup.py
.gitlab-ci.yml
*requirements.txt
tox.ini
- Create
pyproject.toml
(use existing tools in python or if no can do, CLI through python subprocess) based on the content insetup.py
- we need to keep
setuptools
's backend for now - all dependencies should be listed in the file
- package should be mentioned with the default setuptools configuration
- we need to keep
[tool.setuptools.packages.find]
where = ["."] # list of folders that contain the packages (["."] by default)
include = ["<package-name>"] # package names should match these glob patterns (["*"] by default)
exclude = [] # exclude packages matching these glob patterns (empty by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
- If the repository publishes a package on pypi (i.e.
pypi
is present in.gitlab-ci.yml
), we need to update the publication section-
PYPI_...
variables should be renamed toTWINE_USERNAME
etc, -
before_script:
one single linepip install twine build
-
script:
- python -m build
- twine upload --repository-url ${TWINE_REPOSITORY_URL} dist/* # if TWINE_REPO is defined, else no need for `--repository-url` arg
In the end, the MR should be about:
- removing
setup.py
and every*requirements.txt
- adding
pyproject.toml
- updating
.gitlab-ci.yml
- updating
tox.ini
to remove mentions aboutrequirements.txt