Skip to content
Snippets Groups Projects
VIPS Logo

VIPSCore-Python-Common

This is the source code for the module that contains the common data models and utilities for the Python implementation(s) of VIPS. It can be installed with pip like this:

# From local path, if you've cloned the Git repo
pip3 install /home/foo/vipscore-python-common/
# From GitLab
pip3 install git+https://gitlab.nibio.no/VIPS/vipscore-python-common.git@v0.1.7

...where the version is specified after the @

If you're implementing a VIPS model, typical imports would be

from vipscore_common.vips_model import VIPSModel
from vipscore_common.entities import Result, ModelConfiguration, WeatherObservation
from vipscore_common.data_utils import *

Developer guide

Unit tests

The tests are located in the tests folder, and we're using Pytest

Prerequisite: To test, use a venv, install this package in it by running:

(venv) $ python -m pip install -e .

To run the unit tests, move to the root folder of the project, and execute:

pytest -v

Using bumpver

For developers: When you want to publish a new version, use

# Increment the PATCH version when you make backwards compatible bug fixes.
bumpver update --patch
# Increment the MINOR version when you add functionality in a backwards compatible manner.
bumpver update --minor
# Increment the MAJOR version when you make incompatible API changes.
bumpver update --major

(Source)

References

We used this excellent guide for packaging: https://realpython.com/pypi-publish-python-package/

Deployment

Whenever changes are pushed to the repository, the pipeline defined in .gitlab-ci.yml is triggered. Here, there are three jobs: build, test and deploy. The final job will only be performed for the main branch. Please note that publishing a package to the package repository will fail (= red deploy job) if the version of the package has not been bumped since the previous deploy.

Follow these steps for running build, test + deploy on your laptop:

  1. Create Personal access token with name=gitlab-pypi and scope=Api.

  2. Create file ~/.pypirc with the following content:

[distutils]
index-servers =
    gitlab

[gitlab]
repository = https://gitlab.nibio.no/api/v4/projects/401/packages/pypi
username = gitlab-pypi
password = <personal access token>
  1. Clone project, build, test and deploy package
$ git clone git@gitlab.nibio.no:VIPS/vipscore-python-common.git
$ cd vipscore-python-common
$ python3 -m venv venv
$ . venv/bin/activate 
$ pip install -e .
$ pip install build pytest twine
$ python3 -m build
-> Successfully built vipscore_common-0.1.7.tar.gz and vipscore_common-0.1.6-py3-none-any.whl
$ pytest
-> [100%] ======================= 2 passed in 0.27s ==========================
$ python3 -m twine upload --repository gitlab dist/* --verbose
-> Uploading vipscore_common-0.1.7-py3-none-any.whl
-> 201 Created
-> Uploading vipscore_common-0.1.7.tar.gz
-> 201 Created