Skip to main content

Template project for PyPI publication of a package using GitLab CI/CD that implements multiple down-sampled convolutions.

Project description

Down-sampled convolutions

License Downloads Downloads PyPI version

This module provides a function to compute F down-sampled convolutions using Numba and demonstrates how to publish this package on PyPI using GitLab INRIA CI/CD.

Python with pip

This example demonstrates how to use GitLab INRIA CI/CD with the pip project manager. Please, first read how to enable CI on your project.

It contains jobs to ensure the python project can be build, do unit testing with python3 -m unittest and generate the code coverage with coverage and eventually publish the package.

It also adds badges: coverage, version and downloads.

Source code

You can find a dummy function that computes the down-sampled convolution of an input signal x with a batch of filters filters in the script src/dsconv/dsconv.py. The documentation includes an example that will be tested using doctest Python module.

Dockerfile

The Dockerfile use Debian 13 image and install Numba, NumPy as-well-as SciPy in a Python virtual environment dsconv. It also installs Sphinx to build documentation.

# Create a virtual environment.
RUN mkdir /usr/local/venvs
RUN python3 -m venv /usr/local/venvs/dsconv

The .gitlab-ci.yml includes a stage to build the docker image and to store it.

build_docker_img:
  stage: build_img
  image: docker:stable
  script:
    - docker build -t "$CI_REGISTRY_IMAGE/debian13_dsconv" .
    - docker login -u gitlab-ci-token -p "$CI_JOB_TOKEN" "$CI_REGISTRY"
    - docker push "$CI_REGISTRY_IMAGE/debian13_dsconv"
  tags:
    - ci.inria.fr
    - small
    - linux

The build of the docker image triggers when a new branch is pushed or if the Dockerfile has been modified.

  # no build of docker image if specs haven't changed
  rules:
    - if: $CI_COMMIT_BRANCH
      changes:
        - Dockerfile
      when: always

This example uses small runner. It could be medium or large too.

Run unittest

Use the module doctest to check the example. Use coverage to get a coverage of the tests. At the end of the stage we ask to store the artifacts for only 30 days (see How can I manage and reduce my disk space? for more details). We extract part of the .gitlab-ci.yml file to highlight where to find the source code related to the tests:

whl_test:
  stage: test
  image: "$CI_REGISTRY_IMAGE/debian13_dsconv"
  coverage: '/Coverage:.*\%/'
  script:
    - source /usr/local/venvs/dsconv/bin/activate
    # Matches version in whl_pkg_rev
    - python3 -m pip install --no-deps dist/dsconv-0.0.0+${CI_COMMIT_SHA}-py3-none-any.whl
    - DSCONV_DIR=$(dirname $(python3 -c "import dsconv as mm; print(mm.__file__)"))
    # Check doctest.
    - python3 -m doctest -v src/dsconv/dsconv.py
    - coverage run -a --source $DSCONV_DIR tests/test_dsconv.py
    - coverage report $(find $DSCONV_DIR -name src/dsconv/dsconv.py) | tee /tmp/dsconv_coverage_report
    - COV=$(sed -e '/^$/d' /tmp/dsconv_cov_report | tail -1 | sed -e 's/.*\s\+//')
    # Print coverage.
    - 'echo Coverage: $COV'
    # Export coverage as html.
    - coverage html $(find $DSCONV_DIR -name "*.py")
  artifacts:
    paths:
      - htmlcov
    when: always
    expire_in: 30 days

Verification of PEP8

Use the package pycodestyle to check if your code satisfies PEP8. Do not verify PEP8 before tag. You can find more details in the pre_pages stage of .gitlab-ci.yml file.

GitLab pages

A small example of Sphinx documentation using "book theme" is available in the folder sphinx/source/. You have to install the following packages:

pip install sphinx
pip install myst_parser
pip install sphinx_autodoc_typehints
pip install sphinx_design
pip install sphinxcontrib_jquery
pip install sphinx_math_dollar
pip install sphinx_book_theme

pre_pages stage of .gitlab-ci.yml builds the documentation and store it as an artifact. You can find the artifacts in the build/Jobs section then pre_pages job and eventually clicking the browse button.

pages stage of .gitlab-ci.yml builds the documentation only if tag and publish it on GitLab pages.

Of note, you can locally build the documentation:

cd sphinx
make clean
make html

PyPI publication

To learn more about PyPI publication of your own package please have a look to the documentation. Note that you have to setup a PyPI token and store it in Settings/CI/CD/Variables section of your GitLab project or you can use Trusted Publishers. Currently, only projects hosted on https://gitlab.com are supported. Self-managed instances are not supported. We extract part of the .gitlab-ci.yml file to highlight where to find the source code related to the PyPI publication:

pypi_pub:
  stage: pkg_pub
  image: "$CI_REGISTRY_IMAGE/debian13_dsconv"
  script:
    - TOKEN=$(echo $PYPI_TOKEN | base64 -d)
    - python3 -m twine upload -u __token__ -p $(echo $TOKEN) --verbose --non-interactive dsconv-${CI_COMMIT_TAG}-py3-none-any.whl

The package publication triggers when a new tag is created.

  rules:
    - if: '$CI_COMMIT_TAG'
      when: always

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dsconv-0.0.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dsconv-0.0.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file dsconv-0.0.1.tar.gz.

File metadata

  • Download URL: dsconv-0.0.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for dsconv-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2607d6080f452c73d9ee36dea5a6135b168f406f34ee18a2f1233e6c997a2b76
MD5 a3cd335c71bdd36c84af9d2103a482ef
BLAKE2b-256 a4d22504fc09e4c31da2ba431ad966a64e28555adf03ecae074adfa9c8009616

See more details on using hashes here.

File details

Details for the file dsconv-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: dsconv-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for dsconv-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8a8ca6706bf10b18126537c1cebcb4fc75ffdedea69eba880c4b042cc546d4
MD5 7dc9e455f0b8ce59aaa1c48f6e89bd38
BLAKE2b-256 750c0b645280b9a6e460ab02f3de2ebb81ac036e40a53fe31ab4db764b295714

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page