Skip to content

Commit

Permalink
Merge pull request #169 from scikit-hep/py313
Browse files Browse the repository at this point in the history
Python 3.13 support
  • Loading branch information
jonas-eschle authored Nov 9, 2024
2 parents 417fd96 + 3965330 commit 5991986
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 71 deletions.
35 changes: 12 additions & 23 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,49 +32,35 @@ jobs:
- ubuntu-latest
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
include:
- os: windows-latest
python-version: "3.9"
- os: macos-13
python-version: "3.9"
- os: macos-14
- os: macos-latest
python-version: "3.12" # old versions not supported
name: Check Python ${{ matrix.python-version }} ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/[email protected]
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.cfg') }}-pip-${{ hashFiles('**/setup.py') }}-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install package
run: |
python -m pip install --upgrade pip
python -m pip install -e .[test] pytest-xdist # for multiprocessing
pip install uv
uv pip install --system -e .[test] pytest-xdist # for multiprocessing, -e needed for pathes etc.
- name: Test package
run: python -m pytest --doctest-modules --cov=hepstats --cov-report=xml -n auto

- name: Upload coverage to Codecov
if: matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest'
if: matrix.python-version == '3.9' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # technically not needed, but prevents failures: https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
Expand Down Expand Up @@ -106,13 +92,16 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5

- name: Setup Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: 3.9

- name: Install dependencies
run: |
pip install -U -q -e .[docs]
pip list
pip install uv
uv pip install --system -e .[docs]
- name: build docs
run: |
sphinx-build -b html docs docs/_build/html
Expand Down
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ repos:
- id: requirements-txt-fixer
- id: debug-statements
- id: end-of-file-fixer
- repo: https://github.com/mgedmin/check-manifest
rev: "0.50"
hooks:
- id: check-manifest
args:
- --update
- --no-build-isolation
additional_dependencies:
- hatchling
- hatch-vcs
# - repo: https://github.com/mgedmin/check-manifest
# rev: "0.50"
# hooks:
# - id: check-manifest
# args:
# - --update
# - --no-build-isolation
# additional_dependencies:
# - hatchling
# - hatch-vcs

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.12.0
Expand Down Expand Up @@ -60,7 +60,7 @@ repos:
rev: v2.7.0
hooks:
- id: setup-cfg-fmt
args: [ --max-py-version=3.12, --include-version-classifiers ]
args: [ --max-py-version=3.13, --include-version-classifiers ]

# Notebook formatting
- repo: https://github.com/nbQA-dev/nbQA
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
main
**************

* Add support for Python 3.13

Version 0.8.1
**************

Expand Down
24 changes: 0 additions & 24 deletions MANIFEST.in

This file was deleted.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ test = [
"pytest",
"pytest-cov",
"pytest-runner",
"zfit>=0.20.0",
"zfit>=0.20.0;python_version<'3.13'",
# 'hepstats[zfit];python_version<"3.13"', # not working, why?
]
zfit = ["zfit>=0.20.0"]

Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def data_gen():
# TODO: manually ported, use pre-made: https://github.com/zfit/zfit-development/issues/73
@pytest.fixture(autouse=True)
def _setup_teardown():
import zfit
try:
import zfit
except ImportError:
yield
return

old_chunksize = zfit.run.chunking.max_n_points
old_active = zfit.run.chunking.active
Expand Down
3 changes: 2 additions & 1 deletion tests/hypotests/test_basetest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import numpy as np
import zfit
zfit = pytest.importorskip("zfit")
from zfit.loss import UnbinnedNLL
from zfit.minimize import Minuit

Expand All @@ -9,6 +9,7 @@
from hepstats.hypotests.parameters import POI, POIarray



def create_loss():
obs = zfit.Space("x", limits=(0.1, 2.0))
data = zfit.data.Data.from_numpy(obs=obs, array=np.random.normal(1.2, 0.1, 10000))
Expand Down
2 changes: 1 addition & 1 deletion tests/hypotests/test_calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np
import pytest
import zfit
zfit = pytest.importorskip("zfit")
from zfit.loss import UnbinnedNLL
from zfit.minimize import Minuit

Expand Down
2 changes: 1 addition & 1 deletion tests/hypotests/test_confidence_intervals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import numpy as np
import zfit
zfit = pytest.importorskip("zfit")
import os
from zfit.loss import UnbinnedNLL
from zfit.minimize import Minuit
Expand Down
2 changes: 1 addition & 1 deletion tests/hypotests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np
import pytest
import zfit
zfit = pytest.importorskip("zfit")
from zfit.loss import UnbinnedNLL
from zfit.minimize import Minuit

Expand Down
2 changes: 1 addition & 1 deletion tests/hypotests/test_parameters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
import pytest
import numpy as np
import zfit
zfit = pytest.importorskip("zfit")

from hepstats.hypotests.parameters import POI, POIarray

Expand Down
2 changes: 1 addition & 1 deletion tests/hypotests/test_toysutils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import numpy as np
import zfit
zfit = pytest.importorskip("zfit")
import os
from zfit.loss import ExtendedUnbinnedNLL, UnbinnedNLL
from zfit.minimize import Minuit
Expand Down
1 change: 1 addition & 0 deletions tests/hypotests/test_upperlimit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import numpy as np
import os
zfit = pytest.importorskip("zfit")
from zfit.minimize import Minuit

import hepstats
Expand Down
10 changes: 6 additions & 4 deletions tests/modeling/test_bayesianblocks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from pathlib import Path

import numpy as np

import hepstats
from hepstats.modeling import bayesian_blocks

answer_dir = os.path.dirname(hepstats.__file__) + "/../../tests/modeling/data"
answer_dir = Path(__file__).parent / "data"


def test_bayesian_blocks(cmdopt, data_gen):
Expand All @@ -12,10 +14,10 @@ def test_bayesian_blocks(cmdopt, data_gen):
be3 = bayesian_blocks(data_gen[0], weights=data_gen[2])

if cmdopt == "generate":
with open(answer_dir + "/answers_bayesian_blocks.npz", "wb") as f:
with open(answer_dir / "answers_bayesian_blocks.npz", "wb") as f:
np.savez(f, be1=be1, be2=be2, be3=be3)
elif cmdopt == "test":
answers = np.load(answer_dir + "/answers_bayesian_blocks.npz")
answers = np.load(answer_dir / "answers_bayesian_blocks.npz")
assert np.all(be1 == answers["be1"])
assert np.all(be2 == answers["be2"])
assert np.all(be3 == answers["be3"])
Expand Down
2 changes: 1 addition & 1 deletion tests/splots/test_splots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from scipy.stats import ks_2samp

import zfit
zfit = pytest.importorskip("zfit")
from zfit.loss import ExtendedUnbinnedNLL
from zfit.minimize import Minuit

Expand Down

0 comments on commit 5991986

Please sign in to comment.