Skip to content

Commit db0b2c9

Browse files
committed
Only import setuptools_scm when we are in a matplotlib git repo
Closes matplotlib#23114, where somebody has installed matplotlib into another git repo.
1 parent bcef5d6 commit db0b2c9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.matplotlib-repo

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The existence of this file signals that the code is a matplotlib source repo
2+
and not an installed version. We use this in __init__.py for gating version
3+
detection.

lib/matplotlib/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ def _parse_to_version_info(version_str):
164164

165165
def _get_version():
166166
"""Return the version string used for __version__."""
167-
# Only shell out to a git subprocess if really needed, and not on a
168-
# shallow clone, such as those used by CI, as the latter would trigger
169-
# a warning from setuptools_scm.
167+
# Only shell out to a git subprocess if really needed, i.e. when we are in
168+
# a matplotlib git repo but not in a shallow clone, such as those used by
169+
# CI, as the latter would trigger a warning from setuptools_scm.
170170
root = Path(__file__).resolve().parents[2]
171-
if (root / ".git").exists() and not (root / ".git/shallow").exists():
171+
if ((root / ".matplotlib-repo").exists()
172+
and (root / ".git").exists()
173+
and not (root / ".git/shallow").exists()):
172174
import setuptools_scm
173175
return setuptools_scm.get_version(
174176
root=root,

0 commit comments

Comments
 (0)