Skip to content

Commit

Permalink
Introduce tox
Browse files Browse the repository at this point in the history
Although I was initially reluctant to use tox, two recent things have
convinced me to give it a try: firstly, I've seen now a few projects
using them to great effect; and secondly, the ability to use the tox-uv
plug-in means that it's very easy to run tests across multiple versions
of python without needing them pre-installed in the host machine.

This first version of tox declares the default environment command to be
running the unit tests, and the default list of environments to run to
be all python versions crc32c supports. It additionally declares an
environment to run the benchmarks on, and another to run the linting
checks, both of which rely on declaring the dependencies in the
pyproject.toml file itself (removing the need to maintain a separate
requirements-dev.txt file).

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Dec 17, 2024
1 parent 7f4e12e commit c01a20b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 50 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ jobs:
with:
python-version: '3.13'

- name: Install setuptools
run: pip install setuptools

- name: Install crc32c
run: python setup.py develop
- name: Install tox-uv
run: pip install tox-uv

- name: Benchmark with 1 [GB] 10 times
env:
CRC32C_SW_MODE: ${{ matrix.sw_mode }}
run: python -m crc32c.benchmark -i 10 -s 1073741824
run: tox -e benchmark -- -i 10 -s 1073741824
26 changes: 0 additions & 26 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,6 @@ jobs:
name: source-dist
path: dist/*.tar.gz

test_sdist:
name: Check source distribution is usable
needs: [build_sdist]
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.13"

- uses: actions/download-artifact@v4
with:
name: source-dist

- name: Extract source distribution
run: tar xvf crc32c*.tar.gz && rm crc32c*.tar.gz

- name: Install source distribution
run: pip install ./crc32c*

- name: Install test dependencies
run: pip install pytest

- name: Run source distribution tests
run: cd crc32c* && python run-tests.py

merge_artifacts:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
Expand Down
16 changes: 4 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@ jobs:
architecture: x64
- name: Checkout
uses: actions/checkout@v3
- name: Install build
run: pip install build
- name: Install dev requirements
run: pip install -r requirements-dev.txt
- name: Build and install package
run: python -m build -w && pip install dist/crc32c*.whl
- name: Run mypy
run: mypy --strict src test
- name: Run black
run: black --check .
- name: Run isort
run: isort --profile black --check --diff .
- name: Install tox-uv
run: pip install tox-uv
- name: Run linting steps
run: tox -e lint
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
This includes its build system (setuptools),
moving most static content from `setup.py` to `pyproject.toml`,
and moving the `pytest` configuration out from `pytest.ini` too.
* Introduced `tox` as a job runner for development avtivities,
good to use with `tox-uv` for easy multi-python testing.

## [2.7.1]

Expand Down
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,54 @@ urls.github = "https://github.com/ICRAR/crc32c"
urls.changelog = "https://github.com/ICRAR/crc32c/blob/master/CHANGELOG.md"
urls.issues = "https://github.com/ICRAR/crc32c/issues"

[dependency-groups]
test = [
"pytest",
]
lint = [
"black",
"isort",
"mypy",
]

[tool.pytest.ini_options]
markers = [
"calculates_crc32c: Mark a test as needing crc32c working"
]

[tool.tox]
requires = ["tox>=4.23"]
env_list = [
"py3.8",
"py3.9",
"py3.10",
"py3.11",
"py3.12",
"py3.13",
]

[tool.tox.env_run_base]
description = "Run test under {base_python}"
labels = ["test"]
commands = [["{env_python}", "-u", "run-tests.py"]]
dependency_groups = ["test"]
passenv = ["CRC32C_SW_MODE"]

[tool.tox.env.benchmark]
description = "Run basic benckmark"
labels = ["benchmark"]
commands = [["{env_python}", "-m", "crc32c.benchmark", { replace = "posargs", extend = true }]]
passenv = ["CRC32C_SW_MODE"]
parallel_show_output = true

[tool.tox.env.lint]
description = "Run linting checks"
labels = ["lint"]
commands = [
["mypy", "--strict", "src", "test"],
["black", "--check", "src", "test"],
["isort", "--profile", "black", "--check", "--diff", "src", "test"],
]
dependency_groups = ["lint", "test"]
package = "skip"
changedir = "{toxinidir}"
6 changes: 0 additions & 6 deletions requirements-dev.txt

This file was deleted.

0 comments on commit c01a20b

Please sign in to comment.