2
2
3
3
"""Build the Python docs for various branches and various languages.
4
4
5
- Usage:
6
-
7
- build_docs.py [-h] [-d] [-q] [-b 3.7] [-r BUILD_ROOT] [-w WWW_ROOT]
8
- [--skip-cache-invalidation] [--group GROUP] [--git]
9
- [--log-directory LOG_DIRECTORY]
10
- [--languages [fr [fr ...]]]
11
-
12
-
13
5
Without any arguments builds docs for all active versions configured in the
14
6
global VERSIONS list and all languages configured in the LANGUAGES list,
15
7
ignoring the -d flag as it's given in the VERSIONS configuration.
@@ -106,7 +98,7 @@ def title(self):
106
98
# their doc, they don't follow Sphinx deprecations.
107
99
VERSIONS = [
108
100
Version ("2.7" , "2.7" , "EOL" , sphinx_version = "2.3.1" ),
109
- Version ("3.5" , "3.5" , "security-fixes " , sphinx_version = "1.8.4" ),
101
+ Version ("3.5" , "3.5" , "EOL " , sphinx_version = "1.8.4" ),
110
102
Version ("3.6" , "3.6" , "security-fixes" , sphinx_version = "2.3.1" ),
111
103
Version ("3.7" , "3.7" , "security-fixes" , sphinx_version = "2.3.1" ),
112
104
Version ("3.8" , "3.8" , "stable" , sphinx_version = "2.4.4" ),
@@ -427,6 +419,8 @@ def build_one(
427
419
"-D gettext_compact=0" ,
428
420
)
429
421
)
422
+ if version .status == "EOL" :
423
+ sphinxopts .append ("-D html_context.outdated=1" )
430
424
git_clone ("https://github.com/python/cpython.git" , checkout , version .branch )
431
425
maketarget = (
432
426
"autobuild-"
@@ -472,14 +466,14 @@ def build_one(
472
466
logging .info ("Build done for version: %s, language: %s" , version .name , language .tag )
473
467
474
468
475
- def build_venv (build_root , version ):
469
+ def build_venv (build_root , version , theme ):
476
470
"""Build a venv for the specific version.
477
471
This is used to pin old Sphinx versions to old cpython branches.
478
472
"""
479
473
requirements = [
480
474
"blurb" ,
481
475
"jieba" ,
482
- "python-docs- theme" ,
476
+ theme ,
483
477
"sphinx=={}" .format (version .sphinx_version ),
484
478
]
485
479
venv_path = os .path .join (build_root , "venv-with-sphinx-" + version .sphinx_version )
@@ -491,13 +485,18 @@ def build_venv(build_root, version):
491
485
return venv_path
492
486
493
487
494
- def build_robots_txt (www_root ):
488
+ def build_robots_txt (www_root , group , skip_cache_invalidation ):
489
+ robots_file = os .path .join (www_root , "robots.txt" )
495
490
with open (HERE / "templates" / "robots.txt" ) as robots_txt_template_file :
496
- with open (os . path . join ( www_root , "robots.txt" ) , "w" ) as robots_txt_file :
491
+ with open (robots_file , "w" ) as robots_txt_file :
497
492
template = jinja2 .Template (robots_txt_template_file .read ())
498
493
robots_txt_file .write (
499
494
template .render (languages = LANGUAGES , versions = VERSIONS ) + "\n "
500
495
)
496
+ os .chmod (robots_file , 0o775 )
497
+ shell_out (["chgrp" , group , robots_file ])
498
+ if not skip_cache_invalidation :
499
+ shell_out (["curl" , "-XPURGE" , "https://docs.python.org/robots.txt" ])
501
500
502
501
503
502
def build_sitemap (www_root ):
@@ -621,13 +620,21 @@ def head(lines, n=10):
621
620
622
621
623
622
def version_info ():
624
- platex_version = head (
625
- subprocess .check_output (["platex" , "--version" ], universal_newlines = True ), n = 3
626
- )
623
+ try :
624
+ platex_version = head (
625
+ subprocess .check_output (["platex" , "--version" ], universal_newlines = True ),
626
+ n = 3 ,
627
+ )
628
+ except FileNotFoundError :
629
+ platex_version = "Not installed."
627
630
628
- xelatex_version = head (
629
- subprocess .check_output (["xelatex" , "--version" ], universal_newlines = True ), n = 2
630
- )
631
+ try :
632
+ xelatex_version = head (
633
+ subprocess .check_output (["xelatex" , "--version" ], universal_newlines = True ),
634
+ n = 2 ,
635
+ )
636
+ except FileNotFoundError :
637
+ xelatex_version = "Not installed."
631
638
print (
632
639
"""build_docs: {VERSION}
633
640
@@ -717,6 +724,12 @@ def parse_args():
717
724
action = "store_true" ,
718
725
help = "Get build_docs and dependencies version info" ,
719
726
)
727
+ parser .add_argument (
728
+ "--theme" ,
729
+ default = "python-docs-theme" ,
730
+ help = "Python package to use for python-docs-theme: Usefull to test branches:"
731
+ " --theme git+https://github.com/obulat/python-docs-theme@master" ,
732
+ )
720
733
return parser .parse_args ()
721
734
722
735
@@ -838,7 +851,7 @@ def main():
838
851
args .skip_cache_invalidation ,
839
852
)
840
853
build_sitemap (args .www_root )
841
- build_robots_txt (args .www_root )
854
+ build_robots_txt (args .www_root , args . group , args . skip_cache_invalidation )
842
855
843
856
844
857
if __name__ == "__main__" :
0 commit comments