Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c80b465

Browse files
QuLogicissamarabi
authored andcommitted
Try to generate a version from Meson
1 parent ec3ee45 commit c80b465

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

lib/matplotlib/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,20 @@ def _get_version():
219219
if ((root / ".matplotlib-repo").exists()
220220
and (root / ".git").exists()
221221
and not (root / ".git/shallow").exists()):
222-
import setuptools_scm
223-
return setuptools_scm.get_version(
224-
root=root,
225-
version_scheme="release-branch-semver",
226-
local_scheme="node-and-date",
227-
fallback_version=_version.version,
228-
)
229-
else: # Get the version from the _version.py setuptools_scm file.
230-
return _version.version
222+
try:
223+
import setuptools_scm
224+
except ImportError:
225+
pass
226+
else:
227+
return setuptools_scm.get_version(
228+
root=root,
229+
version_scheme="release-branch-semver",
230+
local_scheme="node-and-date",
231+
fallback_version=_version.version,
232+
)
233+
# Get the version from the _version.py file if not in repo or setuptools_scm is
234+
# unavailable.
235+
return _version.version
231236

232237

233238
@_api.caching_module_getattr

lib/matplotlib/_version.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version = @VCS_TAG@

lib/matplotlib/meson.build

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ typing_sources = [
138138
py3.install_sources(python_sources, typing_sources,
139139
subdir: 'matplotlib')
140140

141+
fs = import('fs')
142+
if fs.exists('_version.py')
143+
py3.install_sources('_version.py', subdir: 'matplotlib')
144+
else
145+
cfg = configuration_data()
146+
cfg.set_quoted('VCS_TAG', meson.project_version())
147+
configure_file(
148+
input: '_version.py.in', output: '_version.py',
149+
configuration: cfg,
150+
install: true,
151+
install_tag: 'python-runtime',
152+
install_dir: py3.get_install_dir() / 'matplotlib')
153+
endif
154+
141155
subdir('_api')
142156
subdir('axes')
143157
subdir('backends')

0 commit comments

Comments
 (0)