-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Expand file tree
/
Copy pathgenerate_matplotlibrc.py
More file actions
executable file
·28 lines (22 loc) · 917 Bytes
/
generate_matplotlibrc.py
File metadata and controls
executable file
·28 lines (22 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
"""
Generate matplotlirc for installs.
If packagers want to change the default backend, insert a `#backend: ...` line.
Otherwise, use the default `##backend: Agg` which has no effect even after
decommenting, which allows _auto_backend_sentinel to be filled in at import
time.
"""
import sys
from pathlib import Path
if len(sys.argv) != 4:
raise SystemExit('usage: {sys.argv[0]} <input> <output> <backend>')
input = Path(sys.argv[1])
output = Path(sys.argv[2])
backend = sys.argv[3]
template_lines = input.read_text(encoding="utf-8").splitlines(True)
backend_line_idx, = ( # Also asserts that there is a single such line.
idx for idx, line in enumerate(template_lines)
if "#backend:" in line)
template_lines[backend_line_idx] = (
f"#backend: {backend}\n" if backend not in ['', 'auto'] else "##backend: Agg\n")
output.write_text("".join(template_lines), encoding="utf-8")