Skip to content

Commit a36ff9d

Browse files
authored
Fix --sdistonly behaviour (#2775)
1 parent b0c3cf6 commit a36ff9d

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

docs/changelog/2653.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``--sdistonly`` behaviour.

src/tox/session/cmd/run/common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ def _queue_and_wait(
299299

300300
def _run(tox_env: RunToxEnv) -> ToxEnvRunResult:
301301
spinner.add(tox_env.conf.name)
302-
return run_one(tox_env, options.parsed.no_test, suspend_display=live is False)
302+
return run_one(
303+
tox_env,
304+
options.parsed.no_test or options.parsed.package_only,
305+
suspend_display=live is False,
306+
)
303307

304308
try:
305309
executor = ThreadPoolExecutor(max_workers=max_workers, thread_name_prefix="tox-driver")

src/tox/tox_env/runner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ def _register_package_conf(self) -> bool:
165165

166166
def _setup_pkg(self) -> None:
167167
self._packages = self._build_packages()
168-
self._install(self._packages, RunToxEnv.__name__, "package")
168+
if not self.options.package_only:
169+
self._install(self._packages, RunToxEnv.__name__, "package")
169170
self._handle_journal_package(self.journal, self._packages)
170171

171172
@staticmethod

tests/tox_env/test_tox_env_runner.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from pathlib import Path
2+
3+
from tox.pytest import ToxProjectCreator
4+
5+
6+
def test_package_only(
7+
tox_project: ToxProjectCreator,
8+
demo_pkg_inline: Path,
9+
) -> None:
10+
ini = "[testenv]\ncommands = python -c 'print('foo')'"
11+
proj = tox_project(
12+
{"tox.ini": ini, "pyproject.toml": (demo_pkg_inline / "pyproject.toml").read_text()},
13+
base=demo_pkg_inline,
14+
)
15+
execute_calls = proj.patch_execute(lambda r: 0 if "install" in r.run_id else None)
16+
result = proj.run("r", "--sdistonly")
17+
result.assert_success()
18+
19+
expected_calls = [
20+
(".pkg", "_optional_hooks"),
21+
(".pkg", "get_requires_for_build_sdist"),
22+
(".pkg", "build_wheel"),
23+
(".pkg", "build_sdist"),
24+
(".pkg", "_exit"),
25+
]
26+
found_calls = [(i[0][0].conf.name, i[0][3].run_id) for i in execute_calls.call_args_list]
27+
assert found_calls == expected_calls

0 commit comments

Comments
 (0)