From f4bb5efcf84cc60c7bb662a56c3d5b2e5e11c010 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Mon, 3 Oct 2022 11:43:10 +0200 Subject: [PATCH 1/3] Add docs/demo.ipynb to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b6e4761..9624e8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +docs/demo.ipynb + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From 9c1d947b265aa55c59f29524a15e95e73f16afde Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Mon, 3 Oct 2022 12:22:36 +0200 Subject: [PATCH 2/3] A docs and workflow for publishing to pypi --- .github/workflows/pypi.yml | 43 +++++++++++++++++++++++++++++++++ docs/_toc.yml | 8 +++++- docs/part4/conda.md | 5 ++++ docs/part4/docker.md | 3 +++ docs/part4/pypi.md | 10 ++++++++ docs/{part4 => part5}/badges.md | 0 pyproject.toml | 3 +++ 7 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pypi.yml create mode 100644 docs/part4/conda.md create mode 100644 docs/part4/docker.md create mode 100644 docs/part4/pypi.md rename docs/{part4 => part5}/badges.md (100%) diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..371ddf5 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,43 @@ +name: PyPI + +on: + push: + # The CI is executed on every push on every branch + branches: + - main + pull_request: + # The CI is executed on every pull request to the main branch + branches: + - main + + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: python3 -m pip install ".[pypi]" + + - name: Build a binary wheel and a source tarball + run: >- + python3 -m + build + --sdist + --wheel + --outdir dist/ + . + + - name: Publish distribution 📦 to PyPI + if: startsWith(github.ref, 'refs/tags') # Only push to pypi when there is a new tag + uses: pypa/gh-action-pypi-publish@master + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/docs/_toc.yml b/docs/_toc.yml index 5bc9070..779f090 100644 --- a/docs/_toc.yml +++ b/docs/_toc.yml @@ -32,8 +32,14 @@ parts: # The following file should be autogenerated by the Makefile - file: "demo.ipynb" + - caption: Distribution + chapters: + - file: "part4/pypi" + - file: "part4/conda" + - file: "part4/docker" + - caption: Other Features chapters: - - file: "part4/badges" + - file: "part5/badges" diff --git a/docs/part4/conda.md b/docs/part4/conda.md new file mode 100644 index 0000000..8c0b7f8 --- /dev/null +++ b/docs/part4/conda.md @@ -0,0 +1,5 @@ +# Publishing conda package + +TBW + +## Uploading your package to conda-forge \ No newline at end of file diff --git a/docs/part4/docker.md b/docs/part4/docker.md new file mode 100644 index 0000000..509bd33 --- /dev/null +++ b/docs/part4/docker.md @@ -0,0 +1,3 @@ +# Publishing docker image for your package + +TBW \ No newline at end of file diff --git a/docs/part4/pypi.md b/docs/part4/pypi.md new file mode 100644 index 0000000..a26f1ac --- /dev/null +++ b/docs/part4/pypi.md @@ -0,0 +1,10 @@ +# Publishing package to pypi + +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/) + +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/) + + +## Building multiple wheels using `cibuildwheel` + +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/). \ No newline at end of file diff --git a/docs/part4/badges.md b/docs/part5/badges.md similarity index 100% rename from docs/part4/badges.md rename to docs/part5/badges.md diff --git a/pyproject.toml b/pyproject.toml index a2c21b8..d006f20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,9 @@ binder = [ # Required to interface with Binder when having a Dockerfile in root "jupyterlab", "notebook" ] +pypi = [ + "build" # Used for building wheels and uploading to pypi +] [tool.mypy] ignore_missing_imports = true # Does not show errors when importing untyped libraries From 9c2701139f5372cd9d8cafb0aac5dd28732c368b Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Mon, 3 Oct 2022 12:30:37 +0200 Subject: [PATCH 3/3] Add workflow of publishing docker image --- .github/workflows/docker-image.yml | 49 ++++++++++++++++++++++++++++++ docs/part4/docker.md | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..0cd0590 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,49 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Create and publish a Docker image + +on: + push: + branches: + - "!*" + tags: + - "v*" + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/docs/part4/docker.md b/docs/part4/docker.md index 509bd33..745b92d 100644 --- a/docs/part4/docker.md +++ b/docs/part4/docker.md @@ -1,3 +1,3 @@ # Publishing docker image for your package -TBW \ No newline at end of file +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 \ No newline at end of file