Skip to content

Commit 323fcc9

Browse files
authored
chore: use dependency-groups (#973)
Signed-off-by: Henry Schreiner <[email protected]>
1 parent df21e44 commit 323fcc9

15 files changed

+101
-94
lines changed

.github/CONTRIBUTING.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ package is in a virtual environment. This is how you would set one up with
5757
Python's built-in venv:
5858

5959
```bash
60-
python3 -m venv .env
61-
source ./.env/bin/activate
62-
pip install -U pip
63-
pip install -ve .[all]
60+
python3 -m venv .venv
61+
source ./.venv/bin/activate
62+
pip install dependency-groups
63+
pip-install-dependency-groups dev
64+
pip install -ve.
6465
```
6566

6667
<details><summary>Optional: External Jupyter kernel (click to expand)</summary>
@@ -109,7 +110,8 @@ Here is the recommendation for a CMake install:
109110
```bash
110111
python3 -m venv env_cmake
111112
source ./env_cmake/bin/activate
112-
pip install -r dev-requirements.txt
113+
pip install dependency-groups
114+
pip-install-dependency-groups dev
113115
cmake -S . -B build-debug \
114116
-GNinja \
115117
-DCMAKE_INSTALL_PREFIX=$(python -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False))")
@@ -285,7 +287,8 @@ This requires LLVM 9+, and is based on [this post](https://aras-p.info/blog/2019
285287
brew install llvm # macOS way to get clang-9
286288
python3 -m venv .env_core # general environment (no install will be made)
287289
. .env_core/bin/activate
288-
pip install -r dev-requirements.txt
290+
pip install dependency-groups
291+
pip-install-dependency-groups dev
289292
CXX="/usr/local/opt/llvm/bin/clang++" cmake -S . -B build-llvm \
290293
-DCMAKE_CXX_FLAGS="-ftime-trace" \
291294
-DPYTHON_EXECUTABLE=$(which python)

.github/workflows/examples.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
paths:
77
- "examples/*.py"
88
- "notebooks/*.ipynb"
9+
- ".github/workflows/examples.yml"
910
push:
1011
branches:
1112
- master
@@ -21,13 +22,10 @@ jobs:
2122
- uses: actions/setup-python@v5
2223
with:
2324
python-version: "3.9"
24-
- name: Pre-install NumPy
25-
run: python -m pip install -r dev-requirements.txt nbconvert ipykernel
26-
- name: Install kernel
27-
run: python -m ipykernel install --user --name boost-hist
28-
- name: Build
29-
run: python -m pip install .[examples]
25+
- uses: astral-sh/setup-uv@v4
26+
- name: Build and install kernel
27+
run: uv run --group examples -m ipykernel install --user --name boost-hist
3028
- name: Examples
31-
run: for f in examples/*.py; do python "$f"; done
29+
run: for f in examples/*.py; do uv run "$f"; done
3230
- name: Notebooks
33-
run: jupyter nbconvert --execute --ExecutePreprocessor.timeout=90 --inplace notebooks/*.ipynb
31+
run: uv run jupyter nbconvert --execute --ExecutePreprocessor.timeout=90 --inplace notebooks/*.ipynb

.github/workflows/tests.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,18 @@ jobs:
7878

7979
- uses: rui314/setup-mold@v1
8080

81-
- uses: yezz123/setup-uv@v4
81+
- uses: astral-sh/setup-uv@v4
8282

8383
- uses: hendrikmuhs/[email protected]
8484
with:
8585
key: ${{ matrix.python-version }}
8686
create-symlink: true
8787

88+
- name: Make requirements.txt
89+
run: |
90+
uv pip install --system dependency-groups
91+
dependency-groups dev > dev-requirements.txt
92+
8893
- name: Install python tools
8994
run: uv pip install --system -r dev-requirements.txt pytest-github-actions-annotate-failures
9095
env:

.github/workflows/weekly.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ jobs:
2121

2222
- uses: actions/setup-python@v5
2323
with:
24-
python-version: "3.11"
24+
python-version: "3.12"
2525

2626
- name: Build and install wheel
27-
run: pip install -v .[test]
27+
run: |
28+
pip install dependency-groups
29+
pip-install-dependency-groups test
30+
pip install -v .
2831
2932
- name: Test
3033
run: python -m pytest

.pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ repos:
2121
- id: debug-statements
2222
- id: end-of-file-fixer
2323
- id: mixed-line-ending
24-
- id: requirements-txt-fixer
2524
- id: trailing-whitespace
2625

2726
- repo: https://github.com/cheshirekow/cmake-format-precommit
@@ -54,7 +53,7 @@ repos:
5453
rev: v2.3.0
5554
hooks:
5655
- id: codespell
57-
args: ["-L", "hist,nd,circularly,ba", "-w"]
56+
args: ["-L", "hist,nd,circularly,ba,fo", "-w"]
5857
exclude: ^(notebooks/xarray.ipynb|notebooks/BoostHistogramHandsOn.ipynb|.*\.svg)$
5958

6059
- repo: local

.readthedocs.yml

+7-13
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@
66
version: 2
77

88
build:
9-
os: ubuntu-22.04
9+
os: "ubuntu-22.04"
1010
tools:
11-
python: "3"
12-
13-
# Build documentation in the docs/ directory with Sphinx
14-
sphinx:
15-
configuration: docs/conf.py
16-
17-
# Include PDF and ePub
18-
formats: all
19-
20-
python:
21-
install:
22-
- requirements: docs/requirements.txt
11+
python: "3.12"
12+
commands:
13+
- asdf plugin add uv
14+
- asdf install uv latest
15+
- asdf global uv latest
16+
- uv run --only-group docs sphinx-build -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html
2317

2418
submodules:
2519
exclude: all

dev-requirements.txt

-7
This file was deleted.

docs/conf.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# documentation root, use os.path.abspath to make it absolute, like shown here.
99
#
1010
import contextlib
11+
import importlib.metadata
1112
import shutil
1213
import sys
1314
from pathlib import Path
@@ -31,11 +32,8 @@
3132
copyright = "2020, Henry Schreiner, Hans Dembinski"
3233
author = "Henry Schreiner, Hans Dembinski"
3334

34-
# It is better to use pkg_resources, but we can't build on RtD
35-
from pkg_resources import DistributionNotFound, get_distribution
36-
37-
with contextlib.suppress(DistributionNotFound):
38-
version = get_distribution("boost_histogram").version
35+
with contextlib.suppress(ModuleNotFoundError):
36+
version = importlib.metadata.version("boost_histogram")
3937
# passed if no version (latest/git hash)
4038

4139

docs/requirements.txt

-7
This file was deleted.

notebooks/PerformanceComparison.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394
"name": "python",
395395
"nbconvert_exporter": "python",
396396
"pygments_lexer": "ipython3",
397-
"version": "3.7.6"
397+
"version": "3.12.8"
398398
}
399399
},
400400
"nbformat": 4,

notebooks/SimpleExample.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"name": "python",
138138
"nbconvert_exporter": "python",
139139
"pygments_lexer": "ipython3",
140-
"version": "3.7.6"
140+
"version": "3.12.8"
141141
}
142142
},
143143
"nbformat": 4,

notebooks/ThreadedFills.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
"name": "python",
199199
"nbconvert_exporter": "python",
200200
"pygments_lexer": "ipython3",
201-
"version": "3.7.6"
201+
"version": "3.12.8"
202202
}
203203
},
204204
"nbformat": 4,

notebooks/aghast.ipynb

+17-11
Large diffs are not rendered by default.

noxfile.py

+26-13
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,55 @@
22

33
import argparse
44
from pathlib import Path
5+
from typing import Any
56

67
import nox
78

8-
nox.needs_version = ">=2024.3.2"
9+
nox.needs_version = ">=2024.4.15"
910
nox.options.default_venv_backend = "uv|virtualenv"
10-
nox.options.sessions = ["lint", "tests"]
1111

1212

13-
@nox.session
13+
def _get_group(name: str, groups: dict[str, Any]) -> list[str]:
14+
group = groups[name]
15+
return [d if isinstance(d, str) else _get_group(d, groups) for d in group]
16+
17+
18+
def dependency_groups(pyproject: dict[str, Any], *names: str) -> list[str]:
19+
groups = pyproject["dependency-groups"]
20+
return [item for name in names for item in _get_group(name, groups)]
21+
22+
1423
def tests(session: nox.Session) -> None:
1524
"""
1625
Run the unit and regular tests.
1726
"""
18-
19-
session.install(".[test]")
27+
pyproject = nox.project.load_toml("pyproject.toml")
28+
session.install(".", *dependency_groups(pyproject, "test"))
2029
session.run("pytest", *session.posargs)
2130

2231

23-
@nox.session
32+
@nox.session(default=False)
2433
def hist(session: nox.Session) -> None:
2534
"""
2635
Run Hist's test suite
2736
"""
37+
pyproject = nox.project.load_toml("pyproject.toml")
2838
session.install(".")
2939
tmpdir = session.create_tmp()
3040
session.chdir(tmpdir)
3141
session.run("git", "clone", "https://github.com/scikit-hep/hist", external=True)
3242
session.chdir("hist")
33-
session.install(".[test,plot]")
43+
session.install(".", *dependency_groups(pyproject, "test", "plot"))
3444
session.run("pip", "list")
3545
session.run("pytest", *session.posargs)
3646

3747

38-
@nox.session(reuse_venv=True)
48+
@nox.session(reuse_venv=True, default=False)
3949
def docs(session: nox.Session) -> None:
4050
"""
4151
Build the docs. Pass --non-interactive to avoid serving. Pass "-b linkcheck" to check links.
4252
"""
53+
pyproject = nox.project.load_toml("pyproject.toml")
4354

4455
parser = argparse.ArgumentParser()
4556
parser.add_argument(
@@ -49,7 +60,7 @@ def docs(session: nox.Session) -> None:
4960
serve = args.builder == "html" and session.interactive
5061

5162
extra_installs = ["sphinx-autobuild"] if serve else []
52-
session.install("-r", "docs/requirements.txt", *extra_installs)
63+
session.install(*dependency_groups(pyproject, "docs"), *extra_installs)
5364

5465
shared_args = (
5566
"-n", # nitpicky mode
@@ -67,13 +78,14 @@ def docs(session: nox.Session) -> None:
6778
session.run("sphinx-build", "--keep-going", *shared_args)
6879

6980

70-
@nox.session
81+
@nox.session(default=False)
7182
def build_api_docs(session: nox.Session) -> None:
7283
"""
7384
Build (regenerate) API docs.
7485
"""
86+
pyproject = nox.project.load_toml("pyproject.toml")
7587

76-
session.install(".", "-r", "docs/requirements.txt")
88+
session.install(*dependency_groups(pyproject, "docs"))
7789
session.run(
7890
"sphinx-apidoc",
7991
"-o",
@@ -121,10 +133,11 @@ def pylint(session: nox.Session) -> None:
121133
session.run("pylint", "boost_histogram", *session.posargs)
122134

123135

124-
@nox.session
136+
@nox.session(default=False)
125137
def make_pickle(session: nox.Session) -> None:
126138
"""
127139
Make a pickle file for this version
128140
"""
129-
session.install(".[dev]")
141+
pyproject = nox.project.load_toml("pyproject.toml")
142+
session.install(".", *dependency_groups(pyproject, "dev"))
130143
session.run("python", "tests/pickles/make_pickle.py", *session.posargs)

pyproject.toml

+18-16
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,37 @@ dependencies = [
5050
"numpy",
5151
]
5252

53-
[project.optional-dependencies]
53+
[project.urls]
54+
"Bug Tracker" = "https://github.com/scikit-hep/boost-histogram/issues"
55+
Changelog = "https://boost-histogram.readthedocs.io/en/latest/CHANGELOG.html"
56+
Chat = " https://gitter.im/HSF/PyHEP-histogramming"
57+
Discussions = "https://github.com/scikit-hep/boost-histogram/discussions"
58+
Documentation = "https://boost-histogram.readthedocs.io/"
59+
Homepage = "https://github.com/scikit-hep/boost-histogram"
60+
61+
[dependency-groups]
5462
dev = [
55-
"cloudpickle",
56-
"hypothesis>=6.0",
63+
{ include-group = "test" },
5764
"ipykernel",
58-
"pytest-benchmark",
59-
"pytest>=6.0",
65+
"nbconvert",
66+
"numpy",
67+
"setuptools_scm",
6068
"typer",
6169
]
6270
docs = [
71+
"ipython",
6372
"myst_parser>=0.13",
6473
"nbsphinx",
74+
"numpy",
6575
"sphinx-book-theme>=0.0.33",
66-
"Sphinx>=4.0",
76+
"sphinx>=4.0",
6777
"sphinx_copybutton",
6878
]
6979
examples = [
7080
"matplotlib",
7181
"netCDF4",
7282
"numba",
73-
"uproot3",
83+
"uproot",
7484
"xarray",
7585
"xhistogram",
7686
]
@@ -81,14 +91,6 @@ test = [
8191
"pytest>=6.0",
8292
]
8393

84-
[project.urls]
85-
"Bug Tracker" = "https://github.com/scikit-hep/boost-histogram/issues"
86-
Changelog = "https://boost-histogram.readthedocs.io/en/latest/CHANGELOG.html"
87-
Chat = " https://gitter.im/HSF/PyHEP-histogramming"
88-
Discussions = "https://github.com/scikit-hep/boost-histogram/discussions"
89-
Documentation = "https://boost-histogram.readthedocs.io/"
90-
Homepage = "https://github.com/scikit-hep/boost-histogram"
91-
9294

9395
[tool.scikit-build]
9496
minimum-version = "build-system.requires"
@@ -159,7 +161,7 @@ ignore_missing_imports = true
159161

160162
[tool.cibuildwheel]
161163
build-frontend = "build[uv]"
162-
test-extras = "test"
164+
test-groups = ["test"]
163165
test-command = "pytest --benchmark-disable {project}/tests"
164166
skip = [
165167
"pp38-*",

0 commit comments

Comments
 (0)