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

Skip to content

Commit 2a3c65a

Browse files
committed
Remove matplotlibrc.template.
1 parent fe27023 commit 2a3c65a

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ Thumbs.db
5656

5757
# Things specific to this project #
5858
###################################
59-
lib/matplotlib/mpl-data/matplotlib.conf
60-
lib/matplotlib/mpl-data/matplotlibrc
6159
tutorials/intermediate/CL01.png
6260
tutorials/intermediate/CL02.png
6361

File renamed without changes.

lib/matplotlib/tests/test_rcparams.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,11 @@ def test_backend_fallback_headful(tmpdir):
496496
env = {**os.environ, "MPLBACKEND": "", "MPLCONFIGDIR": str(tmpdir)}
497497
backend = subprocess.check_output(
498498
[sys.executable, "-c",
499-
"import matplotlib.pyplot; print(matplotlib.get_backend())"],
499+
"import matplotlib as mpl; "
500+
"assert dict.__getitem__(mpl.rcParams, 'backend') == "
501+
"mpl.rcsetup._auto_backend_sentinel; "
502+
"import matplotlib.pyplot; "
503+
"print(matplotlib.get_backend())"],
500504
env=env, universal_newlines=True)
501505
# The actual backend will depend on what's installed, but at least tkagg is
502506
# present.

setup.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@
3030
import subprocess
3131

3232
from setuptools import setup, find_packages, Extension
33-
from setuptools.command.build_ext import build_ext as BuildExtCommand
34-
from setuptools.command.test import test as TestCommand
33+
import setuptools.command.build_ext
34+
import setuptools.command.build_py
35+
import setuptools.command.test
36+
import setuptools.command.sdist
3537

3638
# The setuptools version of sdist adds a setup.cfg file to the tree.
3739
# We don't want that, so we simply remove it, and it will fall back to
3840
# vanilla distutils.
39-
try:
40-
from setuptools.command import sdist
41-
except ImportError:
42-
pass
43-
else:
44-
del sdist.sdist.make_release_tree
41+
del setuptools.command.sdist.sdist.make_release_tree
4542

4643
from distutils.errors import CompileError
4744
from distutils.dist import Distribution
@@ -75,13 +72,13 @@ def has_flag(self, flagname):
7572
return True
7673

7774

78-
class NoopTestCommand(TestCommand):
75+
class NoopTestCommand(setuptools.command.test.test):
7976
def __init__(self, dist):
8077
print("Matplotlib does not support running tests with "
8178
"'python setup.py test'. Please run 'pytest'.")
8279

8380

84-
class BuildExtraLibraries(BuildExtCommand):
81+
class BuildExtraLibraries(setuptools.command.build_ext.build_ext):
8582
def finalize_options(self):
8683
self.distribution.ext_modules[:] = [
8784
ext
@@ -196,6 +193,34 @@ def build_extensions(self):
196193
return super().build_extensions()
197194

198195

196+
def update_matplotlibrc(path):
197+
# Update the matplotlibrc file if packagers want to change the default
198+
# backend.
199+
template_lines = path.read_text().splitlines(True)
200+
backend_line_idx, = [ # Also asserts that there is a single such line.
201+
idx for idx, line in enumerate(template_lines)
202+
if line.startswith("#backend:")]
203+
template_lines[backend_line_idx] = (
204+
"#backend: {}".format(setupext.options["backend"])
205+
if setupext.options["backend"]
206+
else "#backend:")
207+
path.write_text("".join(template_lines))
208+
209+
210+
class BuildPy(setuptools.command.build_py.build_py):
211+
def run(self):
212+
super().run()
213+
update_matplotlibrc(
214+
Path(self.build_lib, "matplotlib/mpl-data/matplotlibrc"))
215+
216+
217+
class Sdist(setuptools.command.sdist.sdist):
218+
def make_release_tree(self, base_dir, files):
219+
super().make_release_tree(base_dir, files)
220+
update_matplotlibrc(
221+
Path(base_dir, "lib/matplotlib/mpl-data/matplotlibrc"))
222+
223+
199224
package_data = {} # Will be filled below by the various components.
200225

201226
# If the user just queries for information, don't bother figuring out which
@@ -234,18 +259,6 @@ def build_extensions(self):
234259
package_data.setdefault(key, [])
235260
package_data[key] = list(set(val + package_data[key]))
236261

237-
# Write the default matplotlibrc file
238-
with open('matplotlibrc.template') as fd:
239-
template_lines = fd.read().splitlines(True)
240-
backend_line_idx, = [ # Also asserts that there is a single such line.
241-
idx for idx, line in enumerate(template_lines)
242-
if line.startswith('#backend:')]
243-
if setupext.options['backend']:
244-
template_lines[backend_line_idx] = (
245-
'backend: {}'.format(setupext.options['backend']))
246-
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
247-
fd.write(''.join(template_lines))
248-
249262
setup( # Finally, pass this all along to distutils to do the heavy lifting.
250263
name="matplotlib",
251264
description="Python plotting package",
@@ -316,5 +329,7 @@ def build_extensions(self):
316329
cmdclass={
317330
"test": NoopTestCommand,
318331
"build_ext": BuildExtraLibraries,
332+
"build_py": BuildPy,
333+
"sdist": Sdist,
319334
},
320335
)

tutorials/introductory/customizing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
# A sample matplotlibrc file
201201
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
202202
#
203-
# .. literalinclude:: ../../../matplotlibrc.template
203+
# .. literalinclude:: ../../../lib/matplotlib/mpl-data/matplotlibrc
204204
#
205205
#
206206
# .. _ggplot: https://ggplot2.tidyverse.org/

0 commit comments

Comments
 (0)