|
66 | 66 | ]
|
67 | 67 |
|
68 | 68 |
|
| 69 | +cmdclass = versioneer.get_cmdclass() |
| 70 | + |
| 71 | + |
69 | 72 | # From https://bugs.python.org/issue26689
|
70 | 73 | def has_flag(self, flagname):
|
71 | 74 | """Return whether a flag name is supported on the specified compiler."""
|
@@ -200,9 +203,37 @@ def build_extensions(self):
|
200 | 203 | return super().build_extensions()
|
201 | 204 |
|
202 | 205 |
|
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 | + |
204 | 233 | cmdclass['test'] = NoopTestCommand
|
205 | 234 | cmdclass['build_ext'] = BuildExtraLibraries
|
| 235 | +cmdclass['build_py'] = BuildPy |
| 236 | +cmdclass['sdist'] = Sdist |
206 | 237 |
|
207 | 238 |
|
208 | 239 | package_data = {} # Will be filled below by the various components.
|
@@ -243,18 +274,6 @@ def build_extensions(self):
|
243 | 274 | package_data.setdefault(key, [])
|
244 | 275 | package_data[key] = list(set(val + package_data[key]))
|
245 | 276 |
|
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 |
| - |
258 | 277 | setup( # Finally, pass this all along to distutils to do the heavy lifting.
|
259 | 278 | name="matplotlib",
|
260 | 279 | version=__version__,
|
|
0 commit comments