8000 Implement backend setup in matplotlibrc · matplotlib/matplotlib@9f19159 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f19159

Browse files
committed
Implement backend setup in matplotlibrc
1 parent e65e538 commit 9f19159

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

lib/matplotlib/meson.build

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,13 @@ endif
158158
subdir('_api')
159159
subdir('axes')
160160
subdir('backends')
161+
subdir('mpl-data')
161162
subdir('projections')
162163
subdir('sphinxext')
163164
subdir('style')
164165
subdir('testing')
165166
subdir('tri')
166167

167-
install_subdir(
168-
'mpl-data',
169-
install_tag: 'data',
170-
install_dir: py3.get_install_dir(subdir: 'matplotlib'))
171168
install_subdir('tests',
172169
install_tag: 'tests',
173170
install_dir: py3.get_install_dir(subdir: 'matplotlib'))

lib/matplotlib/mpl-data/meson.build

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
custom_target('matplotlibrc',
2+
command: [
3+
find_program(meson.project_source_root() / 'tools/generate_matplotlibrc.py'),
4+
'@INPUT@',
5+
'@OUTPUT@',
6+
get_option('rcParams-backend')
7+
],
8+
input: 'matplotlibrc',
9+
output: 'matplotlibrc',
10+
install: true,
11+
install_tag: 'data',
12+
install_dir: py3.get_install_dir(subdir: 'matplotlib/mpl-data'))
13+
14+
install_data(
15+
'kpsewhich.lua',
16+
install_tag: 'data',
17+
install_dir: py3.get_install_dir(subdir: 'matplotlib/mpl-data'))
18+
19+
foreach dir : ['fonts', 'images', 'plot_directive', 'sample_data', 'stylelib']
20+
install_subdir(
21+
dir,
22+
install_tag: 'data',
23+
install_dir: py3.get_install_dir(subdir: 'matplotlib/mpl-data'))
24+
endforeach

tools/generate_matplotlibrc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
"""
3+
Generate matplotlirc for installs.
4+
5+
If packagers want to change the default backend, insert a `#backend: ...` line.
6+
Otherwise, use the default `##backend: Agg` which has no effect even after
7+
decommenting, which allows _auto_backend_sentinel to be filled in at import
8+
time.
9+
"""
10+
11+
import sys
12+
from pathlib import Path
13+
14+
15+
if len(sys.argv) < 4:
16+
raise SystemExit('usage: {sys.argv[0]} <input> <output> <backend>')
17+
18+
input = Path(sys.argv[1])
19+
output = Path(sys.argv[2])
20+
backend = sys.argv[3]
21+
22+
template_lines = input.read_text(encoding="utf-8").splitlines(True)
23+
backend_line_idx, = [ # Also asserts that there is a single such line.
24+
idx for idx, line in enumerate(template_lines)
25+
if "#backend:" in line]
26+
template_lines[backend_line_idx] = (
27+
f"#backend: {backend}\n" if backend else "##backend: Agg\n")
28+
output.write_text("".join(template_lines), encoding="utf-8")

0 commit comments

Comments
 (0)
0