Skip to content

Commit

Permalink
refactor workflow to install from build configuration and use `pytest…
Browse files Browse the repository at this point in the history
…` and `tox` (#218)

* refactor workflow to install from build configuration and use `pytest`

* branch filter

* use `tox`

* add coverage

* remove schedule

* ignore lint rule

* add `xdist` to env list

* don't fail-fast checks

* add `long_description`

* add `build-backend` to use PEP517 build
  • Loading branch information
zacharyburnett authored Jan 5, 2023
1 parent d4e1c66 commit 78cca9f
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 54 deletions.
95 changes: 44 additions & 51 deletions .github/workflows/python_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,57 @@ name: CalCOS Pytest

on:
push:
branches: [ pytest ]
branches:
- master
pull_request:
branches: [ pytest ]
schedule:
- cron: '00 00 * * *' # every day at midnight
branches:
- master

jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.runs-on }}
env:
check:
name: ${{ matrix.toxenv }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toxenv: [ check-style, check-build ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'tox.ini'
- run: pip install tox
- run: tox -e ${{ matrix.toxenv }}
test:
name: ${{ matrix.toxenv }} (Python ${{ matrix.python }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
TEST_BIGDATA: https://bytesalad.stsci.edu/artifactory
lref: /grp/hst/cdbs/lref/
working-directory: ./
strategy:
fail-fast: false
matrix:
toxenv: [ test-xdist ]
python: [ '3.8', '3.9', '3.10', '3.11' ]
os: [ ubuntu-latest,macos-latest ]
include:
- name: Python 3.10
runs-on: ubuntu-latest
python-version: '3.10'
toxenv: py310

- name: Python 3.9
runs-on: ubuntu-latest
python-version: 3.9
toxenv: py39

- name: Python 3.8
runs-on: ubuntu-latest
python-version: 3.8
toxenv: py38

- toxenv: test-cov-xdist
os: ubuntu-latest
python: '3.11'
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install ci-watson
pip install astropy
pip install scipy
pip install matplotlib
pip install stsci.tools==4.0.0
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
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: Test with pytest
run: |
# run all the unit tests.
python setup.py install
pytest tests/test_cosutil.py -v
working-directory: ${{env.working-directory}}
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: 'pip'
cache-dependency-path: 'tox.ini'
- run: pip install tox
- run: tox -e ${{ matrix.toxenv }}
- if: contains(matrix.toxenv, '-cov')
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unit
fail_ci_if_error: true
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ requires = [
"wheel",
"oldest-supported-numpy",
]
build-backend = 'setuptools.build_meta'
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ junit_family = xunit2

[flake8]
# E265: block comment should start with '#'
ignore = E265
# F821 undefined name
ignore = E265,F821,F841
exclude = setup.py,__init__.py
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def c_includes(parent, depth=1):
'astropy>=5.0.4',
'numpy',
'scipy',
'stsci.tools',
'stsci.tools>=4.0.0',
],
extras_require={
'docs': [
'sphinx',
],
'test': [
'ci_watson',
'ci-watson',
'pytest',
'pytest-cov',
'codecov',
Expand Down Expand Up @@ -74,6 +74,8 @@ def c_includes(parent, depth=1):
author='Phil Hodge, Robert Jedrzejewski',
author_email='[email protected]',
description='Calibration software for COS (Cosmic Origins Spectrograph)',
long_description='README.md',
long_description_content_type='text/x-rst',
url='https://github.com/spacetelescope/calcos',
license='BSD',
classifiers=[
Expand Down
77 changes: 77 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[tox]
envlist =
check-{style,build}
test{,-pyargs,-warnings,-regtests,-cov}-xdist
build-{docs,dist}

# tox environments are constructed with so-called 'factors' (or terms)
# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor:
# will only take effect if that factor is included in the environment name. To
# see a list of example environments that can be run, along with a description,
# run:
#
# tox -l -v
#

[testenv:check-style]
description = check code style, e.g. with flake8
skip_install = true
deps =
flake8
commands =
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics {posargs}
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics {posargs}

[testenv:check-build]
description = check build sdist/wheel and a strict twine check for metadata
skip_install = true
deps =
build
twine>=3.3
commands =
python -m build .
twine check --strict dist/*

[testenv]
description =
run tests
warnings: treating warnings as errors
regtests: with --bigdata and --slow flags
cov: with coverage
xdist: using parallel processing
passenv =
HOME
CRDS_*
CODECOV_*
TEST_BIGDATA
lref
extras =
test
deps =
cov: pytest-cov
xdist: pytest-xdist
commands_pre =
pip freeze
commands =
pytest --slow \
regtests: --bigdata \
cov: --cov --cov-report=xml \
warnings: -W error \
xdist: -n auto \
{posargs}

[testenv:build-docs]
description = invoke sphinx-build to build the HTML docs
skip_install = true
extras =
docs
commands =
sphinx-build -W docs/source docs/_build

[testenv:build-dist]
description = build wheel and sdist
skip_install = true
deps =
build
commands =
python -m build .

0 comments on commit 78cca9f

Please sign in to comment.