Skip to content

Commit 198ec95

Browse files
committed
refactor: migrate setup configuration to pyproject.toml
Moved all package metadata and dependencies from setup.cfg and setup.py to pyproject.toml for a more modern and standardized project setup. Updated pre-commit hooks and made minor corrections in the code to align with the new configurations.
1 parent 53d23b5 commit 198ec95

File tree

5 files changed

+133
-149
lines changed

5 files changed

+133
-149
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ repos:
2020
- id: debug-statements
2121
- id: end-of-file-fixer
2222
- repo: https://github.com/mgedmin/check-manifest
23-
rev: "0.49"
23+
rev: "0.50"
2424
hooks:
2525
- id: check-manifest
26-
args: [ --update, --no-build-isolation ]
27-
additional_dependencies: [ setuptools-scm, setuptools-scm-git-archive ]
26+
args: [ --update ]
2827
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.11.2
28+
rev: v1.12.0
3029
hooks:
3130
- id: mypy
3231
files: src
@@ -46,13 +45,13 @@ repos:
4645
- id: rst-directive-colons
4746

4847
- repo: https://github.com/asottile/pyupgrade
49-
rev: v3.17.0
48+
rev: v3.18.0
5049
hooks:
5150
- id: pyupgrade
5251
args: [ --py38-plus ]
5352

5453
- repo: https://github.com/asottile/setup-cfg-fmt
55-
rev: v2.5.0
54+
rev: v2.7.0
5655
hooks:
5756
- id: setup-cfg-fmt
5857
args: [ --max-py-version=3.12, --include-version-classifiers ]
@@ -64,7 +63,7 @@ repos:
6463

6564
- id: nbqa-pyupgrade
6665
additional_dependencies: [ pyupgrade ]
67-
args: [ --py38-plus ]
66+
args: [ --py39-plus ]
6867

6968

7069
- repo: https://github.com/roy-ht/pre-commit-jupyter
@@ -85,7 +84,7 @@ repos:
8584
- id: rm-unneeded-f-str
8685

8786
- repo: https://github.com/python-jsonschema/check-jsonschema
88-
rev: 0.29.3
87+
rev: 0.29.4
8988
hooks:
9089
- id: check-github-workflows
9190
- id: check-github-actions
@@ -102,7 +101,7 @@ repos:
102101
hooks:
103102
- id: ruff
104103
types_or: [ python, pyi, jupyter ]
105-
args: [ --fix, --unsafe-fixes, --show-fixes , --line-length=120]
104+
args: [ --fix, --unsafe-fixes, --show-fixes , --line-length=120 ]
106105
# Run the formatter.
107106
- id: ruff-format
108107
types_or: [ python, pyi, jupyter ]

pyproject.toml

