Skip to content

Commit fa22c64

Browse files
authored
Merge pull request #1118 from sirosen/toxfile-rmtree
Add a new tox plugin setting to do `rm -r`
2 parents da5f83d + d86e998 commit fa22c64

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

tox.ini

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,16 @@ commands = pyright src/ {posargs}
6969
# readthedocs doc build
7070
basepython = python3.11
7171
deps = -r requirements/py{py_dot_ver}/docs.txt
72-
allowlist_externals = rm
73-
changedir = docs/
7472
# clean the build dir before rebuilding
75-
commands_pre = rm -rf _build/
73+
globus_sdk_rmtree = docs/_build
74+
changedir = docs/
7675
commands = sphinx-build -j auto -d _build/doctrees -b html -W . _build/html {posargs}
7776

7877
[testenv:twine-check]
7978
skip_install = true
8079
deps = build
8180
twine!=5.1.0
82-
allowlist_externals = rm
83-
commands_pre = rm -rf dist/
81+
globus_sdk_rmtree = dist
8482
# check that twine validating package data works
8583
commands = python -m build
8684
twine check --strict dist/*
@@ -89,8 +87,7 @@ commands = python -m build
8987
skip_install = true
9088
deps = poetry
9189
# remove the dist dir because it can lead to (confusing) spurious failures
92-
allowlist_externals = rm
93-
commands_pre = rm -rf dist/
90+
globus_sdk_rmtree = dist
9491
# use `poetry lock` to ensure that poetry can parse our dependencies
9592
changedir = tests/non-pytest/poetry-lock-test
9693
commands = poetry lock

toxfile.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@
1111

1212
from __future__ import annotations
1313

14+
import logging
1415
import pathlib
1516
import shutil
1617
import typing as t
1718

1819
from tox.plugin import impl
1920

2021
if t.TYPE_CHECKING:
22+
from tox.config.sets import EnvConfigSet
23+
from tox.session.state import State
2124
from tox.tox_env.api import ToxEnv
2225

26+
log = logging.getLogger(__name__)
27+
2328
REPO_ROOT = pathlib.Path(__file__).parent
2429
BUILD_DIR = REPO_ROOT / "build"
2530

@@ -33,3 +38,23 @@ def tox_on_install(
3338
return
3439
if BUILD_DIR.exists():
3540
shutil.rmtree(BUILD_DIR)
41+
42+
43+
@impl
44+
def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None:
45+
env_conf.add_config(
46+
keys=["globus_sdk_rmtree"],
47+
of_type=list[str],
48+
default=[],
49+
desc="A dir tree to remove before running the environment commands",
50+
)
51+
52+
53+
@impl
54+
def tox_before_run_commands(tox_env: ToxEnv) -> None:
55+
sdk_rmtree = tox_env.conf.load("globus_sdk_rmtree")
56+
for name in sdk_rmtree:
57+
path = pathlib.Path(name)
58+
if path.exists():
59+
log.warning(f"globus_sdk_rmtree: {path}")
60+
shutil.rmtree(path)

0 commit comments

Comments
 (0)