Skip to content

Commit 90f3073

Browse files
authored
Add docs and workflows for distributing packages (#35)
* Add docs/demo.ipynb to .gitignore * A docs and workflow for publishing to pypi * Add workflow of publishing docker image
1 parent f0cffca commit 90f3073

File tree

9 files changed

+122
-1
lines changed

9 files changed

+122
-1
lines changed

.github/workflows/docker-image.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Create and publish a Docker image
7+
8+
on:
9+
push:
10+
branches:
11+
- "!*"
12+
tags:
13+
- "v*"
14+
15+
env:
16+
REGISTRY: ghcr.io
17+
IMAGE_NAME: ${{ github.repository }}
18+
19+
jobs:
20+
build-and-push-image:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
packages: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v2
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
45+
with:
46+
context: .
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}

.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 }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
docs/demo.ipynb
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

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+
Publishing a docker image is perhaps one of the best ways to make sure that people are able to run your package in exactly the same environment as you. GitHub has the possibility to [publish docker images](https://docs.github.com/en/actions/publishing-packages/publishing-docker-images) as a part of GitHub packages

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)