Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modernize, Python 3.8+ #130

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
dist:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -29,11 +29,18 @@ jobs:
url: https://pypi.org/p/uhi
permissions:
id-token: write
attestations: write

steps:
- uses: actions/download-artifact@v4
with:
name: Packages
path: dist

- uses: actions/attest-build-provenance@v1
with:
subject-path: "dist/*"

- uses: pypa/gh-action-pypi-publish@release/v1
with:
attestations: true
13 changes: 4 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.12"]
runs-on: [ubuntu-latest, macos-13, windows-latest]
python-version: ["3.8", "3.13"]
runs-on: [ubuntu-latest, macos-latest, windows-latest]

include:
- python-version: pypy-3.9
runs-on: ubuntu-latest
- python-version: "3.7"
runs-on: ubuntu-20.04
exclude:
- python-version: "3.7"
- python-version: pypy-3.10
runs-on: ubuntu-latest

steps:
Expand All @@ -38,6 +33,7 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install package
run: python -m pip install .[test,schema]
Expand All @@ -59,7 +55,6 @@ jobs:

- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
use-mamba: true
environment-file: environment.yml

Expand Down
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ ci:
autoupdate_commit_msg: 'chore: update pre-commit hooks'

repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand All @@ -26,6 +21,7 @@ repos:
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
Expand All @@ -34,9 +30,8 @@ repos:
files: ^(src|tests)
args: []
additional_dependencies:
- numpy~=1.26.0
- numpy
- pytest
- importlib_metadata
- importlib_resources

- repo: https://github.com/pre-commit/pygrep-hooks
Expand All @@ -60,8 +55,8 @@ repos:
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.3.3"
hooks:
- id: prettier
types_or: [json]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ It is not usually a runtime dependency, but only a type checking, testing,
and/or docs dependency in support of other libraries (such as
[boost-histogram][] 0.13+, [hist][] 2.1+, [mplhep][] 0.2.15+, [uproot][] 4+,
and [histoprint][] 2+). There are a few useful runtime usable components
(listed below). It requires Python 3.6+. [See what's
(listed below). Older versions are available for Python 3.6+. [See what's
new](https://github.com/scikit-hep/uhi/releases).

To assist plotting libraries in accepting Histograms from classic sources, see
Expand Down
10 changes: 2 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@

from __future__ import annotations

import importlib.metadata
import os
import sys

if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
import importlib.metadata as metadata


# -- Project information -----------------------------------------------------

Expand All @@ -22,7 +16,7 @@
author = "Henry Schreiner, Hans Dembinski, Jim Pivarski"

# The full version, including alpha/beta/rc tags
version = release = metadata.version("uhi")
version = release = importlib.metadata.version("uhi")


# -- General configuration ---------------------------------------------------
Expand Down
19 changes: 5 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@ authors = [
maintainers = [
{name="The Scikit-HEP admins", email="scikit-hep-admins@googlegroups.com"},
]
requires-python = ">=3.7"
requires-python = ">=3.8"
readme = "README.md"
license = {file="LICENSE"}
dependencies = [
"numpy>=1.13.3",
"typing-extensions>=3.7; python_version<'3.8'",
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering",
"Typing :: Typed",
]
Expand All @@ -58,7 +57,6 @@ docs = [
]
test = [
"pytest>=6",
"importlib-metadata>=1.0; python_version<'3.8'",
"boost-histogram>=1.0",
]

Expand All @@ -70,7 +68,6 @@ build.hooks.vcs.version-file = "src/uhi/_version.py"
[tool.pdm.dev-dependencies]
dev = [
"pytest>=6",
"importlib-metadata>=1.0; python_version<'3.8'",
"boost-histogram>=1.0",
]

Expand All @@ -97,7 +94,7 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
module = ["fastjsonschema"]
ignore_missing_imports = true

[tool.ruff]
[tool.ruff.lint]
select = [
"E", "F", "W", # flake8
"B", # flake8-bugbear
Expand Down Expand Up @@ -128,18 +125,12 @@ extend-ignore = [
"E501", # Line too long
"PT004", # Use underscore for non-returning fixture (use usefixture instead)
"PT013", # Incorrect import of pytest
"ISC001", # Conflicts with formatter
]
typing-modules = ["mypackage._compat.typing"]
src = ["src"]
unfixable = [
"T20", # Removes print statements
"F841", # Removes unused variables
]
exclude = []
flake8-unused-arguments.ignore-variadic-names = true
isort.required-imports = ["from __future__ import annotations"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]
"noxfile.py" = ["T20"]
"tests/test_ensure.py" = ["NPY002"]
4 changes: 2 additions & 2 deletions src/uhi/numpy_plottable.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __len__(self) -> int:
Return the number of bins (not counting flow bins, which are ignored
for this Protocol currently).
"""
return self.edges.shape[0]
return self.edges.shape[0] # type: ignore[no-any-return]

def __eq__(self, other: Any) -> bool:
"""
Expand Down Expand Up @@ -140,7 +140,7 @@ def __init__(

self.kind = kind
self.axes: Sequence[PlottableAxis] = [
_bin_helper(shape, b) for shape, b in zip(hist.shape, bins) # type: ignore[arg-type]
_bin_helper(shape, b) for shape, b in zip(hist.shape, bins)
]

def __repr__(self) -> str:
Expand Down
10 changes: 1 addition & 9 deletions src/uhi/typing/plottable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@

from __future__ import annotations

import sys
from collections.abc import Iterator, Sequence
from typing import Any, Tuple, TypeVar, Union
from typing import Any, Protocol, Tuple, TypeVar, Union, runtime_checkable

# NumPy 1.20+ will work much, much better than previous versions when type checking
import numpy as np

if sys.version_info < (3, 8):
from typing_extensions import Protocol, runtime_checkable

else:
from typing import Protocol, runtime_checkable


protocol_version = (1, 2)

# Known kinds of histograms. A Producer can add Kinds not defined here; a
Expand Down
4 changes: 2 additions & 2 deletions tests/test_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_root_th1f_convert() -> None:
assert all(th.GetBinContent(i + 1) == approx(iv) for i, iv in enumerate(h.values()))
assert all(
th.GetBinError(i + 1) == approx(ie)
for i, ie in enumerate(np.sqrt(h.variances())) # type: ignore[arg-type]
for i, ie in enumerate(np.sqrt(h.variances()))
)


Expand All @@ -36,6 +36,6 @@ def test_root_th2f_convert() -> None:
)
assert all(
th.GetBinError(i + 1, j + 1) == approx(ie)
for i, row in enumerate(np.sqrt(h.variances())) # type: ignore[arg-type]
for i, row in enumerate(np.sqrt(h.variances()))
for j, ie in enumerate(row)
)
9 changes: 2 additions & 7 deletions tests/test_uhi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from __future__ import annotations

import sys
import importlib.metadata

from uhi import __version__

if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata


def test_version() -> None:
assert __version__ == metadata.version("uhi")
assert __version__ == importlib.metadata.version("uhi")
Loading