2222
2323from __future__ import annotations
2424
25+ import argparse
26+ import dataclasses
27+ import datetime as dt
2528import filecmp
2629import json
2730import logging
2831import logging .handlers
32+ import os
2933import re
3034import shlex
3135import shutil
3236import subprocess
3337import sys
34- from argparse import ArgumentParser , Namespace
3538from bisect import bisect_left as bisect
3639from contextlib import contextmanager , suppress
37- from dataclasses import dataclass
38- from datetime import datetime as dt , timezone
3940from functools import total_ordering
40- from os import getenv , readlink
4141from pathlib import Path
4242from string import Template
4343from time import perf_counter , sleep
6868HERE = Path (__file__ ).resolve ().parent
6969
7070
71- @dataclass (frozen = True , slots = True )
71+ @dataclasses . dataclass (frozen = True , slots = True )
7272class Versions :
7373 _seq : Sequence [Version ]
7474
@@ -213,7 +213,7 @@ def picker_label(self):
213213 return self .name
214214
215215
216- @dataclass (frozen = True , slots = True )
216+ @dataclasses . dataclass (frozen = True , slots = True )
217217class Languages :
218218 _seq : Sequence [Language ]
219219
@@ -250,7 +250,7 @@ def filter(self, language_tags: Sequence[str] = ()) -> Sequence[Language]:
250250 return list (self )
251251
252252
253- @dataclass (order = True , frozen = True , kw_only = True )
253+ @dataclasses . dataclass (order = True , frozen = True , kw_only = True )
254254class Language :
255255 iso639_tag : str
256256 name : str
@@ -337,7 +337,7 @@ def traverse(dircmp_result):
337337 return changed
338338
339339
340- @dataclass
340+ @dataclasses . dataclass
341341class Repository :
342342 """Git repository abstraction for our specific needs."""
343343
@@ -505,7 +505,7 @@ def version_info():
505505 )
506506
507507
508- @dataclass
508+ @dataclasses . dataclass
509509class DocBuilder :
510510 """Builder for a CPython version and a language."""
511511
@@ -539,7 +539,7 @@ def includes_html(self):
539539 def run (self , http : urllib3 .PoolManager ) -> bool :
540540 """Build and publish a Python doc, for a language, and a version."""
541541 start_time = perf_counter ()
542- start_timestamp = dt .now (tz = timezone . utc ).replace (microsecond = 0 )
542+ start_timestamp = dt .datetime . now (tz = dt . UTC ).replace (microsecond = 0 )
543543 logging .info ("Running." )
544544 try :
545545 if self .language .html_only and not self .includes_html :
@@ -861,7 +861,7 @@ def load_state(self) -> dict:
861861 except (KeyError , FileNotFoundError ):
862862 return {}
863863
864- def save_state (self , build_start : dt , build_duration : float , trigger : str ):
864+ def save_state (self , build_start : dt . datetime , build_duration : float , trigger : str ):
865865 """Save current CPython sha1 and current translation sha1.
866866
867867 Using this we can deduce if a rebuild is needed or not.
@@ -932,8 +932,9 @@ def main():
932932def parse_args ():
933933 """Parse command-line arguments."""
934934
935- parser = ArgumentParser (
936- description = "Runs a build of the Python docs for various branches."
935+ parser = argparse .ArgumentParser (
936+ description = "Runs a build of the Python docs for various branches." ,
937+ allow_abbrev = False ,
937938 )
938939 parser .add_argument (
939940 "--select-output" ,
@@ -1032,7 +1033,7 @@ def setup_logging(log_directory: Path, select_output: str | None):
10321033 logging .getLogger ().setLevel (logging .DEBUG )
10331034
10341035
1035- def build_docs_with_lock (args : Namespace , lockfile_name : str ) -> int :
1036+ def build_docs_with_lock (args : argparse . Namespace , lockfile_name : str ) -> int :
10361037 try :
10371038 lock = zc .lockfile .LockFile (HERE / lockfile_name )
10381039 except zc .lockfile .LockError :
@@ -1045,7 +1046,7 @@ def build_docs_with_lock(args: Namespace, lockfile_name: str) -> int:
10451046 lock .close ()
10461047
10471048
1048- def build_docs (args ) -> bool :
1049+ def build_docs (args : argparse . Namespace ) -> bool :
10491050 """Build all docs (each language and each version)."""
10501051 logging .info ("Full build start." )
10511052 start_time = perf_counter ()
@@ -1259,7 +1260,7 @@ def symlink(
12591260 if not directory_path .exists ():
12601261 return # No touching link, dest doc not built yet.
12611262
1262- if not link .exists () or readlink (link ) != directory :
1263+ if not link .exists () or os . readlink (link ) != directory :
12631264 # Link does not exist or points to the wrong target.
12641265 link .unlink (missing_ok = True )
12651266 link .symlink_to (directory )
@@ -1318,8 +1319,8 @@ def purge_surrogate_key(http: urllib3.PoolManager, surrogate_key: str) -> None:
13181319
13191320 https://www.fastly.com/documentation/reference/api/purging/#purge-tag
13201321 """
1321- service_id = getenv ("FASTLY_SERVICE_ID" , "__UNSET__" )
1322- fastly_key = getenv ("FASTLY_TOKEN" , "__UNSET__" )
1322+ service_id = os . environ . get ("FASTLY_SERVICE_ID" , "__UNSET__" )
1323+ fastly_key = os . environ . get ("FASTLY_TOKEN" , "__UNSET__" )
13231324
13241325 logging .info ("Purging Surrogate-Key '%s' from CDN" , surrogate_key )
13251326 http .request (
0 commit comments