Files
cibuildwheel/docs/deliver-to-pypi.md
T

100 lines
3.5 KiB
Markdown
Raw Normal View History

2019-10-02 09:49:31 +01:00
---
2019-10-06 20:36:37 +01:00
title: Delivering to PyPI
2019-10-02 09:49:31 +01:00
---
2022-08-16 22:53:11 +01:00
# Delivering to PyPI
2019-10-02 09:49:31 +01:00
After you've built your wheels, you'll probably want to deliver them to PyPI.
2021-11-13 11:55:53 -05:00
## Manual method
2019-10-02 09:49:31 +01:00
2021-11-13 11:55:53 -05:00
On your development machine, install [pipx](https://pypa.github.io/pipx/) and do the following:
2019-10-02 09:49:31 +01:00
```bash
2021-11-13 11:55:53 -05:00
# Either download the SDist from your CI, or make it:
2020-08-14 16:12:24 -04:00
# Clear out your 'dist' folder.
2019-10-02 09:49:31 +01:00
rm -rf dist
# Make a source distribution
2021-11-13 11:55:53 -05:00
pipx run build --sdist
2019-10-02 09:49:31 +01:00
# 🏃🏻
2019-10-06 20:36:37 +01:00
# Go and download your wheel files from wherever you put them. e.g. your CI
2020-08-14 16:12:24 -04:00
# provider can be configured to store them for you. Put them all into the
2019-10-06 20:36:37 +01:00
# 'dist' folder.
2019-10-02 09:49:31 +01:00
# Upload using 'twine'
2021-11-13 11:55:53 -05:00
pipx run twine upload dist/*
2019-10-02 09:49:31 +01:00
```
2021-11-13 11:55:53 -05:00
## Automatic method
2019-10-02 09:49:31 +01:00
2021-11-13 11:55:53 -05:00
If you don't need much control over the release of a package, you can set up
cibuildwheel to deliver the wheels straight to PyPI. You just need to bump the
version and tag it.
2019-10-02 09:49:31 +01:00
2021-11-13 11:55:53 -05:00
### Generic instructions
2019-10-02 09:49:31 +01:00
2021-11-13 11:55:53 -05:00
Make your SDist with the [build](https://github.com/pypa/build) tool, and your wheels with cibuildwheel. If you can make the files available as
downloadable artifacts, this make testing before releases easier (depending on your CI provider's options). The "publish" job/step should collect the
files, and then run `twine upload <paths>` (possibly via [pipx](https://github.com/pypa/pipx)); this should only happen on tags or "releases".
2019-10-02 09:49:31 +01:00
2021-11-13 11:55:53 -05:00
### GitHub Actions
2019-10-02 09:49:31 +01:00
2021-11-13 11:55:53 -05:00
GitHub actions has pipx in all the runners as a supported package manager, as
well as several useful actions. Alongside your existing job(s) that runs cibuildwheel to make wheels, you will probably want to build an SDist:
```yaml
make_sdist:
name: Make SDist
runs-on: ubuntu-latest
steps:
2023-09-05 10:09:36 -04:00
- uses: actions/checkout@v4
2021-11-13 11:55:53 -05:00
with:
fetch-depth: 0 # Optional, use if you use setuptools_scm
submodules: true # Optional, use if you have submodules
- name: Build SDist
run: pipx run build --sdist
2022-06-18 14:11:42 +03:00
- uses: actions/upload-artifact@v3
2021-11-13 11:55:53 -05:00
with:
path: dist/*.tar.gz
```
Then, you need to publish the artifacts that the previous jobs have built. This final job should run only on release or tag, depending on your preference. It gathers the artifacts from the sdist and wheel jobs and uploads them to PyPI. The release environment (`pypi` in the example below) will be created the first time this workflow runs.
2021-11-13 11:55:53 -05:00
This requires setting this GitHub workflow in your project's PyPI settings (for a [new project](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc)/[existing project](https://docs.pypi.org/trusted-publishers/adding-a-publisher)).
2021-11-13 11:55:53 -05:00
```yaml
upload_all:
needs: [build_wheels, make_sdist]
environment: pypi
permissions:
id-token: write
2021-11-13 11:55:53 -05:00
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
2022-06-18 14:11:42 +03:00
- uses: actions/download-artifact@v3
2021-11-13 11:55:53 -05:00
with:
name: artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
2021-11-13 11:55:53 -05:00
```
You should use Dependabot to keep the publish action up to date. In the above
2021-11-13 11:55:53 -05:00
example, the same name (the default, "artifact" is used for all upload-artifact
runs, so we can just download all of the in one step into a common directory.
See
[`examples/github-deploy.yml`](https://github.com/pypa/cibuildwheel/blob/main/examples/github-deploy.yml)
for an example configuration that automatically upload wheels to PyPI. Also see
[scikit-hep.org/developer/gha_wheels](https://scikit-hep.org/developer/gha_wheels)
for a complete guide.
### TravisCI
See
[`examples/travis-ci-deploy.yml`](https://github.com/pypa/cibuildwheel/blob/main/examples/travis-ci-deploy.yml)
for an example configuration.