Skip to content

Remove matplotlibrc.template. #19603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ Thumbs.db

# Things specific to this project #
###################################
lib/matplotlib/mpl-data/matplotlib.conf
lib/matplotlib/mpl-data/matplotlibrc
tutorials/intermediate/CL01.png
tutorials/intermediate/CL02.png

Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,11 @@ def test_backend_fallback_headful(tmpdir):
env = {**os.environ, "MPLBACKEND": "", "MPLCONFIGDIR": str(tmpdir)}
backend = subprocess.check_output(
[sys.executable, "-c",
"import matplotlib.pyplot; print(matplotlib.get_backend())"],
"import matplotlib as mpl; "
"assert dict.__getitem__(mpl.rcParams, 'backend') == "
"mpl.rcsetup._auto_backend_sentinel; "
"import matplotlib.pyplot; "
"print(matplotlib.get_backend())"],
env=env, universal_newlines=True)
# The actual backend will depend on what's installed, but at least tkagg is
# present.
Expand Down
59 changes: 37 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@
import subprocess

from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext as BuildExtCommand
from setuptools.command.test import test as TestCommand
import setuptools.command.build_ext
import setuptools.command.build_py
import setuptools.command.test
import setuptools.command.sdist

# The setuptools version of sdist adds a setup.cfg file to the tree.
# We don't want that, so we simply remove it, and it will fall back to
# vanilla distutils.
try:
from setuptools.command import sdist
except ImportError:
pass
else:
del sdist.sdist.make_release_tree
del setuptools.command.sdist.sdist.make_release_tree

from distutils.errors import CompileError
from distutils.dist import Distribution
Expand Down Expand Up @@ -75,13 +72,13 @@ def has_flag(self, flagname):
return True


class NoopTestCommand(TestCommand):
class NoopTestCommand(setuptools.command.test.test):
def __init__(self, dist):
print("Matplotlib does not support running tests with "
"'python setup.py test'. Please run 'pytest'.")


class BuildExtraLibraries(BuildExtCommand):
class BuildExtraLibraries(setuptools.command.build_ext.build_ext):
def finalize_options(self):
self.distribution.ext_modules[:] = [
ext
Expand Down Expand Up @@ -196,6 +193,34 @@ def build_extensions(self):
return super().build_extensions()


def update_matplotlibrc(path):
# Update the matplotlibrc file if packagers want to change the default
# backend.
template_lines = path.read_text().splitlines(True)
backend_line_idx, = [ # Also asserts that there is a single such line.
idx for idx, line in enumerate(template_lines)
if line.startswith("#backend:")]
template_lines[backend_line_idx] = (
"#backend: {}".format(setupext.options["backend"])
if setupext.options["backend"]
else "#backend:")
path.write_text("".join(template_lines))


class BuildPy(setuptools.command.build_py.build_py):
def run(self):
super().run()
update_matplotlibrc(
Path(self.build_lib, "matplotlib/mpl-data/matplotlibrc"))


class Sdist(setuptools.command.sdist.sdist):
def make_release_tree(self, base_dir, files):
super().make_release_tree(base_dir, files)
update_matplotlibrc(
Path(base_dir, "lib/matplotlib/mpl-data/matplotlibrc"))


package_data = {} # Will be filled below by the various components.

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

# Write the default matplotlibrc file
with open('matplotlibrc.template') as fd:
template_lines = fd.read().splitlines(True)
backend_line_idx, = [ # Also asserts that there is a single such line.
idx for idx, line in enumerate(template_lines)
if line.startswith('#backend:')]
if setupext.options['backend']:
template_lines[backend_line_idx] = (
'backend: {}'.format(setupext.options['backend']))
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
fd.write(''.join(template_lines))

setup( # Finally, pass this all along to distutils to do the heavy lifting.
name="matplotlib",
description="Python plotting package",
Expand Down Expand Up @@ -316,5 +329,7 @@ def build_extensions(self):
cmdclass={
"test": NoopTestCommand,
"build_ext": BuildExtraLibraries,
"build_py": BuildPy,
"sdist": Sdist,
},
)
2 changes: 1 addition & 1 deletion tutorials/introductory/customizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
# A sample matplotlibrc file
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# .. literalinclude:: ../../../matplotlibrc.template
# .. literalinclude:: ../../../lib/matplotlib/mpl-data/matplotlibrc
#
#
# .. _ggplot: https://ggplot2.tidyverse.org/
Expand Down