Skip to content

Commit

Permalink
Merge pull request #115 from dnvgl/config-python-versions
Browse files Browse the repository at this point in the history
Update project configuration and python versions
  • Loading branch information
eneelo authored Dec 5, 2023
2 parents 1b31108 + f44d5a9 commit e94c0a5
Show file tree
Hide file tree
Showing 57 changed files with 543 additions and 701 deletions.
29 changes: 12 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# This workflow will upload a Python Package using Twine when a release is created
# This workflow will upload new releases to PyPi
# Could write it explicitely ourself but this was neat.
# Consider moving the docs dependencies to dev to speed up (probably not a problem).
# reference: https://github.com/marketplace/actions/publish-python-poetry-package

name: Upload Python Package to PyPi

Expand All @@ -12,20 +15,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Check out repository
uses: actions/checkout@v4
- name: Build and publish to pypi
uses: JRubics/[email protected]
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel twine
- name: Build package
run: python setup.py sdist bdist_wheel
- name: Publish package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
python_version: "3.11"
plugins: "poetry-dynamic-versioning[plugin]"
ignore_dev_requirements: "yes"
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
107 changes: 79 additions & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# This workflow will lint, run unit tests, test CLI and build with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test Python package
Expand All @@ -10,47 +10,98 @@ on:
branches: [ master ]

jobs:
build:

