Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new tox plugin setting to do rm -r #1118

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,16 @@ commands = pyright src/ {posargs}
# readthedocs doc build
basepython = python3.11
deps = -r requirements/py{py_dot_ver}/docs.txt
allowlist_externals = rm
changedir = docs/
# clean the build dir before rebuilding
commands_pre = rm -rf _build/
globus_sdk_rmtree = docs/_build
changedir = docs/
commands = sphinx-build -j auto -d _build/doctrees -b html -W . _build/html {posargs}

[testenv:twine-check]
skip_install = true
deps = build
twine!=5.1.0
allowlist_externals = rm
commands_pre = rm -rf dist/
globus_sdk_rmtree = dist
# check that twine validating package data works
commands = python -m build
twine check --strict dist/*
Expand All @@ -89,8 +87,7 @@ commands = python -m build
skip_install = true
deps = poetry
# remove the dist dir because it can lead to (confusing) spurious failures
allowlist_externals = rm
commands_pre = rm -rf dist/
globus_sdk_rmtree = dist
# use `poetry lock` to ensure that poetry can parse our dependencies
changedir = tests/non-pytest/poetry-lock-test
commands = poetry lock
Expand Down
25 changes: 25 additions & 0 deletions toxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@

from __future__ import annotations

import logging
import pathlib
import shutil
import typing as t

from tox.plugin import impl

if t.TYPE_CHECKING:
from tox.config.sets import EnvConfigSet
from tox.session.state import State
from tox.tox_env.api import ToxEnv

log = logging.getLogger(__name__)

REPO_ROOT = pathlib.Path(__file__).parent
BUILD_DIR = REPO_ROOT / "build"

Expand All @@ -33,3 +38,23 @@ def tox_on_install(
return
if BUILD_DIR.exists():
shutil.rmtree(BUILD_DIR)


@impl
def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None:
env_conf.add_config(
keys=["globus_sdk_rmtree"],
of_type=list[str],
default=[],
desc="A dir tree to remove before running the environment commands",
)


@impl
def tox_before_run_commands(tox_env: ToxEnv) -> None:
sdk_rmtree = tox_env.conf.load("globus_sdk_rmtree")
for name in sdk_rmtree:
path = pathlib.Path(name)
if path.exists():
log.warning(f"globus_sdk_rmtree: {path}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, quick review note: logged warnings show up in tox output by default, but info logs don't.

shutil.rmtree(path)
Loading