Skip to content

Merge pull request #225 from andthum/feat/misc/dtrj-lifetimes/compare… #804

Merge pull request #225 from andthum/feat/misc/dtrj-lifetimes/compare…

Merge pull request #225 from andthum/feat/misc/dtrj-lifetimes/compare… #804

Workflow file for this run

# 1.) Format and Lint code
# 2.) Test code
#
# See:
# https://docs.github.com/en/actions/guides/building-and-testing-python
# Keep in sync with `test-skip.yml`.
name: "Tests"
on:
push:
branches:
- "**"
paths:
- ".github/**"
- "**.py"
- "**.rst"
- "docs/**"
- ".flake8"
- "pyproject.toml"
- "**requirements*.txt"
tags:
- "v[0-9]*"
release:
jobs:
# TODO: The lint job can be removed in favor of pre-commit.ci when all
# files are formatted with black and are compliant with flake8.
lint:
strategy:
matrix:
os:
- "ubuntu-latest"
python-version:
- "3.9"
runs-on: "${{ matrix.os }}"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v4"
- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python-version }}"
- name: "Export ${HOME}/.local/bin to ${PATH}"
# Executable Python binaries are usually stored there.
run: 'echo "${HOME}/.local/bin" >> ${GITHUB_PATH}'
- name: "Get pip cache dir"
# pip's cache path depends on the operating system. See
# https://github.com/actions/cache/blob/main/examples.md#python---pip
# This requires pip >=20.1.
id: "pip-cache"
run: |
python -m pip install --user --upgrade pip
echo "dir=$(pip cache dir)" >> ${GITHUB_OUTPUT}
- name: "Create/Restore cache"
uses: "actions/cache@v4"
with:
path: "${{ steps.pip-cache.outputs.dir }}/**"
key: |
${{ runner.os }}-${{ matrix.python-version }}-${{ github.job }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}
${{ runner.os }}
- name: "Install/Upgrade setuptools and wheel"
run: "python -m pip install --user --upgrade setuptools wheel"
- name: "Install/Upgrade packages in requirements-dev.txt"
run: |
python -m pip install \
--user \
--upgrade \
--requirement requirements-dev.txt
- name: "Check code formatting with black"
# TODO: The --include flag should be removed once all files are
# formatted with black. But as long as this is not the case,
# only check those files that are already formatted.
run: |
python -m black ./ --check --diff --color \
--include \
docs/source/conf.py \
misc/*.py \
src/mdtools/__init__.py \
src/mdtools/_metadata.py \
src/mdtools/box.py \
src/mdtools/dtrj.py \
src/mdtools/file_handler.py \
src/mdtools/functions.py \
src/mdtools/numpy_helper_functions.py \
src/mdtools/plot.py \
src/mdtools/run_time_info.py \
src/mdtools/scipy_helper_functions.py \
src/mdtools/select.py \
src/mdtools/statistics.py \
src/mdtools/structure.py \
src/mdtools/version.py \
scripts/discretization/back_jump*.py \
scripts/discretization/discrete_pos.py \
scripts/discretization/kaplan_meier*.py \
scripts/discretization/plot_*.py \
scripts/discretization/state_lifetime* \
scripts/dynamics/extract_renewal_events.py \
scripts/dynamics/lifetime_autocorr*.py \
scripts/dynamics/msd_layer*.py \
scripts/dynamics/plot_msd_layer*.py \
scripts/gmx/*.py \
scripts/other/*.py \
scripts/structure/densmap.py \
scripts/structure/lig_change_at_pos_change_blocks.py \
scripts/structure/subvolume_charge.py \
scripts/structure/plot_gmx_densmap.py \
scripts/structure/rmsd_vs_time.py \
scripts/templates/*.py \
*.py
- name: "Lint code and docstrings with flake8"
# Use setup.cfg to configure flake8
# TODO: The --select flag should be removed once all files are
# revised to be compliant with flake8. But as long as this is
# not the case, select only those error codes that have been
# fixed in all files.
#
# F821 ("undefined name name") gives false positives in
# doctests, because it does not recognize `doctest_global_setup`
# in the Sphinx configuration file `conf.py`.
#
# W504 ("line break after binary operator") is turned on in the
# .flake config file but the error code isn't fixed in all
# files, yet. So, ignore it in the CI workflow for now.
#
# The other ignored error codes are copied from the .flake8
# config file.
run: |
python -m flake8 ./ \
--select=\
E1,E2,E3,E4,E9,\
F4,F7,F63,F82,\
W1,W2,W3 \
--extend-ignore=\
S101,\
D205,D400,\
E203,W503,\
S404,S603,\
B028,\
N806,N813,\
W504,\
F821
test:
strategy:
matrix:
# Tests must be run on all target platforms and Python versions.
os:
- "ubuntu-latest"
- "macos-latest"
- "windows-latest"
python-version:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
# Python 3.6 is not supported anymore in the Ubuntu 22.04 runner
# https://github.com/actions/setup-python/issues/544#issuecomment-1332535877
exclude:
- os: "ubuntu-latest"
python-version: "3.6"
include:
- os: "ubuntu-20.04"
python-version: "3.6"
# Do not cancel in-progress jobs if any matrix job fails
fail-fast: false
runs-on: "${{ matrix.os }}"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v4"
- name: "Set up Python ${{ matrix.python-version }}"
uses: "actions/setup-python@v5"
with:
python-version: "${{ matrix.python-version }}"
- name: "Export ${HOME}/.local/bin to ${PATH}"
# Executable Python binaries are usually stored there.
run: 'echo "${HOME}/.local/bin" >> ${GITHUB_PATH}'
- name: "Get pip cache dir"
# pip's cache path depends on the operating system. See
# https://github.com/actions/cache/blob/main/examples.md#python---pip
# This requires pip >=20.1.
id: "pip-cache"
run: |
python -m pip install --user --upgrade pip
echo "dir=$(pip cache dir)" >> ${GITHUB_OUTPUT}
- name: "Create/Restore cache"
uses: "actions/cache@v4"
with:
path: |
${{ steps.pip-cache.outputs.dir }}/**
./docs/build/**
key: |
${{ runner.os }}-${{ matrix.python-version }}-${{ github.job }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}
${{ runner.os }}
- name: "Install/Upgrade setuptools and wheel"
# MDAnalysis requires NumPy (>=1.19.2) for setup (see also
# https://github.com/MDAnalysis/mdanalysis/issues/3374#issuecomment-889189979).
# MDAnalysis <3.0 requires Cython <3.0 (see
# https://github.com/MDAnalysis/mdanalysis/pull/4129 and
# https://github.com/cython/cython/issues/3690).
# Without `python-dev-tools` the installation of MDAnalysis
# fails on MacOS-latest with Python 3.9 while building the wheel
# for MDAnalysis. Strangely, the MDAnalysis wheel is only build
# on this OS-Python combination, whereas other OS-Python
# combinations fetch a pre-build wheel.
run: |
python -m pip install --user --upgrade setuptools wheel
python -m pip install --user --upgrade python-dev-tools
python -m pip install --user "Cython <3.0"
python -m pip install --user "numpy >=1.19.2"
- name: "Test installation of MDTools"
run: |
python -m pip install --user .
python -c "import mdtools"
# Test import of all modules that must be loaded explicitly.
python -c "import mdtools.plot"
- name: "Install/Upgrade requirements to build the documentation"
run: |
python -m pip install --user --upgrade -r docs/requirements-docs.txt
- name: "Test build of the documentation"
run: "make -C ./docs/ html"
- name: "doctest"
# Because the default dtypes of NumPy arrays are different on
# Windows, doctest will detect false failures. See e.g.
# https://stackoverflow.com/questions/36278590/numpy-array-dtype-is-coming-as-int32-by-default-in-a-windows-10-64-bit-machine
if: "${{ runner.os != 'Windows' }}"
run: "make -C ./docs/ doctest"
- name: "linkcheck"
if: "${{ runner.os == 'Linux' && matrix.python-version == '3.9' }}"
run: "make -C ./docs/ linkcheck"
- name: "Install/Upgrade PyTest"
run: "python -m pip install --user --upgrade pytest"
- name: "Test code with pytest"
run: "python -m pytest ./"