From e24c0aa1340bd401f309ad9eb3cc97db429032b1 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Fri, 20 Oct 2023 13:23:19 +0200 Subject: [PATCH] switch to python -m build --- README.md | 2 -- .../.github/workflows/build.yml | 2 +- {{cookiecutter.directory_name}}/README.dev.md | 32 ++++++------------- .../pyproject.toml | 3 +- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2e3095bc..d70b7d73 100644 --- a/README.md +++ b/README.md @@ -135,8 +135,6 @@ my-python-project/ ├── pyproject.toml ├── README.dev.md ├── README.md -├── setup.cfg -├── setup.py ├── sonar-project.properties └── tests ├── __init__.py diff --git a/{{cookiecutter.directory_name}}/.github/workflows/build.yml b/{{cookiecutter.directory_name}}/.github/workflows/build.yml index 80ec495f..b2e166db 100644 --- a/{{cookiecutter.directory_name}}/.github/workflows/build.yml +++ b/{{cookiecutter.directory_name}}/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: - name: Run unit tests run: python -m pytest -v - name: Verify that we can build the package - run: python setup.py sdist bdist_wheel + run: python -m build lint: name: Linting build diff --git a/{{cookiecutter.directory_name}}/README.dev.md b/{{cookiecutter.directory_name}}/README.dev.md index 7217de9b..921634c0 100644 --- a/{{cookiecutter.directory_name}}/README.dev.md +++ b/{{cookiecutter.directory_name}}/README.dev.md @@ -138,35 +138,23 @@ This section describes how to make a release in 3 parts: ### (2/3) PyPI -In a new terminal, without an activated virtual environment or an env directory: +In a new terminal: ```shell -# prepare a new directory +# OPTIONAL: prepare a new directory with fresh git clone to ensure the release +# has the state of origin/main branch cd $(mktemp -d {{ cookiecutter.package_name }}.XXXXXX) - -# fresh git clone ensures the release has the state of origin/main branch git clone {{ cookiecutter.repository }} . -# prepare a clean virtual environment and activate it -python -m venv env -source env/bin/activate - -# make sure to have a recent version of pip and setuptools -python -m pip install --upgrade pip setuptools - -# install runtime dependencies and publishing dependencies -python -m pip install --no-cache-dir . -python -m pip install --no-cache-dir .[publishing] - -# clean up any previously generated artefacts -rm -rf {{ cookiecutter.package_name }}.egg-info -rm -rf dist +# make sure to have a recent version of pip and the publishing dependencies +python -m pip install --upgrade pip +python -m pip install .[publishing] # create the source distribution and the wheel -python setup.py sdist bdist_wheel +python -m build # upload to test pypi instance (requires credentials) -twine upload --repository-url https://test.pypi.org/legacy/ dist/* +python -m twine upload --repository testpypi dist/* ``` Visit @@ -183,7 +171,7 @@ python -m venv env source env/bin/activate # make sure to have a recent version of pip and setuptools -python -m pip install --upgrade pip setuptools +python -m pip install --upgrade pip # install from test pypi instance: python -m pip -v install --no-cache-dir \ @@ -198,7 +186,7 @@ Then upload to pypi.org with: ```shell # Back to the first terminal, # FINAL STEP: upload to PyPI (requires credentials) -twine upload dist/* +python -m twine upload dist/* ``` ### (3/3) GitHub diff --git a/{{cookiecutter.directory_name}}/pyproject.toml b/{{cookiecutter.directory_name}}/pyproject.toml index f29a49b1..7c216c7f 100644 --- a/{{cookiecutter.directory_name}}/pyproject.toml +++ b/{{cookiecutter.directory_name}}/pyproject.toml @@ -43,7 +43,7 @@ version = "{{ cookiecutter.version }}" [project.optional-dependencies] dev = [ - "build", + "build", # build is not only used in publishing (below), but also in the template's test suite "bump2version", "coverage [toml]", "pytest", @@ -56,6 +56,7 @@ dev = [ "myst_parser", ] publishing = [ + "build", "twine", "wheel", ]