Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Nov 7, 2023
1 parent 24f95ad commit 09441d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions sphinx_needs/directives/needbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sphinx_needs.data import SphinxNeedsData
from sphinx_needs.filter_common import FilterBase, filter_needs, prepare_need_list
from sphinx_needs.logging import get_logger
from sphinx_needs.utils import add_doc, get_matplotlib, save_matplotlib_figure
from sphinx_needs.utils import add_doc, import_matplotlib, save_matplotlib_figure

logger = get_logger(__name__)

Expand Down Expand Up @@ -74,7 +74,7 @@ def run(self) -> Sequence[nodes.Node]:
text_color = text_color.strip()

style = self.options.get("style")
matplotlib = get_matplotlib()
matplotlib = import_matplotlib()
style = style.strip() if style else (matplotlib.style.use("default") if matplotlib else "default")

legend = "legend" in self.options
Expand Down Expand Up @@ -165,7 +165,7 @@ def process_needbar(app: Sphinx, doctree: nodes.document, fromdocname: str, foun
needs_data = SphinxNeedsData(env)
needs_config = NeedsSphinxConfig(env.config)

matplotlib = get_matplotlib()
matplotlib = import_matplotlib()

if matplotlib is None and found_nodes and needs_config.include_needs:
logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions sphinx_needs/directives/needpie.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sphinx_needs.utils import (
add_doc,
check_and_get_external_filter_func,
get_matplotlib,
import_matplotlib,
save_matplotlib_figure,
)

Expand Down Expand Up @@ -105,7 +105,7 @@ def process_needpie(app: Sphinx, doctree: nodes.document, fromdocname: str, foun
needs_data = SphinxNeedsData(env)
needs_config = NeedsSphinxConfig(env.config)

matplotlib = get_matplotlib()
matplotlib = import_matplotlib()

if matplotlib is None and found_nodes and needs_config.include_needs:
logger.warning(
Expand Down
9 changes: 7 additions & 2 deletions sphinx_needs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import operator
import os
import re
from functools import reduce, wraps
from functools import lru_cache, reduce, wraps
from re import Pattern
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -384,7 +384,12 @@ def jinja_parse(context: Dict[str, Any], jinja_string: str) -> str:
return content


def get_matplotlib() -> Optional["matplotlib"]:
@lru_cache()
def import_matplotlib() -> Optional["matplotlib"]:
"""Import and return matplotlib, or return None if it cannot be imported.
Also sets the interactive backend to ``Agg``, if ``DISPLAY`` is not set.
"""
try:
import matplotlib
import matplotlib.pyplot
Expand Down

0 comments on commit 09441d7

Please sign in to comment.