@@ -805,12 +805,12 @@ def build(self) -> None:
805805 def build_venv (self ) -> None :
806806 """Build a venv for the specific Python version.
807807
808- The venv is created at most once per run and reused by later
809- builds of the same version: reusing a venv across runs can
810- silently keep outdated packages, because pip considers a
811- requirement satisfied when the installed version number matches,
812- even if the requirement is a direct URL now pointing at
813- different code.
808+ The venv is created at most once per run, reused by later builds
809+ of the same version, and removed at the end of the run: reusing
810+ a venv across runs can silently keep outdated packages, because
811+ pip considers a requirement satisfied when the installed version
812+ number matches, even if the requirement is a direct URL now
813+ pointing at different code.
814814 """
815815 venv_name = self .build_meta .venv_name
816816 if self .select_output is not None :
@@ -1284,31 +1284,35 @@ def build_docs(args: argparse.Namespace) -> int:
12841284 args .build_root / _checkout_name (args .select_output ),
12851285 )
12861286 built_venvs : set [Path ] = set ()
1287- while todo :
1288- build_props = todo .pop ()
1289- logging .root .handlers [0 ].setFormatter (
1290- logging .Formatter (
1291- f"%(asctime)s %(levelname)s { build_props .slug } : %(message)s"
1287+ try :
1288+ while todo :
1289+ build_props = todo .pop ()
1290+ logging .root .handlers [0 ].setFormatter (
1291+ logging .Formatter (
1292+ f"%(asctime)s %(levelname)s { build_props .slug } : %(message)s"
1293+ )
12921294 )
1293- )
1294- if sentry_sdk :
1295- scope = sentry_sdk .get_isolation_scope ()
1296- scope .set_tag ("version" , build_props .version )
1297- scope .set_tag ("language" , build_props .language )
1298- cpython_repo .update ()
1299- builder = DocBuilder (
1300- build_props ,
1301- cpython_repo ,
1302- docs_by_version_content ,
1303- switchers_content ,
1304- built_venvs ,
1305- ** vars (args ),
1306- )
1307- built_successfully = builder .run (http , force_build = force_build )
1308- if built_successfully :
1309- build_succeeded .add (build_props .slug )
1310- elif built_successfully is not None :
1311- any_build_failed = True
1295+ if sentry_sdk :
1296+ scope = sentry_sdk .get_isolation_scope ()
1297+ scope .set_tag ("version" , build_props .version )
1298+ scope .set_tag ("language" , build_props .language )
1299+ cpython_repo .update ()
1300+ builder = DocBuilder (
1301+ build_props ,
1302+ cpython_repo ,
1303+ docs_by_version_content ,
1304+ switchers_content ,
1305+ built_venvs ,
1306+ ** vars (args ),
1307+ )
1308+ built_successfully = builder .run (http , force_build = force_build )
1309+ if built_successfully :
1310+ build_succeeded .add (build_props .slug )
1311+ elif built_successfully is not None :
1312+ any_build_failed = True
1313+ finally :
1314+ for venv_path in built_venvs :
1315+ shutil .rmtree (venv_path , ignore_errors = True )
13121316
13131317 logging .root .handlers [0 ].setFormatter (
13141318 logging .Formatter ("%(asctime)s %(levelname)s: %(message)s" )
0 commit comments