From c01a20b4d4b0bcc9043e13ed7b4edda73d12453c Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Mon, 16 Dec 2024 13:54:32 +0800 Subject: [PATCH] Introduce tox 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 --- .github/workflows/benchmark.yml | 9 ++--- .github/workflows/build_and_release.yml | 26 -------------- .github/workflows/lint.yml | 16 +++------ CHANGELOG.md | 2 ++ pyproject.toml | 46 +++++++++++++++++++++++++ requirements-dev.txt | 6 ---- 6 files changed, 55 insertions(+), 50 deletions(-) delete mode 100644 requirements-dev.txt diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 6ffa618..3610632 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -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 diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index 3bd2ee8..41c1ccd 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ea85171..22064b4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a86ac..230c2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] diff --git a/pyproject.toml b/pyproject.toml index 8d0518e..8cf13d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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}" diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index c2216e6..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,6 +0,0 @@ -# Keep alphasorted -black -isort -mypy -pytest -wheel