File: generate_matplotlibrc.py

package info (click to toggle)
matplotlib 3.10.1%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,352 kB
  • sloc: python: 147,118; cpp: 62,988; objc: 1,679; ansic: 1,426; javascript: 786; makefile: 104; sh: 53
file content (28 lines) | stat: -rwxr-xr-x 917 bytes parent folder | download
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")