Skip to content

Commit 9ea1c32

Browse files
vytas7gaborbernatpre-commit-ci[bot]
authored
Prevent Tox from hanging with --installpkg sdist due to orphaned build backend (#3530)
Co-authored-by: Bernát Gábor <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent aa90652 commit 9ea1c32

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

docs/changelog/3530.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Prevent tox from hanging upon exit due to orphaned build threads and subprocesses when the ``--installpkg`` option is
2+
used with *sdist*.
3+
- by :user:`vytas7`

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ test = [
8686
"flaky>=3.8.1",
8787
"hatch-vcs>=0.5",
8888
"hatchling>=1.27",
89+
"pdm-backend",
8990
"psutil>=7",
9091
"pytest>=8.4.1",
9192
"pytest-cov>=6.2.1",

src/tox/tox_env/python/virtual_env/package/pyproject.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ def root(self) -> Path:
118118

119119
@root.setter
120120
def root(self, value: Path) -> None:
121+
# Recreating the frontend with a new root would orphan the current frontend.backend_executor, if any, making tox
122+
# hang upon exit waiting for its threads and subprocesses (#3512).
123+
# Therefore, we make sure to close the existing back-end executor in the case of an existing PEP 517 frontend.
124+
if self._frontend is not None:
125+
self._frontend.backend_executor.close()
126+
121127
self._root = value
122128
self._frontend_ = None # force recreating the frontend with new root
123129

tests/tox_env/python/virtual_env/package/conftest.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
from textwrap import dedent
5-
from typing import TYPE_CHECKING
5+
from typing import TYPE_CHECKING, Callable
66

77
import pytest
88

@@ -41,3 +41,41 @@ def pkg_with_extras_project(tmp_path_factory: pytest.TempPathFactory) -> Path:
4141
toml = '[build-system]\nrequires=["setuptools"]\nbuild-backend = "setuptools.build_meta"'
4242
(tmp_path / "pyproject.toml").write_text(toml)
4343
return tmp_path
44+
45+
46+
@pytest.fixture(scope="session")
47+
def pkg_with_pdm_backend(
48+
tmp_path_factory: pytest.TempPathFactory,
49+
pkg_builder: Callable[[Path, Path, list[str], bool], Path],
50+
) -> Path:
51+
tmp_path = tmp_path_factory.mktemp("skeleton")
52+
53+
pyproject_toml = """
54+
[build-system]
55+
requires = ["pdm-backend"]
56+
build-backend = "pdm.backend"
57+
58+
[project]
59+
name = "skeleton"
60+
description = "Just a skeleton for reproducing #3512."
61+
version = "0.1.1337"
62+
dependencies = [
63+
"requests",
64+
]
65+
66+
[tool.pdm.build]
67+
includes = [
68+
"skeleton/",
69+
]
70+
source-includes = [
71+
"tox.ini",
72+
]
73+
"""
74+
(tmp_path / "pyproject.toml").write_text(dedent(pyproject_toml))
75+
(tmp_path / "skeleton").mkdir(exist_ok=True)
76+
(tmp_path / "skeleton" / "__init__.py").touch()
77+
78+
dist = tmp_path / "dist"
79+
pkg_builder(dist, tmp_path, ["sdist"], False)
80+
81+
return tmp_path

tests/tox_env/python/virtual_env/package/test_package_pyproject.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,3 +464,24 @@ def test_pyproject_config_settings_editable_legacy(
464464
"get_requires_for_build_wheel": {"C": "3"},
465465
"prepare_metadata_for_build_wheel": {"D": "4"},
466466
}
467+
468+
469+
@pytest.mark.usefixtures("enable_pip_pypi_access")
470+
def test_pyproject_installpkg_pep517_envs(tox_project: ToxProjectCreator, pkg_with_pdm_backend: Path) -> None:
471+
# Regression test for #3512
472+
tox_ini = """
473+
[tox]
474+
envlist = dummy1,dummy2
475+
476+
[testenv:dummy1]
477+
commands =
478+
python -c print(1)
479+
480+
[testenv:dummy2]
481+
commands =
482+
python -c print(42)
483+
"""
484+
sdist = pkg_with_pdm_backend / "dist" / "skeleton-0.1.1337.tar.gz"
485+
proj = tox_project({"tox.ini": tox_ini}, base=pkg_with_pdm_backend)
486+
result = proj.run("--installpkg", str(sdist))
487+
result.assert_success()

0 commit comments

Comments
 (0)