From f2a3ec5f3c360ebe2ce6f7ff79939e9dc79560e5 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Sat, 11 Jun 2022 11:33:48 +0200 Subject: [PATCH] Backport PR #23144: Only import setuptools_scm when we are in a matplotlib git repo --- .matplotlib-repo | 3 +++ lib/matplotlib/__init__.py | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .matplotlib-repo diff --git a/.matplotlib-repo b/.matplotlib-repo new file mode 100644 index 000000000000..0b1d699bcdb1 --- /dev/null +++ b/.matplotlib-repo @@ -0,0 +1,3 @@ +The existence of this file signals that the code is a matplotlib source repo +and not an installed version. We use this in __init__.py for gating version +detection. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index ba9cd6c90c17..b8fd4f9860a3 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -160,11 +160,13 @@ def _parse_to_version_info(version_str): def _get_version(): """Return the version string used for __version__.""" - # Only shell out to a git subprocess if really needed, and not on a - # shallow clone, such as those used by CI, as the latter would trigger - # a warning from setuptools_scm. + # Only shell out to a git subprocess if really needed, i.e. when we are in + # a matplotlib git repo but not in a shallow clone, such as those used by + # CI, as the latter would trigger a warning from setuptools_scm. root = Path(__file__).resolve().parents[2] - if (root / ".git").exists() and not (root / ".git/shallow").exists(): + if ((root / ".matplotlib-repo").exists() + and (root / ".git").exists() + and not (root / ".git/shallow").exists()): import setuptools_scm return setuptools_scm.get_version( root=root,