Skip to content

Commit 9c1d947

Browse files
committed
A docs and workflow for publishing to pypi
1 parent f4bb5ef commit 9c1d947

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

.github/workflows/pypi.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: PyPI
2+
3+
on:
4+
push:
5+
# The CI is executed on every push on every branch
6+
branches:
7+
- main
8+
pull_request:
9+
# The CI is executed on every pull request to the main branch
10+
branches:
11+
- main
12+
13+
14+
jobs:
15+
test:
16+
name: Test
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Setup Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: "3.10"
26+
27+
- name: Install dependencies
28+
run: python3 -m pip install ".[pypi]"
29+
30+
- name: Build a binary wheel and a source tarball
31+
run: >-
32+
python3 -m
33+
build
34+
--sdist
35+
--wheel
36+
--outdir dist/
37+
.
38+
39+
- name: Publish distribution 📦 to PyPI
40+
if: startsWith(github.ref, 'refs/tags') # Only push to pypi when there is a new tag
41+
uses: pypa/gh-action-pypi-publish@master
42+
with:
43+
password: ${{ secrets.PYPI_API_TOKEN }}

docs/_toc.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ parts:
3232
# The following file should be autogenerated by the Makefile
3333
- file: "demo.ipynb"
3434

35+
- caption: Distribution
36+
chapters:
37+
- file: "part4/pypi"
38+
- file: "part4/conda"
39+
- file: "part4/docker"
40+
3541
- caption: Other Features
3642
chapters:
37-
- file: "part4/badges"
43+
- file: "part5/badges"
3844

3945

docs/part4/conda.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Publishing conda package
2+
3+
TBW
4+
5+
## Uploading your package to conda-forge

docs/part4/docker.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Publishing docker image for your package
2+
3+
TBW

docs/part4/pypi.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Publishing package to pypi
2+
3+
Whenever you have a package that you want to share with others, you need a way to distribute it with others. Sharing your package through a repository at GitHub is one way, but most programming langues have their own way of distributing packages. For example `node` uses [npm](https://www.npmjs.com), `rust` uses [`crates.io`](https://crates.io) and `julia` uses [`Pkg`](https://docs.julialang.org/en/v1/stdlib/Pkg/)
4+
5+
Python uses the [Python Packaging Index (PyPI)](https://pypi.org) where the process is to first build a wheel of your package and then upload this wheel to the index. You can do everything with a package called [`build`](https://github.com/pypa/build), and of course you can [automate the process using GitHub actions](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)
6+
7+
8+
## Building multiple wheels using `cibuildwheel`
9+
10+
If your package contains extensions written in another language than python then you might need to build wheels for different platforms and architectures. In this case you can use a tool such as [`cibuildwheel`](https://cibuildwheel.readthedocs.io/en/stable/).
File renamed without changes.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ binder = [ # Required to interface with Binder when having a Dockerfile in root
3434
"jupyterlab",
3535
"notebook"
3636
]
37+
pypi = [
38+
"build" # Used for building wheels and uploading to pypi
39+
]
3740

3841
[tool.mypy]
3942
ignore_missing_imports = true # Does not show errors when importing untyped libraries

0 commit comments

Comments
 (0)