Skip to content

Commit

Permalink
refactor: migrate setup configuration to pyproject.toml
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonas-eschle committed Oct 17, 2024
1 parent 53d23b5 commit 198ec95
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 149 deletions.
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ repos:
- id: debug-statements
- id: end-of-file-fixer
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
rev: "0.50"
hooks:
- id: check-manifest
args: [ --update, --no-build-isolation ]
additional_dependencies: [ setuptools-scm, setuptools-scm-git-archive ]
args: [ --update ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.12.0
hooks:
- id: mypy
files: src
Expand All @@ -46,13 +45,13 @@ repos:
- id: rst-directive-colons

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
rev: v3.18.0
hooks:
- id: pyupgrade
args: [ --py38-plus ]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
rev: v2.7.0
hooks:
- id: setup-cfg-fmt
args: [ --max-py-version=3.12, --include-version-classifiers ]
Expand All @@ -64,7 +63,7 @@ repos:

- id: nbqa-pyupgrade
additional_dependencies: [ pyupgrade ]
args: [ --py38-plus ]
args: [ --py39-plus ]


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

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.3
rev: 0.29.4
hooks:
- id: check-github-workflows
- id: check-github-actions
Expand All @@ -102,7 +101,7 @@ repos:
hooks:
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix, --unsafe-fixes, --show-fixes , --line-length=120]
args: [ --fix, --unsafe-fixes, --show-fixes , --line-length=120 ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
161 changes: 123 additions & 38 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,97 @@
[build-system]
requires = [
"setuptools>=42",
"setuptools_scm[toml]>=3.4"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "hepstats"
description = "statistics tools and utilities"
authors = [{ name = "Matthieu Marinangeli", email = "[email protected]" }]
maintainers = [{ name = "Scikit-HEP", email = "[email protected]" }]
license = { text = "BSD 3-Clause License" }
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Software Development",
"Topic :: Utilities",
]
urls = { Homepage = "https://github.com/scikit-hep/hepstats" }
requires-python = ">=3.9"
dependencies = [
"asdf",
"numpy",
"pandas",
"scipy",
"tqdm",
"uhi",
]
dynamic = ["version"]

[project.readme]
file = "README.md"
content-type = "text/markdown"

[project.optional-dependencies]
dev = [
"hepstats[docs]",
"hepstats[test]",
"pre-commit",
]
docs = [
"matplotlib",
"pydata-sphinx-theme",
"sphinx>=3.1.2",
"sphinx-autodoc-typehints",
"sphinx-copybutton",
"sphinxcontrib-bibtex>=2.0.0",
]
doc = ["hepstats[docs]"] # alias
test = [
"pytest",
"pytest-cov",
"pytest-runner",
"zfit>=0.20.0",
]
zfit = ["zfit>=0.20.0"]



[tool.pytest.ini_options]
junit_family = "xunit2"
testpaths = ["tests"]

[tool.check-manifest]
ignore = ["src/hepstats/_version.py"]

[tool.build_sphinx]
project = "hepstats"
source-dir = "docs"
build-dir = "docs/_build"
all-files = "1"
warning-is-error = "0"

build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "src/hepstats/version.py"
[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/hepstats/_version.py"

[tool.ruff]
#src = ["src"]
Expand All @@ -20,41 +104,42 @@ exclude = [
]
[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
ignore = [
"UP007", # type annotation upgrade, breaks pydantic for Python 3.9 (remove once above)
"PLR09", # Too many <...>
"PLR2004", # Magic value used in comparison
"ISC001", # Conflicts with formatter
"RET505", # This is sometimes wanted, protets against accidental intendation
"PD901", # "avoid using `df[...].values`" -> no, this is a very good name if there is only one df
"PD011", # "replace `df[...].values` with `df[...].to_numpy()`" -> not yet, it's not deprecated.
"UP007", # type annotation upgrade, breaks pydantic for Python 3.9 (remove once above)
"PLR09", # Too many <...>
"PLR2004", # Magic value used in comparison
"ISC001", # Conflicts with formatter
"RET505", # This is sometimes wanted, protets against accidental intendation
"PD901", # "avoid using `df[...].values`" -> no, this is a very good name if there is only one df
"PD011", # "replace `df[...].values` with `df[...].to_numpy()`" -> not yet, it's not deprecated.
# Prefer to have a single way to access the data if we don't care about whether it's a numpy array or not.
"PLW0603", # updating global variables with a function is bad, but we use it for
"PLW2901", # "for loop overwritten by assignment" -> we use this to update the loop variable
"PD013", # "melt over stack": df function, but triggers on tensors
"NPY002", # "Use rnd generator in numpy" -> we use np.random for some legacy stuff but do use the new one where we can
"PLW0603", # updating global variables with a function is bad, but we use it for
"PLW2901", # "for loop overwritten by assignment" -> we use this to update the loop variable
"PD013", # "melt over stack": df function, but triggers on tensors
"NPY002", # "Use rnd generator in numpy" -> we use np.random for some legacy stuff but do use the new one where we can
"T201", # "print used" -> we use print for displaying information in verbose mode

]
isort.required-imports = ["from __future__ import annotations"]
Expand Down
87 changes: 0 additions & 87 deletions setup.cfg

This file was deleted.

13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/hepstats/hypotests/calculators/asymptotic_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _convert_to_binned(self, loss, asimov_bins):
"""Converts the loss to binned if necessary."""

for unbinned_loss, binned_loss in self.UNBINNED_TO_BINNED_LOSS.items():
if type(loss) == unbinned_loss:
if type(loss) is unbinned_loss:
datasets = []
models = []
for d, m, nbins in zip(loss.data, loss.model, asimov_bins):
Expand All @@ -171,7 +171,7 @@ def _convert_to_binned(self, loss, asimov_bins):
models.append(model_binned)
loss = binned_loss(model=models, data=datasets, constraints=loss.constraints)
break
if type(loss) == binned_loss:
if type(loss) is binned_loss:
break
else:
loss = False
Expand Down

0 comments on commit 198ec95

Please sign in to comment.