From db0b2c90f11be8cd3c52be8440811022dbf4ab0d Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 26 May 2022 22:58:13 +0200 Subject: [PATCH] Only import setuptools_scm when we are in a matplotlib git repo Closes #23114, where somebody has installed matplotlib into another 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 7df511af1e16..1dcfb827833e 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -164,11 +164,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,