Skip to content

Commit

Permalink
Standardize local and CI testing to use tox (#184)
Browse files Browse the repository at this point in the history
* Standardize local and CI testing to use tox

* Use tox exclusively to manage test and build environments.

    This change standardizes make and CI invocations of the test suite.

* Merge Windows testing in with the Linux and macOS test suite.

    This means that Linux and macOS wheels are now getting built and uploaded,
    and also means that coveralls is getting Windows coverage reports.

* Support building wheels for all supported Python versions.

    This is accomplished using a tox label that expands to all supported Python versions.
    Run tox run -m build or make build to invoke this.

* Support running the test suite across all Python versions in parallel.

    This is accomplished by running tox run-parallel or simply tox p.
    Cross-environment dependencies, like generating coverage reports after all tests have run,
    are managed in the tox configuration.
  • Loading branch information
kurtmckee authored Sep 22, 2024
1 parent 306fee9 commit aa16a03
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 98 deletions.
17 changes: 16 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
[run]
source = smartcard
branch = True
parallel = True
relative_files = True
source =
smartcard
test

[paths]
source =
src
*/site-packages

[report]
skip_covered = True
fail_under = 33
exclude_lines =
pragma: no cover
if __name__ == '__main__':

[html]
directory = htmlcov/
skip_covered = False
94 changes: 63 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,69 +10,101 @@ on:

jobs:
test:
name: "${{ matrix.os.name }} (${{ matrix.cpython }})"
runs-on: "${{ matrix.os.runner }}"
name: "${{ matrix.name }} / ${{ matrix.cpython }}"
runs-on: "${{ matrix.runner }}"
defaults:
run:
shell: "bash"

strategy:
fail-fast: false
matrix:
os:
- name: "Linux"
runner: "ubuntu-latest"
- name: "macOS"
runner: "macos-latest"
name:
- "Linux"
- "macOS"
- "Windows (x64)"
- "Windows (x86)"
cpython:
- "3.9"
- "3.10"
- "3.11"
- "3.12"

include:
# Augment the matrix with additional values.
# The values match on "name".
- name: "Linux"
runner: "ubuntu-latest"
architecture: "x64"

- name: "macOS"
runner: "macos-latest"
architecture: "arm64"

- name: "Windows (x64)"
runner: "windows-latest"
architecture: "x64"

- name: "Windows (x86)"
runner: "windows-latest"
architecture: "x86"

steps:
- uses: actions/checkout@v4
- name: "Checkout the repository"
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.cpython }}
- name: "Set up Python ${{ matrix.cpython }}"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.cpython }}
python-version: "${{ matrix.cpython }}"
architecture: "${{ matrix.architecture }}"

- name: setup prerequisites (Linux)
if: matrix.os.name == 'Linux'
- name: "Install build prerequisites (Linux)"
if: matrix.name == 'Linux'
run: |
sudo apt install libpcsclite-dev python3-all-dev python3-setuptools swig
- name: setup prerequisites (macOS)
if: matrix.os.name == 'macOS'
- name: "Install build prerequisites (macOS)"
if: matrix.name == 'macOS'
run: |
brew install swig pylint
- name: build
- name: "Install build prerequisites (Windows)"
if: startsWith(matrix.name, 'Windows')
run: |
choco upgrade swig --allow-empty-checksums --yes --limit-output
swig -version
- name: "Determine virtual environment bin path"
shell: "bash"
run: |
python3 -m venv temp
source temp/bin/activate
pip install -r dev-requirements.txt
make
echo 'venv-path=temp/${{ runner.os == 'Windows' && 'Scripts' || 'bin' }}' >> "$GITHUB_ENV"
- name: test run
- name: "Create a virtual environment"
run: |
source temp/bin/activate
make test
python -m venv temp
${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel
${{ env.venv-path }}/pip install tox
- name: coverage
- name: "Test"
run: |
source temp/bin/activate
python3 -m coverage erase
python3 -m coverage run -m pytest
python3 -m coverage report
python3 -m coverage xml
${{ env.venv-path }}/tox -e py${{ matrix.cpython }},coverage_report-ci
- name: Coveralls
- name: "Coveralls"
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: pylint
- name: "Build"
run: |
${{ env.venv-path }}/tox -e build
- name: "Upload wheel"
uses: actions/upload-artifact@v4
with:
name: wheel-${{ matrix.name }}-${{ matrix.cpython }}-${{ matrix.architecture }}
path: dist/*.whl

- name: "Lint"
run: |
pylint --errors-only smartcard || true
${{ env.venv-path }}/tox -e pylint
47 changes: 0 additions & 47 deletions .github/workflows/windows.yml

This file was deleted.

2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Unreleased changes
* Migrate a `src/` layout.
* Support only Python 3.9 and higher
* Migrate CI to use the official Coveralls action
* Standardize local and CI testing to use tox
* Build wheels in CI for all supported Python versions

2.1.1 (September 2024)
======================
Expand Down
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PYTHON ?= python3
COVERAGE ?= coverage
TOX ?= tox

build:
$(PYTHON) -m build
$(TOX) run -m build

install: clean
$(PYTHON) -m pip install --editable .
Expand All @@ -21,17 +21,15 @@ pypi: clean
# files generated by pydoctor
rm -rf src/smartcard/doc/html
rm -rf dist
$(PYTHON) -m build
# Use the tox 'build' label to generate wheels for all Python versions.
$(TOX) run -m build
python3 -m twine upload dist/*

test: install
pytest
test:
$(TOX) run -e py

coverage:
$(COVERAGE) erase
$(COVERAGE) run -m unittest discover
$(COVERAGE) report
$(COVERAGE) html
$(TOX) run

ChangeLog.git:
git log --stat --decorate=short > $@
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ wheel
build
setuptools
pytest
tox
58 changes: 48 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
# The following list of Python versions appears in several places in this file.
#
# {3.9, 3.10, 3.11, 3.12}
#
# This affects parallel test suite execution and wheels that get built,
# so use search-and-replace to update this list in all locations.
# Manual editing may lead to mistakes.

[tox]
envlist =
pylint
py3.9
py3.10
py3.11
py3.12
coverage_erase
py{3.9, 3.10, 3.11, 3.12}
coverage_report
skip_missing_interpreters = True
labels =
build=build-py{3.9, 3.10, 3.11, 3.12}

[testenv:coverage_erase]
description = Erase existing coverage reports
skip_install = True
deps =
coverage
commands =
- coverage erase

[testenv]
depends =
py{3.9, 3.10, 3.11, 3.12}: coverage_erase
deps =
-r{toxinidir}/dev-requirements.txt
commands =
coverage erase
coverage run -m unittest discover
coverage report
coverage html
coverage run -m pytest

[testenv:pylint]
base_python = py3.12
[testenv:coverage_report{,-ci}]
depends = py{3.9, 3.10, 3.11, 3.12}
description =
!ci: Generate HTML and console reports
ci: Generate an XML report
deps =
coverage
commands_pre =
- coverage combine
commands =
# Locally, generate an HTML and a console report
!ci: - coverage html
!ci: coverage report
# In CI, simply generate an XML report
ci: - coverage xml

[testenv:build,build-py{3.9, 3.10, 3.11, 3.12}]
description = Build sdist and wheel files
skip_install = True
deps =
build
commands =
python -m build

[testenv:pylint]
deps =
pylint
commands =
Expand Down

0 comments on commit aa16a03

Please sign in to comment.