|
12 | 12 | from tox import reporter
|
13 | 13 | from tox.action import Action
|
14 | 14 | from tox.config.parallel import ENV_VAR_KEY as PARALLEL_ENV_VAR_KEY
|
15 |
| -from tox.constants import PARALLEL_RESULT_JSON_PREFIX, PARALLEL_RESULT_JSON_SUFFIX |
| 15 | +from tox.constants import INFO, PARALLEL_RESULT_JSON_PREFIX, PARALLEL_RESULT_JSON_SUFFIX |
16 | 16 | from tox.package.local import resolve_package
|
17 | 17 | from tox.util.lock import get_unique_file
|
18 | 18 | from tox.util.path import ensure_empty_dir
|
@@ -694,6 +694,31 @@ def tox_testenv_create(venv, action):
|
694 | 694 |
|
695 | 695 | def cleanup_for_venv(venv):
|
696 | 696 | within_parallel = PARALLEL_ENV_VAR_KEY in os.environ
|
| 697 | + # if the directory exists and it doesn't look like a virtualenv, produce |
| 698 | + # an error |
| 699 | + if venv.path.exists(): |
| 700 | + dir_items = set(os.listdir(str(venv.path))) - {".lock", "log"} |
| 701 | + dir_items = {p for p in dir_items if not p.startswith(".tox-")} |
| 702 | + else: |
| 703 | + dir_items = set() |
| 704 | + |
| 705 | + if not ( |
| 706 | + # doesn't exist => OK |
| 707 | + not venv.path.exists() |
| 708 | + # does exist, but it's empty => OK |
| 709 | + or not dir_items |
| 710 | + # it exists and we're on windows with Lib and Scripts => OK |
| 711 | + or (INFO.IS_WIN and dir_items > {"Scripts", "Lib"}) |
| 712 | + # non-windows, with lib and bin => OK |
| 713 | + or dir_items > {"bin", "lib"} |
| 714 | + ): |
| 715 | + venv.status = "error" |
| 716 | + reporter.error( |
| 717 | + "cowardly refusing to delete `envdir` (it does not look like a virtualenv): " |
| 718 | + "{}".format(venv.path) |
| 719 | + ) |
| 720 | + raise SystemExit(2) |
| 721 | + |
697 | 722 | if within_parallel:
|
698 | 723 | if venv.path.exists():
|
699 | 724 | # do not delete the log folder as that's used by parent
|
|
0 commit comments