|
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,38 @@ 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 | + template_lines[backend_line_idx] = ( |
| 214 | + "#backend: {}".format(setupext.options["backend"]) |
| 215 | + if setupext.options["backend"] |
| 216 | + else "#backend:") |
| 217 | + path.write_text("".join(template_lines)) |
| 218 | + |
| 219 | + |
| 220 | +class BuildPy(cmdclass['build_py']): |
| 221 | + def run(self): |
| 222 | + super().run() |
| 223 | + update_matplotlibrc( |
| 224 | + Path(self.build_lib, "matplotlib/mpl-data/matplotlibrc")) |
| 225 | + |
| 226 | + |
| 227 | +class Sdist(cmdclass['sdist']): |
| 228 | + def make_release_tree(self, base_dir, files): |
| 229 | + super().make_release_tree(base_dir, files) |
| 230 | + update_matplotlibrc( |
| 231 | + Path(base_dir, "lib/matplotlib/mpl-data/matplotlibrc")) |
| 232 | + |
| 233 | + |
204 | 234 | cmdclass['test'] = NoopTestCommand |
205 | 235 | cmdclass['build_ext'] = BuildExtraLibraries |
| 236 | +cmdclass['build_py'] = BuildPy |
| 237 | +cmdclass['sdist'] = Sdist |
206 | 238 |
|
207 | 239 |
|
208 | 240 | package_data = {} # Will be filled below by the various components. |
@@ -243,18 +275,6 @@ def build_extensions(self): |
243 | 275 | package_data.setdefault(key, []) |
244 | 276 | package_data[key] = list(set(val + package_data[key])) |
245 | 277 |
|
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 | 278 | setup( # Finally, pass this all along to distutils to do the heavy lifting. |
259 | 279 | name="matplotlib", |
260 | 280 | version=__version__, |
|
0 commit comments