Skip to content

Commit 0a7f89f

Browse files
authored
General cleanup (#35)
* πŸ”§ config: reorganize dependency groups and update package versions * πŸ’„ ui: change typing_extensions.Doc for docstrings * πŸ”§ config(ci): nox and py13 * πŸ‘· build: CI pass step Signed-off-by: nstarman <nstarman@users.noreply.github.com>
1 parent 59a8cf9 commit 0a7f89f

5 files changed

Lines changed: 118 additions & 74 deletions

File tree

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ jobs:
3535
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
3636
uv run nox -s pylint
3737
38-
checks:
38+
tests:
3939
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
4040
runs-on: ${{ matrix.runs-on }}
4141
needs: [pre-commit]
4242
strategy:
4343
fail-fast: false
4444
matrix:
45-
python-version: ["3.10", "3.12"]
45+
python-version: ["3.10", "3.13"]
4646
runs-on: [ubuntu-latest, macos-latest, windows-latest]
4747

4848
steps:
@@ -61,3 +61,14 @@ jobs:
6161
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
6262
with:
6363
token: ${{ secrets.CODECOV_TOKEN }}
64+
65+
status:
66+
name: CI Pass
67+
runs-on: ubuntu-latest
68+
needs: [pre-commit, tests]
69+
if: always()
70+
steps:
71+
- name: All required jobs passed
72+
uses: re-actors/alls-green@release/v1
73+
with:
74+
jobs: ${{ toJSON(needs) }}

β€Žnoxfile.pyβ€Ž

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,96 @@
99

1010
nox.needs_version = ">=2024.3.2"
1111
nox.options.sessions = [
12-
"tests",
1312
# Linting
1413
"lint",
1514
"pylint",
15+
"precommit",
1616
# Testing
17-
"test",
17+
"tests",
1818
# Packaging
1919
"build",
2020
]
21-
nox.options.default_venv_backend = "uv|virtualenv"
22-
23-
24-
@nox.session
25-
def check(session: nox.Session, /) -> None:
26-
"""Run all checks."""
27-
lint(session)
28-
test(session)
21+
nox.options.default_venv_backend = "uv"
2922

3023

3124
# =============================================================================
25+
# Linting
3226

3327

34-
@nox.session
28+
@nox.session(venv_backend="uv")
3529
def lint(session: nox.Session, /) -> None:
3630
"""Run the linter."""
37-
precommit(session)
38-
pylint(session)
31+
precommit(session) # reuse pre-commit session
32+
pylint(session) # reuse pylint session
3933

4034

41-
@nox.session
35+
@nox.session(venv_backend="uv")
4236
def precommit(session: nox.Session, /) -> None:
43-
"""Run the pre-commit hooks."""
44-
session.run(
37+
"""Run pre-commit."""
38+
session.run_install(
4539
"uv",
46-
"run",
47-
"pre-commit",
48-
"run",
49-
"--all-files",
50-
"--show-diff-on-failure",
51-
*session.posargs,
40+
"sync",
41+
"--group=lint",
42+
f"--python={session.virtualenv.location}",
43+
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
5244
)
45+
session.run("pre-commit", "run", "--all-files", *session.posargs)
5346

5447

55-
@nox.session
48+
@nox.session(venv_backend="uv")
5649
def pylint(session: nox.Session, /) -> None:
5750
"""Run PyLint."""
58-
# This needs to be installed into the package environment, and is slower
59-
# than a pre-commit check
60-
session.run("uv", "sync", "--group", "pylint")
61-
session.run("uv", "run", "pylint", "xmmutablemap", *session.posargs)
51+
session.run_install(
52+
"uv",
53+
"sync",
54+
"--group=lint",
55+
f"--python={session.virtualenv.location}",
56+
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
57+
)
58+
session.run("pylint", "xmmutablemap", *session.posargs)
6259

6360

6461
# =============================================================================
6562
# Testing
6663

6764

68-
@nox.session
69-
def test(session: nox.Session, /) -> None:
70-
"""Run the tests."""
71-
session.run("uv", "sync", "--group", "test")
72-
session.run("uv", "run", "pytest", *session.posargs)
65+
@nox.session(venv_backend="uv")
66+
def tests(session: nox.Session, /) -> None:
67+
"""Run the unit and regular tests."""
68+
session.run_install(
69+
"uv",
70+
"sync",
71+
"--group=test",
72+
f"--python={session.virtualenv.location}",
73+
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
74+
)
75+
session.run("pytest", *session.posargs)
7376

7477

7578
# =============================================================================
7679
# Packaging
7780

7881

79-
@nox.session
82+
@nox.session(venv_backend="uv")
8083
def rm_build(_: nox.Session, /) -> None:
8184
"""Remove the build directory."""
8285
build_path = DIR.joinpath("build")
8386
if build_path.exists():
8487
shutil.rmtree(build_path)
8588

8689

87-
@nox.session
90+
@nox.session(venv_backend="uv")
8891
def build(session: nox.Session, /) -> None:
8992
"""Build an SDist and wheel."""
90-
rm_build(session)
91-
session.run("uv", "build", *session.posargs)
93+
build_path = DIR.joinpath("build")
94+
if build_path.exists():
95+
shutil.rmtree(build_path)
96+
97+
session.run_install(
98+
"uv",
99+
"sync",
100+
"--group=build",
101+
f"--python={session.virtualenv.location}",
102+
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
103+
)
104+
session.run("build")

β€Žpyproject.tomlβ€Ž

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,34 @@ Homepage = "https://github.com/GalacticDynamics/xmmutablemap"
3636
Discussions = "https://github.com/GalacticDynamics/xmmutablemap/discussions"
3737
Changelog = "https://github.com/GalacticDynamics/xmmutablemap/releases"
3838

39+
40+
[build-system]
41+
requires = ["hatchling", "hatch-vcs"]
42+
build-backend = "hatchling.build"
43+
44+
3945
[dependency-groups]
4046
dev = [
4147
"ipykernel>=6.29.5",
4248
"cz-conventional-gitmoji>=0.6.1",
43-
"pre-commit>=4.1.0",
49+
{include-group = "lint"},
4450
{include-group = "nox"},
4551
{include-group = "test"},
4652
]
47-
pylint = [
53+
lint = [
54+
"pre-commit>=4.1.0",
4855
"pylint>=3.3.8",
4956
]
5057
nox = [
5158
"nox>=2024.10.9",
5259
]
5360
test = [
54-
"pytest>=8.3.3",
55-
"pytest-cov>=3",
61+
"pytest>=8.4.2",
62+
"pytest-cov>=6.2.1",
5663
"pytest-github-actions-annotate-failures>=0.2.0",
57-
"sybil>=8.0.0",
64+
"sybil[pytest]>=9.2.0",
5865
]
5966

60-
[build-system]
61-
requires = ["hatchling", "hatch-vcs"]
62-
build-backend = "hatchling.build"
63-
6467

6568
[tool.hatch]
6669
build.hooks.vcs.version-file = "src/xmmutablemap/_version.py"
@@ -72,7 +75,7 @@ name = "cz_gitmoji"
7275

7376

7477
[tool.pytest.ini_options]
75-
minversion = "8.3"
78+
minversion = "8"
7679
addopts = [
7780
"--showlocals",
7881
"--strict-config",

β€Žsrc/xmmutablemap/_core.pyβ€Ž

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
__all__ = ("ImmutableMap",)
77

88
from collections.abc import ItemsView, Iterable, Iterator, KeysView, Mapping, ValuesView
9-
from typing import Annotated, Any, TypeVar, overload
10-
from typing_extensions import Doc
9+
from typing import Any, TypeVar, overload
1110

1211
from jax.tree_util import register_pytree_node_class
1312

@@ -234,16 +233,17 @@ def __repr__(self) -> str:
234233
# ===========================================
235234
# JAX PyTree
236235

237-
def tree_flatten(
238-
self,
239-
) -> tuple[
240-
Annotated[tuple[V, ...], Doc("The values.")],
241-
Annotated[tuple[K, ...], Doc("The keys as auxiliary data.")],
242-
]:
236+
def tree_flatten(self) -> tuple[tuple[V, ...], tuple[K, ...]]:
243237
"""Flatten dict to the values (and keys).
244238
245239
This is used for JAX's tree flattening.
246240
241+
Returns
242+
-------
243+
tuple[tuple[V, ...], tuple[K, ...]]
244+
A tuple of (values, keys).
245+
The keys are treated as auxiliary data.
246+
247247
Examples
248248
--------
249249
>>> import jax
@@ -260,14 +260,19 @@ def tree_flatten(
260260

261261
@classmethod
262262
def tree_unflatten(
263-
cls,
264-
aux_data: Annotated[tuple[K, ...], Doc("The keys.")],
265-
children: Annotated[tuple[V, ...], Doc("The values.")],
263+
cls, aux_data: tuple[K, ...], children: tuple[V, ...]
266264
) -> "ImmutableMap[K, V]":
267265
"""Unflatten into an ImmutableMap from the keys and values.
268266
269267
This is used for JAX's tree un-flattening.
270268
269+
Parameters
270+
----------
271+
aux_data : tuple[K, ...]
272+
The keys.
273+
children : tuple[V, ...]
274+
The values.
275+
271276
Examples
272277
--------
273278
>>> import jax

β€Žuv.lockβ€Ž

Lines changed: 27 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)