From 1e900784109e402a386150e49b98dbb0821fb365 Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Thu, 12 Jan 2023 07:59:30 -0500 Subject: [PATCH] refactor CI and use `tox.ini` with Tox 4 and PEP517 build (#108) * 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 --- .github/workflows/ci.yml | 127 ++++++++++----------------------------- CHANGES.rst | 2 + setup.cfg | 7 ++- tox.ini | 80 ++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 95 deletions(-) create mode 100644 tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6c3cd73..ae2a0ff0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CHANGES.rst b/CHANGES.rst index 584daa61..e803afb3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,6 +14,8 @@ Changes to API Other ----- +- added environments in ``tox.ini`` to support Tox 4 [#108] + 0.4.4 (2022-12-27) ================== diff --git a/setup.cfg b/setup.cfg index e95b7197..7e59f6ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -66,4 +67,8 @@ text_file_format = rst addopts = --open-files testpaths = tests - src +norecursedirs = + build + .tox + .eggs + venv diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..3e90c76e --- /dev/null +++ b/tox.ini @@ -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 .