Skip to content

Commit 11caf6c

Browse files
committed
docs: remove virtual environment after usage
1 parent fc028d2 commit 11caf6c

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

docsrc/poly.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from subprocess import CalledProcessError
55
import os
66
from pathlib import Path
7+
import shutil
78

89
from sphinx_polyversion.api import apply_overrides
910
from sphinx_polyversion.builder import BuildError
@@ -31,7 +32,7 @@
3132
root = Git.root(Path(__file__).parent)
3233

3334
#: CodeRegex matching the branches to build docs for
34-
BRANCH_REGEX = r"^(master)$"
35+
BRANCH_REGEX = r"^(master|dev)$"
3536

3637
#: Regex matching the tags to build docs for
3738
TAG_REGEX = r"^v[\.0-9]*$"
@@ -69,6 +70,8 @@
6970
"tensorflow",
7071
]
7172

73+
VENV_DIR_NAME = ".bf_doc_gen_venv"
74+
7275

7376
#: Data passed to templates
7477
def data(driver, rev, env):
@@ -248,13 +251,22 @@ async def selector(rev, keys):
248251
return None
249252

250253

254+
class DestructingDynamicPip(DynamicPip):
255+
async def __aexit__(self, exc_type, exc, tb):
256+
if self.venv.parent.name == VENV_DIR_NAME:
257+
logger.info("Removing environment " + str(self.venv))
258+
shutil.rmtree(self.venv)
259+
260+
261+
pip_cls = DynamicPip if PARALLEL_BUILDS else DestructingDynamicPip
262+
251263
ENVIRONMENT = {
252264
# configuration for v2 and dev
253-
None: DynamicPip.factory(venv=Path(".venv"), args=["-e", "."] + SPHINX_DEPS + V2_BACKEND_DEPS, creator=creator),
265+
None: pip_cls.factory(venv=Path(VENV_DIR_NAME), args=["-e", "."] + SPHINX_DEPS + V2_BACKEND_DEPS, creator=creator),
254266
# configuration for v1 and master (remove master here and in selector when it moves to v2)
255-
"v1": DynamicPip.factory(venv=Path(".venv"), args=["-e", "."] + SPHINX_DEPS + V1_BACKEND_DEPS, creator=creator),
256-
"master": DynamicPip.factory(
257-
venv=Path(".venv"),
267+
"v1": pip_cls.factory(venv=Path(VENV_DIR_NAME), args=["-e", "."] + SPHINX_DEPS + V1_BACKEND_DEPS, creator=creator),
268+
"master": pip_cls.factory(
269+
venv=Path(VENV_DIR_NAME),
258270
args=["-vv", "-e", "."] + V1_BACKEND_DEPS + SPHINX_DEPS,
259271
creator=creator,
260272
env_vars={"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BAYESFLOW": "1.1.6dev"},

0 commit comments

Comments
 (0)