10
10
11
11
-q selects "quick build", which means to build only HTML.
12
12
13
- Translations are fetched from github repositories according to PEP
14
- 545. `--languages` allows to select translations, like `--languages
15
- en` to just build the english documents.
13
+ Translations are fetched from GitHub repositories according to PEP
14
+ 545. `--languages` allows selecting translations, like `--languages
15
+ en` to just build the English documents.
16
16
17
- This script was originally created and by Georg Brandl in March
18
- 2010.
17
+ This script was originally created by Georg Brandl in March 2010.
19
18
Modified by Benjamin Peterson to do CDN cache invalidation.
20
19
Modified by Julien Palard to build translations.
21
20
69
68
70
69
@total_ordering
71
70
class Version :
72
- """Represents a cpython version and its documentation builds dependencies."""
71
+ """Represents a CPython version and its documentation build dependencies."""
73
72
74
73
STATUSES = {"EOL" , "security-fixes" , "stable" , "pre-release" , "in development" }
75
74
@@ -147,7 +146,7 @@ def filter(versions, branch=None):
147
146
148
147
If *branch* is given, only *versions* matching *branch* are returned.
149
148
150
- Else all live version are returned (this mean no EOL and no
149
+ Else all live versions are returned (this means no EOL and no
151
150
security-fixes branches).
152
151
"""
153
152
if branch :
@@ -156,12 +155,12 @@ def filter(versions, branch=None):
156
155
157
156
@staticmethod
158
157
def current_stable (versions ):
159
- """Find the current stable cPython version."""
158
+ """Find the current stable CPython version."""
160
159
return max ((v for v in versions if v .status == "stable" ), key = Version .as_tuple )
161
160
162
161
@staticmethod
163
162
def current_dev (versions ):
164
- """Find the current de cPython version."""
163
+ """Find the current CPython version in development ."""
165
164
return max (versions , key = Version .as_tuple )
166
165
167
166
@property
@@ -360,7 +359,7 @@ def locate_nearest_version(available_versions, target_version):
360
359
def edit (file : Path ):
361
360
"""Context manager to edit a file "in place", use it as:
362
361
363
- with edit("/etc/hosts") as i, o:
362
+ with edit("/etc/hosts") as ( i, o) :
364
363
for line in i:
365
364
o.write(line.replace("localhoat", "localhost"))
366
365
"""
@@ -376,7 +375,7 @@ def edit(file: Path):
376
375
def setup_switchers (
377
376
versions : Iterable [Version ], languages : Iterable [Language ], html_root : Path
378
377
):
379
- """Setup cross-links between cpython versions:
378
+ """Setup cross-links between CPython versions:
380
379
- Cross-link various languages in a language switcher
381
380
- Cross-link various versions in a version switcher
382
381
"""
@@ -437,7 +436,7 @@ def build_robots_txt(
437
436
):
438
437
"""Disallow crawl of EOL versions in robots.txt."""
439
438
if not www_root .exists ():
440
- logging .info ("Skipping robots.txt generation (www root does not even exists )." )
439
+ logging .info ("Skipping robots.txt generation (www root does not even exist )." )
441
440
return
442
441
robots_file = www_root / "robots.txt"
443
442
with open (HERE / "templates" / "robots.txt" , encoding = "UTF-8" ) as template_file :
@@ -457,7 +456,7 @@ def build_sitemap(
457
456
):
458
457
"""Build a sitemap with all live versions and translations."""
459
458
if not www_root .exists ():
460
- logging .info ("Skipping sitemap generation (www root does not even exists )." )
459
+ logging .info ("Skipping sitemap generation (www root does not even exist )." )
461
460
return
462
461
with open (HERE / "templates" / "sitemap.xml" , encoding = "UTF-8" ) as template_file :
463
462
template = jinja2 .Template (template_file .read ())
@@ -472,7 +471,7 @@ def build_sitemap(
472
471
def build_404 (www_root : Path , group ):
473
472
"""Build a nice 404 error page to display in case PDFs are not built yet."""
474
473
if not www_root .exists ():
475
- logging .info ("Skipping 404 page generation (www root does not even exists )." )
474
+ logging .info ("Skipping 404 page generation (www root does not even exist )." )
476
475
return
477
476
not_found_file = www_root / "404.html"
478
477
shutil .copyfile (HERE / "templates" / "404.html" , not_found_file )
@@ -550,7 +549,7 @@ def parse_args():
550
549
)
551
550
parser .add_argument (
552
551
"--skip-cache-invalidation" ,
553
- help = "Skip fastly cache invalidation." ,
552
+ help = "Skip Fastly cache invalidation." ,
554
553
action = "store_true" ,
555
554
)
556
555
parser .add_argument (
@@ -580,7 +579,7 @@ def parse_args():
580
579
parser .add_argument (
581
580
"--theme" ,
582
581
default = "python-docs-theme" ,
583
- help = "Python package to use for python-docs-theme: Usefull to test branches:"
582
+ help = "Python package to use for python-docs-theme: Useful to test branches:"
584
583
" --theme git+https://github.com/obulat/python-docs-theme@master" ,
585
584
)
586
585
args = parser .parse_args ()
@@ -598,7 +597,7 @@ def parse_args():
598
597
599
598
600
599
def setup_logging (log_directory : Path ):
601
- """Setup logging to stderr if ran by a human, or to a file if ran from a cron."""
600
+ """Setup logging to stderr if run by a human, or to a file if run from a cron."""
602
601
if sys .stderr .isatty ():
603
602
logging .basicConfig (
604
603
format = "%(asctime)s %(levelname)s: %(message)s" , stream = sys .stderr
@@ -615,7 +614,7 @@ def setup_logging(log_directory: Path):
615
614
616
615
@dataclass
617
616
class DocBuilder :
618
- """Builder for a cpython version and a language."""
617
+ """Builder for a CPython version and a language."""
619
618
620
619
version : Version
621
620
versions : Iterable [Version ]
@@ -634,7 +633,7 @@ class DocBuilder:
634
633
def full_build (self ):
635
634
"""Tell if a full build is needed.
636
635
637
- A full build is slow, it builds pdf, txt, epub, texinfo, and
636
+ A full build is slow; it builds pdf, txt, epub, texinfo, and
638
637
archives everything.
639
638
640
639
A partial build only builds HTML and does not archive, it's
@@ -664,7 +663,7 @@ def run(self) -> bool:
664
663
665
664
@property
666
665
def checkout (self ) -> Path :
667
- """Path to cpython git clone."""
666
+ """Path to CPython git clone."""
668
667
return self .build_root / "cpython"
669
668
670
669
def clone_translation (self ):
@@ -687,7 +686,7 @@ def translation_repo(self):
687
686
688
687
@property
689
688
def translation_branch (self ):
690
- """Some cpython versions may be untranslated, being either too old or
689
+ """Some CPython versions may be untranslated, being either too old or
691
690
too new.
692
691
693
692
This function looks for remote branches on the given repo, and
@@ -746,7 +745,7 @@ def build(self):
746
745
python = self .venv / "bin" / "python"
747
746
sphinxbuild = self .venv / "bin" / "sphinx-build"
748
747
blurb = self .venv / "bin" / "blurb"
749
- # Disable cpython switchers, we handle them now:
748
+ # Disable CPython switchers, we handle them now:
750
749
751
750
def is_mac ():
752
751
return platform .system () == 'Darwin'
@@ -791,6 +790,7 @@ def build_venv(self):
791
790
run ([sys .executable , "-m" , "venv" , venv_path ])
792
791
run (
793
792
[venv_path / "bin" / "python" , "-m" , "pip" , "install" , "--upgrade" ]
793
+ + ["--upgrade-strategy=eager" ]
794
794
+ [self .theme ]
795
795
+ self .version .requirements ,
796
796
cwd = self .checkout / "Doc" ,
@@ -959,7 +959,7 @@ def load_state(self) -> dict:
959
959
return {}
960
960
961
961
def save_state (self , build_duration : float ):
962
- """Save current cpython sha1 and current translation sha1.
962
+ """Save current CPython sha1 and current translation sha1.
963
963
964
964
Using this we can deduce if a rebuild is needed or not.
965
965
"""
@@ -983,7 +983,7 @@ def save_state(self, build_duration: float):
983
983
984
984
def symlink (www_root : Path , language : Language , directory : str , name : str , group : str , skip_cache_invalidation : bool ):
985
985
"""Used by major_symlinks and dev_symlink to maintain symlinks."""
986
- if language .tag == "en" : # english is rooted on /, no /en/
986
+ if language .tag == "en" : # English is rooted on /, no /en/
987
987
path = www_root
988
988
else :
989
989
path = www_root / language .tag
@@ -1004,7 +1004,7 @@ def symlink(www_root: Path, language: Language, directory: str, name: str, group
1004
1004
def major_symlinks (
1005
1005
www_root : Path , group , versions : Iterable [Version ], languages : Iterable [Language ], skip_cache_invalidation : bool
1006
1006
):
1007
- """Maintains the /2/ and /3/ symlinks for each languages .
1007
+ """Maintains the /2/ and /3/ symlinks for each language .
1008
1008
1009
1009
Like:
1010
1010
- /3/ → /3.9/
@@ -1018,7 +1018,7 @@ def major_symlinks(
1018
1018
1019
1019
1020
1020
def dev_symlink (www_root : Path , group , versions , languages , skip_cache_invalidation : bool ):
1021
- """Maintains the /dev/ symlinks for each languages .
1021
+ """Maintains the /dev/ symlinks for each language .
1022
1022
1023
1023
Like:
1024
1024
- /dev/ → /3.11/
@@ -1033,7 +1033,7 @@ def dev_symlink(www_root: Path, group, versions, languages, skip_cache_invalidat
1033
1033
def purge (* paths ):
1034
1034
"""Remove one or many paths from docs.python.org's CDN.
1035
1035
1036
- To be used when a file change , so the CDN fetch the new one.
1036
+ To be used when a file changes , so the CDN fetches the new one.
1037
1037
"""
1038
1038
base = "https://docs.python.org/"
1039
1039
for path in paths :
@@ -1045,7 +1045,7 @@ def purge(*paths):
1045
1045
def purge_path (www_root : Path , path : Path ):
1046
1046
"""Recursively remove a path from docs.python.org's CDN.
1047
1047
1048
- To be used when a directory change , so the CDN fetch the new one.
1048
+ To be used when a directory changes , so the CDN fetches the new one.
1049
1049
"""
1050
1050
purge (* [file .relative_to (www_root ) for file in path .glob ("**/*" )])
1051
1051
purge (path .relative_to (www_root ))
@@ -1083,7 +1083,9 @@ def parse_versions_from_devguide():
1083
1083
"python/devguide/main/include/release-cycle.json" ,
1084
1084
timeout = 30 ,
1085
1085
).json ()
1086
- return [Version .from_json (name , release ) for name , release in releases .items ()]
1086
+ versions = [Version .from_json (name , release ) for name , release in releases .items ()]
1087
+ versions .sort (key = Version .as_tuple )
1088
+ return versions
1087
1089
1088
1090
1089
1091
def parse_languages_from_config ():
@@ -1119,7 +1121,7 @@ def format_seconds(seconds: float) -> str:
1119
1121
1120
1122
1121
1123
def build_docs (args ) -> bool :
1122
- """Build all docs (each languages and each versions )."""
1124
+ """Build all docs (each language and each version )."""
1123
1125
logging .info ("Full build start." )
1124
1126
start_time = perf_counter ()
1125
1127
versions = parse_versions_from_devguide ()
@@ -1144,9 +1146,9 @@ def build_docs(args) -> bool:
1144
1146
)
1145
1147
)
1146
1148
if sentry_sdk :
1147
- with sentry_sdk .configure_scope () as scope :
1148
- scope .set_tag ("version" , version .name )
1149
- scope .set_tag ("language" , language .tag )
1149
+ scope = sentry_sdk .get_isolation_scope ()
1150
+ scope .set_tag ("version" , version .name )
1151
+ scope .set_tag ("language" , language .tag )
1150
1152
builder = DocBuilder (
1151
1153
version , versions , language , languages , cpython_repo , ** vars (args )
1152
1154
)
0 commit comments