|
3 | 3 | """Build the Python docs for various branches and various languages.
|
4 | 4 |
|
5 | 5 | Without any arguments builds docs for all active versions and
|
6 |
| -languages configured in the config.ini file. |
| 6 | +languages. |
| 7 | +
|
| 8 | +Languages are stored in `config.toml` while versions are discovered |
| 9 | +from the devguide. |
7 | 10 |
|
8 | 11 | -q selects "quick build", which means to build only HTML.
|
9 | 12 |
|
|
20 | 23 | """
|
21 | 24 |
|
22 | 25 | from argparse import ArgumentParser
|
23 |
| -import configparser |
24 | 26 | from contextlib import suppress
|
25 | 27 | from dataclasses import dataclass
|
26 | 28 | import filecmp
|
|
47 | 49 | import zc.lockfile
|
48 | 50 | import jinja2
|
49 | 51 | import requests
|
| 52 | +from tomlkit import parse |
| 53 | + |
50 | 54 |
|
51 | 55 | HERE = Path(__file__).resolve().parent
|
52 | 56 |
|
@@ -223,71 +227,6 @@ def filter(languages, language_tags=None):
|
223 | 227 | return languages
|
224 | 228 |
|
225 | 229 |
|
226 |
| - |
227 |
| - |
228 |
| -XELATEX_DEFAULT = ( |
229 |
| - "-D latex_engine=xelatex", |
230 |
| - "-D latex_elements.inputenc=", |
231 |
| - "-D latex_elements.fontenc=", |
232 |
| -) |
233 |
| - |
234 |
| -LUALATEX_FOR_JP = ( |
235 |
| - "-D latex_engine=lualatex", |
236 |
| - "-D latex_elements.inputenc=", |
237 |
| - "-D latex_elements.fontenc=", |
238 |
| - "-D latex_docclass.manual=ltjsbook", |
239 |
| - "-D latex_docclass.howto=ltjsarticle", |
240 |
| - |
241 |
| - # supress polyglossia warnings |
242 |
| - "-D latex_elements.polyglossia=", |
243 |
| - "-D latex_elements.fontpkg=", |
244 |
| - |
245 |
| - # preamble |
246 |
| - "-D latex_elements.preamble=" |
247 |
| - |
248 |
| - # Render non-Japanese letters with luatex |
249 |
| - # https://gist.github.com/zr-tex8r/e0931df922f38fbb67634f05dfdaf66b |
250 |
| - r"\\usepackage[noto-otf]{luatexja-preset}" |
251 |
| - r"\\usepackage{newunicodechar}" |
252 |
| - r"\\newunicodechar{^^^^212a}{K}" |
253 |
| - |
254 |
| - # Workaround for the luatex-ja issue (Thanks to @jfbu) |
255 |
| - # https://github.com/sphinx-doc/sphinx/issues/11179#issuecomment-1420715092 |
256 |
| - # https://osdn.net/projects/luatex-ja/ticket/47321 |
257 |
| - r"\\makeatletter" |
258 |
| - r"\\titleformat{\\subsubsection}{\\normalsize\\py@HeaderFamily}" |
259 |
| - r"{\\py@TitleColor\\thesubsubsection}{0.5em}{\\py@TitleColor}" |
260 |
| - r"\\titleformat{\\paragraph}{\\normalsize\\py@HeaderFamily}" |
261 |
| - r"{\\py@TitleColor\\theparagraph}{0.5em}{\\py@TitleColor}" |
262 |
| - r"\\titleformat{\\subparagraph}{\\normalsize\\py@HeaderFamily}" |
263 |
| - r"{\\py@TitleColor\\thesubparagraph}{0.5em}{\\py@TitleColor}" |
264 |
| - r"\\makeatother" |
265 |
| - |
266 |
| - # subpress warning: (fancyhdr)Make it at least 16.4pt |
267 |
| - r"\\setlength{\\footskip}{16.4pt}" |
268 |
| -) |
269 |
| - |
270 |
| -XELATEX_WITH_FONTSPEC = ( |
271 |
| - "-D latex_engine=xelatex", |
272 |
| - "-D latex_elements.inputenc=", |
273 |
| - r"-D latex_elements.fontenc=\\usepackage{fontspec}", |
274 |
| -) |
275 |
| - |
276 |
| -XELATEX_FOR_KOREAN = ( |
277 |
| - "-D latex_engine=xelatex", |
278 |
| - "-D latex_elements.inputenc=", |
279 |
| - "-D latex_elements.fontenc=", |
280 |
| - r"-D latex_elements.preamble=\\usepackage{kotex}\\setmainhangulfont" |
281 |
| - r"{UnBatang}\\setsanshangulfont{UnDotum}\\setmonohangulfont{UnTaza}", |
282 |
| -) |
283 |
| - |
284 |
| -XELATEX_WITH_CJK = ( |
285 |
| - "-D latex_engine=xelatex", |
286 |
| - "-D latex_elements.inputenc=", |
287 |
| - r"-D latex_elements.fontenc=\\usepackage{xeCJK}", |
288 |
| -) |
289 |
| - |
290 |
| - |
291 | 230 | def run(cmd, cwd=None) -> subprocess.CompletedProcess:
|
292 | 231 | """Like subprocess.run, with logging before and after the command execution."""
|
293 | 232 | cmd = [str(arg) for arg in cmd]
|
@@ -626,7 +565,8 @@ def parse_args():
|
626 | 565 | parser.add_argument(
|
627 | 566 | "--languages",
|
628 | 567 | nargs="*",
|
629 |
| - help="Language translation, as a PEP 545 language tag like" " 'fr' or 'pt-br'. " |
| 568 | + help="Language translation, as a PEP 545 language tag like" |
| 569 | + " 'fr' or 'pt-br'. " |
630 | 570 | "Use 'all' to build all of them (it's the default behavior).",
|
631 | 571 | metavar="fr",
|
632 | 572 | )
|
@@ -1061,20 +1001,18 @@ def parse_versions_from_devguide():
|
1061 | 1001 |
|
1062 | 1002 |
|
1063 | 1003 | def parse_languages_from_config():
|
1064 |
| - config = configparser.ConfigParser() |
1065 |
| - config.read(HERE / "config.ini") |
1066 |
| - versions, languages = [], [] |
1067 |
| - for name, section in config.items(): |
1068 |
| - if name == "DEFAULT": |
1069 |
| - continue |
| 1004 | + """Read config.toml to discover languages to build.""" |
| 1005 | + config = tomlkit.parse((HERE / "config.toml").read_text(encoding="UTF-8")) |
| 1006 | + languages = [] |
| 1007 | + for name, section in config["languages"].items(): |
1070 | 1008 | languages.append(
|
1071 | 1009 | Language(
|
1072 | 1010 | name,
|
1073 | 1011 | section.get("iso639_tag", name),
|
1074 | 1012 | section["name"],
|
1075 |
| - section.getboolean("in_prod", True), |
1076 |
| - sphinxopts=globals()[section.get("sphinxopts", "XELATEX_DEFAULT")], |
1077 |
| - html_only=section.get("html_only", False), |
| 1013 | + section.get("in_prod", config["defaults"]["in_prod"]), |
| 1014 | + sphinxopts=section.get("sphinxopts", config["defaults"]["sphinxopts"]), |
| 1015 | + html_only=section.get("html_only", config["defaults"]["html_only"]), |
1078 | 1016 | )
|
1079 | 1017 | )
|
1080 | 1018 | return languages
|
@@ -1129,8 +1067,6 @@ def main():
|
1129 | 1067 | lock.close()
|
1130 | 1068 |
|
1131 | 1069 |
|
1132 |
| - |
1133 |
| - |
1134 | 1070 | if __name__ == "__main__":
|
1135 | 1071 | all_built_successfully = main()
|
1136 | 1072 | sys.exit(EX_OK if all_built_successfully else EX_FAILURE)
|
0 commit comments