Skip to content

Commit

Permalink
fix: support older matplotlib (#455)
Browse files Browse the repository at this point in the history
* fix: support older matplotlib

* fix: apply to all styles

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: add _compat.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: ignore attr-defined

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
agoose77 and pre-commit-ci[bot] authored Oct 11, 2023
1 parent 33ff740 commit c107975
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/mplhep/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import annotations

import matplotlib
from packaging.version import parse as parse_version

if parse_version(matplotlib.__version__) < parse_version("3.8.0"):
from matplotlib import docstring # type: ignore[attr-defined]
else:
from matplotlib import _docstring as docstring # type: ignore[attr-defined]


__all__ = ("docstring",)
3 changes: 1 addition & 2 deletions src/mplhep/alice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import inspect

from matplotlib import _docstring as docstring

import mplhep

from . import label as label_base
from ._compat import docstring
from .label import lumitext

# Log styles
Expand Down
5 changes: 3 additions & 2 deletions src/mplhep/atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mplhep

from . import label as label_base
from ._compat import docstring
from .label import lumitext

# Log styles
Expand All @@ -15,7 +16,7 @@
__all__ = ("style", "lumitext")


@mpl._docstring.copy(label_base.exp_text)
@docstring.copy(label_base.exp_text)
def text(text="", **kwargs):
for key, value in dict(mplhep.rcParams.text._get_kwargs()).items():
if (
Expand All @@ -29,7 +30,7 @@ def text(text="", **kwargs):
return label_base.exp_text("ATLAS", text=text, **kwargs)


@mpl._docstring.copy(label_base.exp_label)
@docstring.copy(label_base.exp_label)
def label(label=None, **kwargs):
for key, value in dict(mplhep.rcParams.label._get_kwargs()).items():
if (
Expand Down
3 changes: 1 addition & 2 deletions src/mplhep/cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import inspect

from matplotlib import _docstring as docstring

import mplhep

from . import label as label_base
from ._compat import docstring
from .label import lumitext

# Log styles
Expand Down
3 changes: 1 addition & 2 deletions src/mplhep/lhcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

import inspect

from matplotlib import _docstring as docstring

import mplhep
from mplhep import label as label_base

from ._compat import docstring
from .label import lumitext
from .styles import lhcb as style

Expand Down

0 comments on commit c107975

Please sign in to comment.