Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 222bd9a

Browse filesBrowse files
authored
Merge pull request #18971 from anntzer/setuptools-scm
DEV: Switch to setuptools_scm
2 parents 1fdc2cd + 14bbff2 commit 222bd9a
Copy full SHA for 222bd9a

File tree

Expand file treeCollapse file tree

15 files changed

+61
-2223
lines changed
Filter options
Expand file treeCollapse file tree

15 files changed

+61
-2223
lines changed

‎.flake8

Copy file name to clipboardExpand all lines: .flake8
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ exclude =
3535
doc/gallery
3636
doc/tutorials
3737
# External files.
38-
versioneer.py
3938
tools/gh_api.py
4039
tools/github_stats.py
4140
.tox

‎.git_archival.txt

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref-names: $Format:%D$

‎.gitattributes

Copy file name to clipboardExpand all lines: .gitattributes
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
*.ppm binary
33
*.svg binary
44
*.svg linguist-language=true
5-
lib/matplotlib/_version.py export-subst
5+
.git_archival.txt export-subst

‎.github/workflows/tests.yml

Copy file name to clipboardExpand all lines: .github/workflows/tests.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
142142
# Install dependencies from PyPI.
143143
python -m pip install --upgrade $PRE \
144-
cycler kiwisolver numpy pillow pyparsing python-dateutil \
144+
cycler kiwisolver numpy pillow pyparsing python-dateutil setuptools-scm \
145145
-r requirements/testing/all.txt \
146146
${{ matrix.extra-requirements }}
147147

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pip-wheel-metadata/*
4242
# tox testing tool
4343
.tox
4444
setup.cfg
45+
# generated by setuptools_scm
46+
lib/matplotlib/_version.py
4547

4648
# OS generated files #
4749
######################

‎MANIFEST.in

Copy file name to clipboardExpand all lines: MANIFEST.in
-18Lines changed: 0 additions & 18 deletions
This file was deleted.

‎doc/conf.py

Copy file name to clipboardExpand all lines: doc/conf.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def _check_dependencies():
198198
try:
199199
SHA = subprocess.check_output(
200200
['git', 'describe', '--dirty']).decode('utf-8').strip()
201-
# Catch the case where git is not installed locally, and use the versioneer
201+
# Catch the case where git is not installed locally, and use the setuptools_scm
202202
# version number instead
203203
except (subprocess.CalledProcessError, FileNotFoundError):
204204
SHA = matplotlib.__version__

‎doc/devel/contributing.rst

Copy file name to clipboardExpand all lines: doc/devel/contributing.rst
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ New modules and files: installation
323323

324324
* If you have added new files or directories, or reorganized existing
325325
ones, make sure the new files are included in the match patterns in
326-
:file:`MANIFEST.in`, and/or in *package_data* in :file:`setup.py`.
326+
in *package_data* in :file:`setupext.py`.
327327

328328
C/C++ extensions
329329
----------------

‎doc/devel/release_guide.rst

Copy file name to clipboardExpand all lines: doc/devel/release_guide.rst
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,12 @@ Finally, push the tag to GitHub::
176176

177177
Congratulations, the scariest part is done!
178178

179-
.. [#] The tarball that is provided by GitHub is produced using `git
180-
archive <https://git-scm.com/docs/git-archive>`__. We use
181-
`versioneer <https://github.com/warner/python-versioneer>`__
182-
which uses a format string in
179+
.. [#] The tarball that is provided by GitHub is produced using `git archive`_.
180+
We use setuptools_scm_ which uses a format string in
183181
:file:`lib/matplotlib/_version.py` to have ``git`` insert a
184182
list of references to exported commit (see
185183
:file:`.gitattributes` for the configuration). This string is
186-
then used by ``versioneer`` to produce the correct version,
184+
then used by ``setuptools_scm`` to produce the correct version,
187185
based on the git tag, when users install from the tarball.
188186
However, if there is a branch pointed at the tagged commit,
189187
then the branch name will also be included in the tarball.
@@ -195,6 +193,8 @@ Congratulations, the scariest part is done!
195193
196194
git archive v2.0.0 -o matplotlib-2.0.0.tar.gz --prefix=matplotlib-2.0.0/
197195
196+
.. _git archive: https://git-scm.com/docs/git-archive
197+
.. _setuptools_scm: https://github.com/pypa/setuptools_scm
198198

199199
If this is a final release, also create a 'doc' branch (this is not
200200
done for pre-releases)::

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+29-10Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,15 @@
102102
import tempfile
103103
import warnings
104104

105+
import numpy
106+
105107
# cbook must import matplotlib only within function
106108
# definitions, so it is safe to import from it here.
107-
from . import _api, cbook, docstring, rcsetup
109+
from . import _api, _version, cbook, docstring, rcsetup
108110
from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
109111
from matplotlib.cbook import mplDeprecation # deprecated
110112
from matplotlib.rcsetup import validate_backend, cycler
111113

112-
import numpy
113-
114-
# Get the version from the _version.py versioneer file. For a git checkout,
115-
# this is computed based on the number of commits since the last tag.
116-
from ._version import get_versions
117-
__version__ = str(get_versions()['version'])
118-
del get_versions
119114

120115
_log = logging.getLogger(__name__)
121116

@@ -135,6 +130,27 @@
135130
}"""
136131

137132

133+
def __getattr__(name):
134+
if name == "__version__":
135+
import setuptools_scm
136+
global __version__ # cache it.
137+
# Only shell out to a git subprocess if really needed, and not on a
138+
# shallow clone, such as those used by CI, as the latter would trigger
139+
# a warning from setuptools_scm.
140+
root = Path(__file__).resolve().parents[2]
141+
if (root / ".git").exists() and not (root / ".git/shallow").exists():
142+
__version__ = setuptools_scm.get_version(
143+
root=root,
144+
version_scheme="post-release",
145+
local_scheme="node-and-date",
146+
fallback_version=_version.version,
147+
)
148+
else: # Get the version from the _version.py setuptools_scm file.
149+
__version__ = _version.version
150+
return __version__
151+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
152+
153+
138154
def _check_versions():
139155

140156
# Quickfix to ensure Microsoft Visual C++ redistributable
@@ -724,6 +740,7 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
724740
fail_on_error : bool, default: False
725741
Whether invalid entries should result in an exception or a warning.
726742
"""
743+
import matplotlib as mpl
727744
rc_temp = {}
728745
with _open_file_or_url(fname) as fd:
729746
try:
@@ -770,7 +787,10 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
770787
version, name=key, alternative=alt_key, obj_type='rcparam',
771788
addendum="Please update your matplotlibrc.")
772789
else:
773-
version = 'master' if '.post' in __version__ else f'v{__version__}'
790+
# __version__ must be looked up as an attribute to trigger the
791+
# module-level __getattr__.
792+
version = ('master' if '.post' in mpl.__version__
793+
else f'v{mpl.__version__}')
774794
_log.warning("""
775795
Bad key %(key)s in file %(fname)s, line %(line_no)s (%(line)r)
776796
You probably need to get an updated matplotlibrc file from
@@ -1385,7 +1405,6 @@ def inner(ax, *args, data=None, **kwargs):
13851405
return inner
13861406

13871407

1388-
_log.debug('matplotlib version %s', __version__)
13891408
_log.debug('interactive is %s', is_interactive())
13901409
_log.debug('platform is %s', sys.platform)
13911410
_log.debug('loaded modules: %s', list(sys.modules))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.