name: Test with Python ${{ matrix.python-version }} on Ubuntu
linting:
name: Linting
# linting has nothing to do with multiple versions of os and python
# (the result will be the same) and therefore separated to save time
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Load pip cache if cache exists
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
restore-keys: ${{ runner.os }}-pip
- name: Install linters
run: python -m pip install black flake8 isort
- name: Lint code
run: |
flake8 ./qats/ --exit-zero --max-complexity=10 --statistics
black .
isort .
testing:
needs: linting
name: Test with Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: ["ubuntu-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
# https://stackoverflow.com/questions/75549995/why-do-the-pyside6-qt-modules-cause-tox-to-fail-during-a-github-action
- name: Install missing libraries on GitHub agent
run: sudo apt update && sudo apt install -y libegl1-mesa-dev
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Load cached Poetry installation
id: cached-poetry
uses: actions/cache@v3
with:
path: ~/.local # the path depends on the OS
key: poetry-0 # increment to reset cache
- name: Install and configure Poetry
# install if not cached. Create venv in project to simplify caching
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
# Consider specifying version (version: 1.7.1 on Python 3.11)
virtualenvs-create: true
virtualenvs-in-project: true #.venv in current directory
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Create venv and install project dependencies
# install if not cached
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install project
# required to test the CLI, show working directory for debugging
run: |
python -m pip install --upgrade pip
python -m pip install flake8
# python -m pip install setuptools-scm flake8 wheel pyside2 h5py pymatreader matplotlib npTDMS numpy openpyxl pandas scipy
# changed 27.12.2023: install from requirements.txt, so that incompatibilities in requirements lead to failed tests
python -m pip install -r requirements.txt
- name: Lint with flake8
poetry install --no-interaction
ls -a
- name: Run unit tests
run: |
# stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
source .venv/bin/activate
pytest test/
- name: Test CLI
env:
QT_API: pyside2
QT_API: pyside6
run: |
python -m unittest discover
python setup.py install
# test running qats via entry points
source .venv/bin/activate
qats -h
qats app -h
qats config -h
# test running qats via __main__ hook
python -m qats -h
# test that building documentation does not fail
- name: Test building package
run: poetry build
- name: Test building documentation
run: |
source .venv/bin/activate
sphinx-build -b html docs/source docs/_build
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ code-snippets/

# local test folders
tmp*/*

# version file written by poetry dynamic versioning
*/_version.py

# Poetry
poetry.lock
24 changes: 11 additions & 13 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ version: 2
# Set the version of Python and other tools you might need
build:
os: ubuntu-20.04
tools:
# minimum supported Python version
python: "3.7"
tools: {python: "3.11"}
# A solution to build docs with Poetry and avoid an additional (out of sync) requirements.txt
# https://github.com/Robpol86/sphinx-multi-theme/blob/28aac0ac3bd54387bd51bfb9c673c2208394c729/.readthedocs.yaml
jobs:
pre_create_environment:
- asdf plugin add poetry
- asdf install poetry latest
- asdf global poetry latest
- poetry config virtualenvs.create false
post_install:
- poetry install

# Build documentation in the docs/ directory with Sphinx
sphinx:
builder: html
configuration: docs/source/conf.py
fail_on_warning: true

# Optionally declare the Python requirements required to build your docs
python:
# install qats first, then requirements
# (because RTD uses `--upgrade-strategy eager` to install the package,
# which installs the latest possible version of all dependencies)
install:
- method: pip
path: .
- requirements: requirements.txt
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog

> **Note:**
> After version 4.12.1 this changelog is deprecated. Releases will in future be documented in [Github's releases page](https://github.com/dnvgl/qats/releases).

All notable changes to the project will be documented in this file, with format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

We apply the *"major.minor.micro"* versioning scheme defined in [PEP 440](https://www.python.org/dev/peps/pep-0440).
Expand Down
79 changes: 35 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ perfect for inspecting, comparing and reporting:

![QATS GUI](https://raw.githubusercontent.com/dnvgl/qats/master/docs/source/demo.gif)

## Python version support

QATS supports Python 3.7, 3.8, 3.9 and 3.10.

## Getting started

### Installation
Expand All @@ -56,21 +52,20 @@ python -m pip install --upgrade qats
You may now import qats in your own scripts:

```python
from qats import TsDB, TimeSeries
>>> from qats import TsDB, TimeSeries
```

... or use the GUI to inspect time series. Note that as of version 4.2.0 you are quite free to choose which
[Qt](https://www.qt.io) binding you would like to use for the GUI: [PyQt5](https://pypi.org/project/PyQt5/) or
[PySide2](https://pypi.org/project/PySide2/), or even [PyQt4](https://pypi.org/project/PyQt4/) /
[PySide](https://pypi.org/project/PySide/).
... or use the GUI to inspect time series.

Install the chosen binding (here PyQt5 as an example):
_New in version 5.0.0._
The [Qt](https://www.qt.io) binding [PySide6](https://pypi.org/project/PySide6/) is installed with `qats`.
If you would rather like to use [PyQt6](https://pypi.org/project/PyQt6/), run

```console
python -m pip install pyqt5
python -m pip install pyqt6
```

If multiple Qt bindinds are installed, the one to use may be controlled by setting the environmental variable `QT_API` to the desired package. Accepted values include `pyqt5` (to use PyQt5) and `pyside2` (PySide2). For more details, see [README file for qtpy](https://github.com/spyder-ide/qtpy/blob/master/README.md).
If multiple Qt bindinds are installed, the one to use may be controlled by setting the environmental variable `QT_API` to the desired package. Accepted values include `pyqt6` (to use PyQt6) and `pyside6` (PySide6). For more details, see [README file for qtpy](https://github.com/spyder-ide/qtpy/blob/master/README.md).

The GUI may now be launched by:

Expand All @@ -97,7 +92,7 @@ python -m qats config --link-app

* [**Source**](https://github.com/dnvgl/qats)
* [**Issues**](https://github.com/dnvgl/qats/issues)
* [**Changelog**](https://github.com/dnvgl/qats/blob/master/CHANGELOG.md)
* [**Changelog**](https://github.com/dnvgl/qats/releases)
* [**Documentation**](https://qats.readthedocs.io)
* [**Download**](https://pypi.org/project/qats/)

Expand All @@ -108,7 +103,13 @@ purposes. See deployment for notes on how to deploy the project on a live system

### Prerequisites

Install Python version 3.7 or later from either https://www.python.org or https://www.anaconda.com.
Install Python version 3.8 or later from either https://www.python.org or https://www.anaconda.com.

Install Poetry with [the official installer](https://python-poetry.org/docs/#installing-with-the-official-installer).

Install the [poetry-dynamic-versioning](https://pypi.org/project/poetry-dynamic-versioning/) plugin:

```poetry self add "poetry-dynamic-versioning[plugin]"```

### Clone the source code repository

Expand All @@ -118,35 +119,22 @@ At the desired location, run:

### Installing

To get the development environment running:

... create an isolated Python environment and activate it,

```console
python -m venv /path/to/new/virtual/environment

/path/to/new/virtual/environment/Scripts/activate
```

... install the dev dependencies in [requirements.txt](requirements.txt),

```console
python -m pip install -r requirements.txt
```

.. and install the package in development ("editable") mode.
To get the development environment running...

```console
python -m pip install -e .
poetry install
```

_Note: This is similar to the "legacy" development installation command ``python setup.py develop``, see the [setuptools page on development mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html)._
This will
- create an isolated environment
- install all dependencies including those required for development, testing and building documentation
- and install the package in development ("editable") mode

You should now be able to import the package in the Python console,

```python
import qats
help(qats)
>>> import qats
>>> help(qats)
```

... and use the command line interface (CLI).
Expand All @@ -171,13 +159,13 @@ python -m unittest discover

### Building the package

Build tarball and wheel distributions by:
Build tarball and wheel distributions by

```console
python setup.py sdist bdist_wheel
poetry build
```

The distribution file names adhere to the [PEP 0427](https://www.python.org/dev/peps/pep-0427/#file-name-convention)
The builds appear in the `.dist` folder. The distributions adhere to the [PEP 0427](https://www.python.org/dev/peps/pep-0427/#file-name-convention)
convention `{distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl`.

### Building the documentation
Expand All @@ -194,16 +182,19 @@ To force a build to read/write all files (always read all files and don't use a
sphinx-build -a -E -b html docs\source docs\_build
```

### Deployment
Packaging, unit testing and deployment to [PyPi](https://pypi.org/project/qats/) is automated using [GitHub Actions](https://docs.github.com/en/actions).

### Versioning

We apply the "major.minor.micro" versioning scheme defined in [PEP 440](https://www.python.org/dev/peps/pep-0440/). See also [Scheme choices](https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/#scheme-choices) on https://packaging.python.org/.

We cut a new version by applying a Git tag like `3.0.1` at the desired commit and then
[setuptools_scm](https://github.com/pypa/setuptools_scm/#setup-py-usage) takes care of the rest. For the versions
available, see the [tags on this repository](https://github.com/dnvgl/qats/tags).
Versions are tagged with Git tags like `v3.0.1`. See the [tags on this repository](https://github.com/dnvgl/qats/tags).

### Release and deployment

We use the [release cycle in GitHub](https://github.com/dnvgl/qats/releases) to cut new releases.

Once a new release is published, [GitHub Actions](https://docs.github.com/en/actions) takes care of the packaging, unit testing and deployment to [PyPi](https://pypi.org/project/qats/).

The workflows for continuous integration and deployment are found in [.github/workflows](.github/workflows/).

## Authors

Expand Down
2 changes: 2 additions & 0 deletions data/model_test_data.dat
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# test comment
# another comment
time[s] WaveC[m] Wave-F[m] Wave-S[m] Surge[m] Sway[m] Heave[m] Roll[deg] Pitch[deg] Yaw[deg] Acc-X[m/s^2] Acc-Y[m/s^3] Acc-Z[m/s^4] Ten-S-FP[kN] Ten-S-FS[kN] Ten-S-AS[kN] Ten-S-AP[kN] RW1[m] RW3[m] RW5[m] RW7[m] RW13[m] RW14[m] RW2[m] RW4[m] RW6[m] RW8[m] RW9[m] RW10[m] RW11[m] RW12[m] RW15[m] RW16[m] RW17[m] RW18[m] RW19[m] Ten-P-FP[kN] Ten-P-FS[kN] Ten-P-AS[kN] Ten-P-AP[kN]
0.0000000e+00 1.1468169e+00 -6.2024932e+00 1.5963418e+00 -1.2440454e+01 1.8175390e+00 5.8588385e-01 3.3933087e-01 1.6214460e+00 4.1363153e-01 1.1196024e-01 -2.3473288e-02 1.5040265e-01 3.6432728e+03 3.7840381e+03 2.5385340e+03 2.3443660e+03 -9.3945101e-01 -1.5887219e+00 -2.6872322e+00 -2.7754727e+00 9.6520604e-01 2.1473762e+00 -1.4565005e+00 -2.1295738e+00 -2.5923946e+00 -1.2597798e+00 -2.6924590e+00 -7.5948454e-01 1.4100411e+00 1.4251543e+00 -1.1114424e+00 -1.2456250e+00 1.1438377e+00 3.4769380e-01 -5.0987183e-01 3.6178672e+03 3.6655819e+03 2.5026818e+03 2.3855970e+03
7.0710678e-02 1.3147447e+00 -6.1294752e+00 1.5299688e+00 -1.2476236e+01 1.8165961e+00 6.0005881e-01 3.3398525e-01 1.6583331e+00 4.2669511e-01 1.1747680e-01 -2.1960561e-02 1.7126258e-01 3.6428042e+03 3.7912919e+03 2.5447336e+03 2.3366768e+03 -9.1152887e-01 -1.5730936e+00 -2.6601386e+00 -2.7932502e+00 1.1041916e+00 2.1576044e+00 -1.4025477e+00 -2.1228321e+00 -2.6254164e+00 -1.2523734e+00 -2.7433894e+00 -7.6519707e-01 1.4704902e+00 1.4266390e+00 -1.0990665e+00 -1.2547405e+00 1.1563448e+00 4.1997923e-01 -3.6905164e-01 3.6210090e+03 3.6738023e+03 2.5028865e+03 2.3816678e+03
Expand Down
Loading

0 comments on commit e94c0a5

Please sign in to comment.