Lines changed: 123 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,97 @@
11
[build-system]
2-
requires = [
3-
"setuptools>=42",
4-
"setuptools_scm[toml]>=3.4"
2+
requires = ["hatchling", "hatch-vcs"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "hepstats"
7+
description = "statistics tools and utilities"
8+
authors = [{ name = "Matthieu Marinangeli", email = "[email protected]" }]
9+
maintainers = [{ name = "Scikit-HEP", email = "[email protected]" }]
10+
license = { text = "BSD 3-Clause License" }
11+
classifiers = [
12+
"Development Status :: 4 - Beta",
13+
"Intended Audience :: Developers",
14+
"Intended Audience :: Information Technology",
15+
"Intended Audience :: Science/Research",
16+
"License :: OSI Approved :: BSD License",
17+
"Operating System :: MacOS",
18+
"Operating System :: Microsoft :: Windows",
19+
"Operating System :: POSIX",
20+
"Operating System :: Unix",
21+
"Programming Language :: C++",
22+
"Programming Language :: Python",
23+
"Programming Language :: Python :: 3",
24+
"Programming Language :: Python :: 3 :: Only",
25+
"Programming Language :: Python :: 3.9",
26+
"Programming Language :: Python :: 3.10",
27+
"Programming Language :: Python :: 3.11",
28+
"Programming Language :: Python :: 3.12",
29+
"Topic :: Scientific/Engineering",
30+
"Topic :: Scientific/Engineering :: Information Analysis",
31+
"Topic :: Scientific/Engineering :: Mathematics",
32+
"Topic :: Scientific/Engineering :: Physics",
33+
"Topic :: Software Development",
34+
"Topic :: Utilities",
35+
]
36+
urls = { Homepage = "https://github.com/scikit-hep/hepstats" }
37+
requires-python = ">=3.9"
38+
dependencies = [
39+
"asdf",
40+
"numpy",
41+
"pandas",
42+
"scipy",
43+
"tqdm",
44+
"uhi",
45+
]
46+
dynamic = ["version"]
47+
48+
[project.readme]
49+
file = "README.md"
50+
content-type = "text/markdown"
51+
52+
[project.optional-dependencies]
53+
dev = [
54+
"hepstats[docs]",
55+
"hepstats[test]",
56+
"pre-commit",
57+
]
58+
docs = [
59+
"matplotlib",
60+
"pydata-sphinx-theme",
61+
"sphinx>=3.1.2",
62+
"sphinx-autodoc-typehints",
63+
"sphinx-copybutton",
64+
"sphinxcontrib-bibtex>=2.0.0",
565
]
66+
doc = ["hepstats[docs]"] # alias
67+
test = [
68+
"pytest",
69+
"pytest-cov",
70+
"pytest-runner",
71+
"zfit>=0.20.0",
72+
]
73+
zfit = ["zfit>=0.20.0"]
74+
75+
76+
77+
[tool.pytest.ini_options]
78+
junit_family = "xunit2"
79+
testpaths = ["tests"]
80+
81+
[tool.check-manifest]
82+
ignore = ["src/hepstats/_version.py"]
83+
84+
[tool.build_sphinx]
85+
project = "hepstats"
86+
source-dir = "docs"
87+
build-dir = "docs/_build"
88+
all-files = "1"
89+
warning-is-error = "0"
690

7-
build-backend = "setuptools.build_meta"
891

9-
[tool.setuptools_scm]
10-
write_to = "src/hepstats/version.py"
92+
[tool.hatch]
93+
version.source = "vcs"
94+
build.hooks.vcs.version-file = "src/hepstats/_version.py"
1195

1296
[tool.ruff]
1397
#src = ["src"]
@@ -20,41 +104,42 @@ exclude = [
20104
]
21105
[tool.ruff.lint]
22106
extend-select = [
23-
"B", # flake8-bugbear
24-
"I", # isort
25-
"ARG", # flake8-unused-arguments
26-
"C4", # flake8-comprehensions
27-
"EM", # flake8-errmsg
28-
"ICN", # flake8-import-conventions
29-
"G", # flake8-logging-format
30-
"PGH", # pygrep-hooks
31-
"PIE", # flake8-pie
32-
"PL", # pylint
33-
"PT", # flake8-pytest-style
34-
"PTH", # flake8-use-pathlib
35-
"RET", # flake8-return
36-
"RUF", # Ruff-specific
37-
"SIM", # flake8-simplify
38-
"T20", # flake8-print
39-
"UP", # pyupgrade
40-
"YTT", # flake8-2020
41-
"EXE", # flake8-executable
42-
"NPY", # NumPy specific rules
43-
"PD", # pandas-vet
107+
"B", # flake8-bugbear
108+
"I", # isort
109+
"ARG", # flake8-unused-arguments
110+
"C4", # flake8-comprehensions
111+
"EM", # flake8-errmsg
112+
"ICN", # flake8-import-conventions
113+
"G", # flake8-logging-format
114+
"PGH", # pygrep-hooks
115+
"PIE", # flake8-pie
116+
"PL", # pylint
117+
"PT", # flake8-pytest-style
118+
"PTH", # flake8-use-pathlib
119+
"RET", # flake8-return
120+
"RUF", # Ruff-specific
121+
"SIM", # flake8-simplify
122+
"T20", # flake8-print
123+
"UP", # pyupgrade
124+
"YTT", # flake8-2020
125+
"EXE", # flake8-executable
126+
"NPY", # NumPy specific rules
127+
"PD", # pandas-vet
44128
]
45129
ignore = [
46-
"UP007", # type annotation upgrade, breaks pydantic for Python 3.9 (remove once above)
47-
"PLR09", # Too many <...>
48-
"PLR2004", # Magic value used in comparison
49-
"ISC001", # Conflicts with formatter
50-
"RET505", # This is sometimes wanted, protets against accidental intendation
51-
"PD901", # "avoid using `df[...].values`" -> no, this is a very good name if there is only one df
52-
"PD011", # "replace `df[...].values` with `df[...].to_numpy()`" -> not yet, it's not deprecated.
130+
"UP007", # type annotation upgrade, breaks pydantic for Python 3.9 (remove once above)
131+
"PLR09", # Too many <...>
132+
"PLR2004", # Magic value used in comparison
133+
"ISC001", # Conflicts with formatter
134+
"RET505", # This is sometimes wanted, protets against accidental intendation
135+
"PD901", # "avoid using `df[...].values`" -> no, this is a very good name if there is only one df
136+
"PD011", # "replace `df[...].values` with `df[...].to_numpy()`" -> not yet, it's not deprecated.
53137
# Prefer to have a single way to access the data if we don't care about whether it's a numpy array or not.
54-
"PLW0603", # updating global variables with a function is bad, but we use it for
55-
"PLW2901", # "for loop overwritten by assignment" -> we use this to update the loop variable
56-
"PD013", # "melt over stack": df function, but triggers on tensors
57-
"NPY002", # "Use rnd generator in numpy" -> we use np.random for some legacy stuff but do use the new one where we can
138+
"PLW0603", # updating global variables with a function is bad, but we use it for
139+
"PLW2901", # "for loop overwritten by assignment" -> we use this to update the loop variable
140+
"PD013", # "melt over stack": df function, but triggers on tensors
141+
"NPY002", # "Use rnd generator in numpy" -> we use np.random for some legacy stuff but do use the new one where we can
142+
"T201", # "print used" -> we use print for displaying information in verbose mode
58143

59144
]
60145
isort.required-imports = ["from __future__ import annotations"]

setup.cfg

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

setup.py

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

src/hepstats/hypotests/calculators/asymptotic_calculator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _convert_to_binned(self, loss, asimov_bins):
160160
"""Converts the loss to binned if necessary."""
161161

162162
for unbinned_loss, binned_loss in self.UNBINNED_TO_BINNED_LOSS.items():
163-
if type(loss) == unbinned_loss:
163+
if type(loss) is unbinned_loss:
164164
datasets = []
165165
models = []
166166
for d, m, nbins in zip(loss.data, loss.model, asimov_bins):
@@ -171,7 +171,7 @@ def _convert_to_binned(self, loss, asimov_bins):
171171
models.append(model_binned)
172172
loss = binned_loss(model=models, data=datasets, constraints=loss.constraints)
173173
break
174-
if type(loss) == binned_loss:
174+
if type(loss) is binned_loss:
175175
break
176176
else:
177177
loss = False

0 commit comments

Comments
 (0)