Skip to content

Commit f5c490f

Browse files
authored
chore: Migrate to dependency groups (#304)
* chore: Migrate to dependency groups Also refine the mypy checking configuration and fix a few typing issues * bump ci python setup * copilot LIED * Bump cibuildwheel to 3.3 We need CPython 3.14.0 final because of stdlib bug that triggers pydantic issue pydantic/pydantic#12527 Available in v3.2.1 but might as well go up one more * Add dependencies for tutorial notebook
1 parent a071b78 commit f5c490f

9 files changed

Lines changed: 124 additions & 90 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ jobs:
4343
fetch-depth: 0
4444
fetch-tags: true
4545

46-
- uses: actions/setup-python@v3
46+
- uses: actions/setup-python@v6
4747
with:
4848
python-version: ${{ matrix.python-version }}
4949

5050
- name: Install package
51-
run: python -m pip install .[test]
51+
run: python -m pip install . --group test
5252

5353
- name: Test package
5454
run: python -m pytest -ra
@@ -77,7 +77,7 @@ jobs:
7777
7878
- name: Install package
7979
shell: bash -l {0}
80-
run: python -m pip install .[test]
80+
run: python -m pip install . --group test
8181

8282
- name: Test package
8383
shell: bash -l {0}

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919

2020
- uses: actions/setup-python@v2
2121
with:
22-
python-version: 3.9
22+
python-version: 3.12
2323

2424
- name: Install pandoc
2525
uses: r-lib/actions/setup-pandoc@v2
2626

2727
- name: Install package
28-
run: python -m pip install .[docs]
28+
run: python -m pip install . --group docs
2929

3030
- name: Build documentation
3131
run: |

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
fetch-tags: true
4949
fetch-depth: 0
5050

51-
- uses: pypa/cibuildwheel@v3.1
51+
- uses: pypa/cibuildwheel@v3.3
5252
env:
5353
CIBW_ARCHS: ${{ matrix.arch }}
5454
MACOSX_DEPLOYMENT_TARGET: 11.0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@ _skbuild
145145
src/correctionlib/cmake
146146
src/correctionlib/include
147147
include/correctionlib_version.h
148+
149+
.vscode

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ repos:
4040
rev: v1.17.1
4141
hooks:
4242
- id: mypy
43-
files: src
44-
additional_dependencies: [types-setuptools, uhi, pydantic, numpy]
43+
pass_filenames: false # to allow mypy to respect pyproject.toml config
44+
additional_dependencies: [uhi, pydantic, numpy]

CONTRIBUTING.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ You can set up a development environment by running:
1313
```bash
1414
python3 -m venv .env
1515
source .env/bin/activate
16-
pip install -e .[dev,test]
16+
pip install -e . --group dev
1717
```
1818

19+
Alternatively, you can use `uv`:
20+
21+
```bash
22+
uv sync --no-editable
23+
source .venv/bin/activate
24+
```
25+
26+
The `--no-editable` flag is needed to avoid installing the package in editable mode,
27+
as the paths to the library and include files are not correctly set up for editable installs,
28+
preventing C++ compilation.
29+
1930
# Post setup
2031

2132
You should prepare pre-commit, which will help you by checking that commits

binder/correctionlib_tutorial.ipynb

Lines changed: 63 additions & 62 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,22 @@ dependencies = [
4444
]
4545

4646
[project.optional-dependencies]
47+
convert = [
48+
"pandas",
49+
"uproot >=4.0.4",
50+
"requests",
51+
"scipy",
52+
]
53+
54+
[dependency-groups]
4755
test = [
48-
"pytest >=4.6",
56+
"pandas",
57+
"uproot >=4.0.4",
58+
"requests",
4959
"scipy",
60+
"pytest >=4.6",
5061
"awkward >=2.2.2",
5162
"dask-awkward >=2024.1.1",
52-
"dask <2025.4.0",
53-
]
54-
dev = [
55-
"pytest >=4.6",
56-
"pre-commit",
57-
"mypy",
58-
"uhi",
59-
"awkward >=2",
60-
"dask-awkward",
6163
]
6264
docs = [
6365
"recommonmark >=0.5.0",
@@ -67,16 +69,31 @@ docs = [
6769
"sphinx-jsonschema",
6870
"myst-parser",
6971
"nbsphinx",
72+
# to match binder/requirements.txt
73+
"awkward",
74+
"hist[plot]",
75+
"matplotlib",
76+
"ipykernel",
7077
]
71-
convert = [
72-
"pandas",
73-
"uproot >=4.0.4",
74-
"requests",
75-
"scipy",
78+
dev = [
79+
{include-group = "test"},
80+
{include-group = "docs"},
81+
"pre-commit",
82+
"mypy",
83+
"uhi",
7684
]
7785

7886
[tool.mypy]
7987
python_version = "3.9"
88+
files = ["src"]
89+
90+
[[tool.mypy.overrides]]
91+
module = ["awkward.*", "uproot.*"]
92+
follow_untyped_imports = true
93+
94+
[[tool.mypy.overrides]]
95+
module = ["cppyy.*", "scipy.*"]
96+
ignore_missing_imports = true
8097

8198
[project.scripts]
8299
correction = "correctionlib.cli:main"
@@ -96,8 +113,8 @@ BUILD_DEMO = "OFF"
96113
write_to = "src/correctionlib/version.py"
97114

98115
[tool.cibuildwheel]
99-
skip = ["pp*-*", "cp313t-*", "cp314t-*"]
100-
test-extras = "test"
116+
skip = ["cp314t-*"]
117+
test-groups = ["test"]
101118
test-command = "python -m pytest {package}/tests"
102119
test-skip = ["*-musllinux_*", "cp3{10,11,12}-win32"]
103120

src/correctionlib/highlevel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import json
44
from collections.abc import Iterator, Mapping
55
from numbers import Integral
6-
from typing import Any, Callable, Union
6+
from typing import TYPE_CHECKING, Any, Callable, Union
77

88
import numpy
99
from packaging import version
1010

1111
import correctionlib._core
1212
import correctionlib.version
1313

14+
if TYPE_CHECKING:
15+
import awkward
16+
1417
_min_version_ak = version.parse("2.0.0")
1518
_min_version_dak = version.parse("2024.1.1")
1619

@@ -98,7 +101,7 @@ def _call_as_numpy(
98101

99102
def _wrap_awkward(
100103
func: Callable[..., Any],
101-
*args: Union["numpy.ndarray[Any, Any]", str, int, float],
104+
*args: Union["awkward.Array", "numpy.ndarray[Any, Any]", str, int, float],
102105
) -> Any:
103106
from functools import partial
104107

0 commit comments

Comments
 (0)