Skip to content

Commit

Permalink
Merge branch 'develop' into fix_lto
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Aug 25, 2024
2 parents d4124bf + abff499 commit 53ca3bd
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .ci/release_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Ensure that current version is not in conflict with published releases."""

from pkg_resources import parse_version
from iminuit._parse_version import parse_version
import subprocess as subp
from pathlib import PurePath
import urllib.request
Expand Down
15 changes: 4 additions & 11 deletions doc/update_changelog.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
from pathlib import Path
import re
import subprocess as subp
from packaging.version import Version, InvalidVersion
import datetime
import warnings
import sys
from iminuit._parse_version import parse_version

cwd = Path(__file__).parent


def parse_version_with_fallback(version_string):
try:
return Version(version_string)
except InvalidVersion:
return Version("0.0.1")


version = (
subp.check_output([sys.executable, cwd.parent / "version.py"]).strip().decode()
)
new_version = parse_version_with_fallback(version)
new_version = parse_version(version)


with warnings.catch_warnings():
Expand All @@ -28,7 +21,7 @@ def parse_version_with_fallback(version_string):
iter(
sorted(
(
parse_version_with_fallback(x)
parse_version(x)
for x in subp.check_output(["git", "tag"])
.decode()
.strip()
Expand All @@ -44,7 +37,7 @@ def parse_version_with_fallback(version_string):

# find latest entry
m = re.search(r"([0-9]+\.[0-9]+\.[0-9]+) \([^\)]+\)\n-*", content, re.MULTILINE)
previous_version = Version(m.group(1))
previous_version = parse_version(m.group(1))
position = m.span(0)[0]

# sanity checks
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
"Operating System :: Unix",
"Operating System :: MacOS",
]
dependencies = ["packaging", "numpy >=1.21"]
dependencies = ["numpy >=1.21"]

[project.urls]
repository = "http://github.com/scikit-hep/iminuit"
Expand Down
11 changes: 7 additions & 4 deletions python_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
from html.parser import HTMLParser
import gzip
from packaging.version import Version


class PythonVersionParser(HTMLParser):
Expand All @@ -27,9 +26,12 @@ def handle_data(self, data):
"""Extract Python version from entry."""
if self.found_version:
self.found_version = False
match = re.search(r"Python (\d+\.\d+)", data)
match = re.search(r"Python (\d+)\.(\d+)\.(\d+)?", data)
if match:
self.versions.add(Version(match.group(1)))
major = int(match.group(1))
minor = int(match.group(2))
bugfix = int(match.group(3))
self.versions.add((major, minor, bugfix))


def versions():
Expand All @@ -56,7 +58,8 @@ def latest():

def main():
"""Print all discovered release versions."""
print(" ".join(str(x) for x in sorted(versions())))
for x in sorted(versions()):
print(x)


if __name__ == "__main__":
Expand Down
10 changes: 6 additions & 4 deletions src/iminuit/_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import warnings
from packaging.version import Version
from typing import Callable, Any
from importlib.metadata import version
from iminuit._parse_version import parse_version

CURRENT_VERSION = Version(version("iminuit"))

CURRENT_VERSION = parse_version(version("iminuit"))


class deprecated:
def __init__(self, reason: str, removal: str = ""):
self.reason = reason
self.removal = Version(removal) if removal else None
self.removal = parse_version(removal) if removal else None

def __call__(self, func: Callable[..., Any]) -> Callable[..., Any]:
category: Any = FutureWarning
extra = ""
if self.removal:
extra = f" and will be removed in version {self.removal}"
vstring = ".".join(str(x) for x in self.removal)
extra = f" and will be removed in version {vstring}"
if CURRENT_VERSION >= self.removal:
category = DeprecationWarning
msg = f"{func.__name__} is deprecated{extra}: {self.reason}"
Expand Down
24 changes: 24 additions & 0 deletions src/iminuit/_parse_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re
from typing import Tuple, Union


def parse_version(s: str) -> Union[Tuple[int, int], Tuple[int, int, int]]:
"""
Parse version string and return tuple of integer parts to allow for comparison.
This does not implement the full version spec for version parsing, see
https://packaging.python.org/en/latest/specifications/version-specifiers/. It is a
simplified approach, so we do not have to depend on the external packaging module.
We only support correct ordering for major, mior, and micro segments, ie. version
strings of the form X.Y and X.Y.Z. Versions with pre- and post-release segments are
correctly parsed, but these segments are ignored, as well as development release
segments.
"""
match = re.match(r"(\d+)\.(\d+)(?:\.(\d+))?", s)
if not match:
msg = f"could not parse version string {s}"
raise ValueError(msg)
if match.group(3):
return int(match.group(1)), int(match.group(2)), int(match.group(3))
return int(match.group(1)), int(match.group(2))
6 changes: 3 additions & 3 deletions src/iminuit/minuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,12 +2141,12 @@ def draw_mncontour(
from matplotlib import pyplot as plt
from matplotlib.path import Path
from matplotlib.contour import ContourSet
from packaging.version import Version
from ._parse_version import parse_version

ix, xname = self._normalize_key(x)
iy, yname = self._normalize_key(y)

mpl_version = Version(mpl_version_string)
mpl_version = parse_version(mpl_version_string)

cls = [replace_none(x, 0.68) for x in mutil._iterate(cl)]

Expand All @@ -2163,7 +2163,7 @@ def draw_mncontour(
experimental=experimental,
)
n_lineto = len(pts) - 2
if (mpl_version.major, mpl_version.minor) < (3, 5):
if mpl_version < (3, 5):
n_lineto -= 1 # pragma: no cover
c_val.append(cl)
c_pts.append([pts]) # level can have more than one contour in mpl
Expand Down
12 changes: 12 additions & 0 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ def func(x):
func(1)


def test_deprecated_func_3():
@deprecated("bla", removal="1000.0")
def func(x):
pass

with pytest.warns(
FutureWarning,
match="func is deprecated and will be removed in version 1000.0: bla",
):
func(1)


def test_deprecated_parameter():
@deprecated_parameter(foo="bar")
def some_function(x, y, foo):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_parse_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from iminuit._parse_version import parse_version
import pytest


@pytest.mark.parametrize(
"s,ref",
[
("1.2", (1, 2)),
("1.2.3", (1, 2, 3)),
("1.2a1", (1, 2)),
("1.2.3a1", (1, 2, 3)),
("1.2.post1", (1, 2)),
("1.2.3.post1", (1, 2, 3)),
("1.2a1.dev1", (1, 2)),
("1.2.3a1.dev1", (1, 2, 3)),
],
)
def test_parse_version(s, ref):
assert parse_version(s) == ref


def test_parse_version_bad():
with pytest.raises(ValueError):
parse_version("a.b.c")

0 comments on commit 53ca3bd

Please sign in to comment.