Skip to content

Commit a08159e

Browse files
committed
Switch to pyproject.toml; remove setuptools dependency
Also, switch from flake8 to Ruff
1 parent ad79e23 commit a08159e

File tree

8 files changed

+111
-108
lines changed

8 files changed

+111
-108
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ concurrency:
1818

1919
jobs:
2020
build-and-test:
21-
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }} jax=${{ matrix.jax-version}}"
21+
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }} jax=${{ matrix.jax-version }}"
2222
runs-on: "${{ matrix.os }}"
2323

2424
strategy:
@@ -29,7 +29,7 @@ jobs:
2929
include:
3030
- python-version: "3.10"
3131
os: "ubuntu-latest"
32-
jax-version: "0.4.27" # Keep this in sync with version in requirements.txt
32+
jax-version: "0.4.27" # Keep this in sync with version in pyproject.toml
3333
- python-version: "3.13"
3434
os: "ubuntu-latest"
3535
jax-version: "nightly"
@@ -38,9 +38,22 @@ jobs:
3838
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3939
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
4040
with:
41-
python-version: "${{ matrix.python-version }}"
42-
cache: "pip"
43-
cache-dependency-path: '**/requirements*.txt'
41+
python-version: "${{ matrix.python-version }}"
42+
43+
- name: Compute pyproject.toml hash
44+
id: deps
45+
run: |
46+
echo "hash=$(shasum -a 256 pyproject.toml | cut -d' ' -f1)" >> $GITHUB_OUTPUT
47+
48+
- name: Cache pip based on pyproject.toml
49+
uses: actions/cache@v3
50+
with:
51+
path: ~/.cache/pip
52+
key: pip-${{ runner.os }}-${{ matrix.python-version }}-${{ steps.deps.outputs.hash }}
53+
54+
- name: Install build dependencies
55+
run: pip install .[dev,test]
56+
4457
- name: Run CI tests
4558
run: JAX_VERSION="${{ matrix.jax-version }}" bash test.sh
4659
shell: bash

MANIFEST.in

Lines changed: 0 additions & 4 deletions
This file was deleted.

pyproject.toml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "chex"
7+
dynamic = ["version"]
8+
description = "Chex: Testing made fun, in JAX!"
9+
readme = "README.md"
10+
license = "Apache-2.0"
11+
requires-python = ">=3.9"
12+
authors = [
13+
{ name = "DeepMind", email = "[email protected]" },
14+
]
15+
keywords = [
16+
"debugging",
17+
"jax",
18+
"learning",
19+
"machine",
20+
"python",
21+
"testing",
22+
]
23+
classifiers = [
24+
"Development Status :: 5 - Production/Stable",
25+
"Environment :: Console",
26+
"Intended Audience :: Developers",
27+
"Intended Audience :: Science/Research",
28+
"Operating System :: OS Independent",
29+
"Programming Language :: Python",
30+
"Programming Language :: Python :: 3",
31+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
32+
"Topic :: Software Development :: Libraries :: Python Modules",
33+
"Topic :: Software Development :: Testing :: Mocking",
34+
"Topic :: Software Development :: Testing :: Unit",
35+
]
36+
dependencies = [
37+
"absl-py>=0.9.0",
38+
"jax>=0.4.27",
39+
"jaxlib>=0.4.27",
40+
"numpy>=1.24.1",
41+
"toolz>=0.9.0",
42+
"typing_extensions>=4.2.0",
43+
]
44+
45+
[project.optional-dependencies]
46+
dev = [
47+
"ruff",
48+
"pytest-xdist",
49+
"pylint",
50+
"pylint-exit",
51+
]
52+
test = [
53+
"cloudpickle==3.1.0",
54+
"dm-tree>=0.1.9",
55+
]
56+
docs = [
57+
"sphinx>=6.0.0",
58+
"sphinx-book-theme>=1.0.1",
59+
"sphinxcontrib-katex",
60+
]
61+
62+
[project.urls]
63+
Homepage = "https://github.com/deepmind/chex"
64+
65+
[tool.hatch.version]
66+
path = "chex/__init__.py"
67+
68+
[tool.hatch.build.targets.sdist]
69+
include = [
70+
"/chex",
71+
]
72+
73+
[tool.ruff]
74+
preview = true
75+
76+
[tool.ruff.lint]
77+
select = [
78+
"E9",
79+
"F63",
80+
"F7",
81+
"F82",
82+
"E225",
83+
"E251",
84+
]

requirements/requirements-docs.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

requirements/requirements-test.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

requirements/requirements.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

test.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ source "${VENV_DIR}/bin/activate"
2727
python --version
2828

2929
# Install dependencies.
30-
pip install --upgrade pip setuptools wheel
31-
pip install flake8 pytest-xdist pylint pylint-exit
32-
pip install -r requirements/requirements.txt
33-
pip install -r requirements/requirements-test.txt
30+
pip install --upgrade pip
31+
pip install .[dev]
3432

3533
# Install the requested JAX version
3634
if [ "$JAX_VERSION" = "" ]; then
@@ -43,8 +41,8 @@ else
4341
pip install "jax==${JAX_VERSION}" "jaxlib==${JAX_VERSION}"
4442
fi
4543

46-
# Lint with flake8.
47-
flake8 `find chex -name '*.py' | xargs` --count --select=E9,F63,F7,F82,E225,E251 --show-source --statistics
44+
# Lint with Ruff.
45+
ruff check
4846

4947
# Lint with pylint.
5048
PYLINT_ARGS="-efail -wfail -cfail -rfail"
@@ -62,9 +60,10 @@ pylint --rcfile=.pylintrc `find chex -name '*_test.py' | xargs` -d W0212,E1130,E
6260
rm .pylintrc
6361

6462
# Build the package.
65-
python setup.py sdist
63+
pip install build
64+
python -m build
6665
pip wheel --verbose --no-deps --no-clean dist/chex*.tar.gz
67-
pip install chex*.whl
66+
pip install chex*.whl --force-reinstall
6867

6968
# Check types with pytype.
7069
# Note: pytype does not support 3.11 as of 25.06.23
@@ -77,7 +76,7 @@ fi;
7776

7877
# Run tests using pytest.
7978
# Change directory to avoid importing the package from repo root.
80-
pip install -r requirements/requirements-test.txt
79+
pip install .[test]
8180
cd _testing
8281

8382
# Main tests.
@@ -88,8 +87,7 @@ pytest -n "$(grep -c ^processor /proc/cpuinfo)" --pyargs chex -k "fake_set_n_cpu
8887
cd ..
8988

9089
# Build Sphinx docs.
91-
92-
pip install -r requirements/requirements-docs.txt
90+
pip install .[docs]
9391
cd docs
9492
make coverage_check
9593
make html

0 commit comments

Comments
 (0)