Skip to content

Commit

Permalink
refactor CI and use tox.ini with Tox 4 and PEP517 build (#108)
Browse files Browse the repository at this point in the history
* refactor CI and use `tox.ini` with TOx 4 and PEP517 build

* add `long_description_content_type` to satisfy metadata check

* ignore directories in pytest discovery

* remove `src` from `testpaths`

* add change log entry

* set CRDS path
  • Loading branch information
zacharyburnett committed Jan 12, 2023
1 parent 655677c commit 1e90078
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 95 deletions.
127 changes: 33 additions & 94 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,121 +14,60 @@ on:
- cron: '0 9 * * 1'

jobs:
style:
name: Code style checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: setup.cfg
- run: pip install pyproject-flake8
- run: pflake8 --count src
audit:
name: Bandit security audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: setup.cfg
- run: pip install bandit
- run: bandit -r -ll src
test:
name: test
needs: [ style, audit ]
check:
name: ${{ matrix.toxenv }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python: [ 3.8, 3.9, '3.10' ]
os: [ ubuntu-latest, macos-latest ]
toxenv: [ check-style, check-security, check-build ]
python-version: [ '3.11' ]
os: [ ubuntu-latest ]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.cfg
- run: pip install -e ".[test]" pytest-xdist
- run: pip freeze
- run: pytest -n auto
test_jwst_datamodels:
name: test latest version of `jwst.datamodels` with this commit
needs: [ style, audit ]
runs-on: ubuntu-latest
- run: pip install "tox>=4.0"
- run: tox -e ${{ matrix.toxenv }}
test:
name: ${{ matrix.toxenv }} (Python ${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
env:
CRDS_SERVER_URL: https://jwst-crds.stsci.edu
CRDS_PATH: /home/runner/work/stdatamodels/crds_cache
CRDS_CLIENT_RETRY_COUNT: 3
CRDS_CLIENT_RETRY_DELAY_SECONDS: 20
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'
cache-dependency-path: setup.cfg
- run: pip install -e ".[test]" pytest-xdist
- run: pip install "jwst[test] @ git+https://github.com/spacetelescope/jwst.git"
- run: pip freeze
- run: echo "crds_context=$(crds list --operational-context)" >> $GITHUB_OUTPUT
id: crds_context
- run: crds sync --contexts ${{ steps.crds_context.outputs.crds_context }}
# Have actions/cache update monthly
- run: echo "today=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
id: cache-date
- uses: actions/cache@v3
with:
path: ${{ env.CRDS_PATH }}
key: crds-${{ steps.cache-date.outputs.today }}
- run: pytest -n auto --pyargs jwst.datamodels --cov-report=xml --cov=src/stdatamodels
- run: coverage report -m
- uses: codecov/codecov-action@v2
with:
file: ./coverage.xml
test_with_coverage:
name: Coverage
needs: [ style, audit ]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toxenv: [ test-xdist ]
python-version: [ '3.8', '3.9', '3.10', '3.11' ]
os: [ ubuntu-latest, macos-latest ]
include:
- toxenv: test-xdist-cov
os: ubuntu-latest
python-version: '3.11'
- toxenv: test-jwst-xdist-cov
os: ubuntu-latest
python-version: '3.11'
steps:
- if: ${{ contains(matrix.toxenv,'docs') }}
run: sudo apt-get install graphviz texlive-latex-extra dvipng
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: setup.cfg
- run: pip install -e ".[test]" pytest-xdist pytest-cov
- run: pip install "asdf @ git+https://github.com/asdf-format/asdf.git"
- run: pip freeze
- run: pytest -n auto --cov-report=xml --cov=src/stdatamodels
- run: coverage report -m
- uses: codecov/codecov-action@v2
- run: pip install "tox>=4.0"
- run: tox -e ${{ matrix.toxenv }}
- if: ${{ contains(matrix.toxenv,'-cov') }}
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
build-docs:
name: Build documentation
needs: [ style, audit ]
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install graphviz texlive-latex-extra dvipng
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'pip'
cache-dependency-path: setup.cfg
- run: pip install -e ".[docs]"
- run: sphinx-build -W docs/source build/docs
flags: unit
fail_ci_if_error: true
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Changes to API
Other
-----

- added environments in ``tox.ini`` to support Tox 4 [#108]

0.4.4 (2022-12-27)
==================

Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = stdatamodels
description = Core support for DataModel classes used in calibration pipelines
long_description = Core support for DataModel classes used in calibration pipelines
long_description_content_type = text/x-markdown
author = STScI
license = BSD-3-Clause
url = https://github.com/spacetelescope/stdatamodels
Expand Down Expand Up @@ -66,4 +67,8 @@ text_file_format = rst
addopts = --open-files
testpaths =
tests
src
norecursedirs =
build
.tox
.eggs
venv
80 changes: 80 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[tox]
envlist =
check-{style,security,build}
test{,-jwst}-xdist{,-cov}
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 src tests {posargs}

[testenv:check-security]
description = run bandit to check security compliance
skip_install = true
deps =
bandit>=1.7
commands =
bandit -r -ll src

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

[testenv]
description =
run tests
xdist: using parallel processing
cov: with coverage
pass_env =
jwst: CRDS_*
set_env =
jwst: CRDS_CLIENT_RETRY_COUNT=3
jwst: CRDS_CLIENT_RETRY_DELAY_SECONDS=20
jwst: CRDS_SERVER_URL=https://jwst-crds.stsci.edu
extras =
test
deps =
xdist: pytest-xdist
cov: pytest-cov
jwst: jwst[test] @ git+https://github.com/spacetelescope/jwst
commands_pre =
pip freeze
commands =
pytest \
xdist: -n auto \
cov: --cov=. --cov-config=setup.cfg --cov-report=term-missing --cov-report=xml \
jwst: --pyargs jwst.datamodels \
{posargs}

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

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

0 comments on commit 1e90078

Please sign in to comment.