Skip to content

Commit 24b7c10

Browse files
committed
Remove matplotlibrc.template.
1 parent 2e248f5 commit 24b7c10

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ Thumbs.db
5454

5555
# Things specific to this project #
5656
###################################
57-
lib/matplotlib/mpl-data/matplotlib.conf
58-
lib/matplotlib/mpl-data/matplotlibrc
5957
tutorials/intermediate/CL01.png
6058
tutorials/intermediate/CL02.png
6159

File renamed without changes.

setup.py

+32-13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
]
6767

6868

69+
cmdclass = versioneer.get_cmdclass()
70+
71+
6972
# From https://bugs.python.org/issue26689
7073
def has_flag(self, flagname):
7174
"""Return whether a flag name is supported on the specified compiler."""
@@ -200,9 +203,37 @@ def build_extensions(self):
200203
return super().build_extensions()
201204

202205

203-
cmdclass = versioneer.get_cmdclass()
206+
def update_matplotlibrc(path):
207+
# Update the matplotlibrc file if packagers want to change the default
208+
# backend.
209+
template_lines = path.read_text().splitlines(True)
210+
backend_line_idx, = [ # Also asserts that there is a single such line.
211+
idx for idx, line in enumerate(template_lines)
212+
if line.startswith("#backend:")]
213+
if setupext.options["backend"]:
214+
template_lines[backend_line_idx] = (
215+
"#backend: {}".format(setupext.options["backend"]))
216+
path.write_text("".join(template_lines))
217+
218+
219+
class BuildPy(cmdclass['build_py']):
220+
def run(self):
221+
super().run()
222+
update_matplotlibrc(
223+
Path(self.build_lib, "matplotlib/mpl-data/matplotlibrc"))
224+
225+
226+
class Sdist(cmdclass['sdist']):
227+
def make_release_tree(self, base_dir, files):
228+
super().make_release_tree(base_dir, files)
229+
update_matplotlibrc(
230+
Path(base_dir, "lib/matplotlib/mpl-data/matplotlibrc"))
231+
232+
204233
cmdclass['test'] = NoopTestCommand
205234
cmdclass['build_ext'] = BuildExtraLibraries
235+
cmdclass['build_py'] = BuildPy
236+
cmdclass['sdist'] = Sdist
206237

207238

208239
package_data = {} # Will be filled below by the various components.
@@ -243,18 +274,6 @@ def build_extensions(self):
243274
package_data.setdefault(key, [])
244275
package_data[key] = list(set(val + package_data[key]))
245276

246-
# Write the default matplotlibrc file
247-
with open('matplotlibrc.template') as fd:
248-
template_lines = fd.read().splitlines(True)
249-
backend_line_idx, = [ # Also asserts that there is a single such line.
250-
idx for idx, line in enumerate(template_lines)
251-
if line.startswith('#backend:')]
252-
if setupext.options['backend']:
253-
template_lines[backend_line_idx] = (
254-
'backend: {}'.format(setupext.options['backend']))
255-
with open('lib/matplotlib/mpl-data/matplotlibrc', 'w') as fd:
256-
fd.write(''.join(template_lines))
257-
258277
setup( # Finally, pass this all along to distutils to do the heavy lifting.
259278
name="matplotlib",
260279
version=__version__,

0 commit comments

Comments
 (0)