Skip to content

Commit 5c627ae

Browse files
committed
tox 4: Abort the --print* options when no tox config was found
That way, Fedora packages using `%pyproject_buildrequires -t` will fail to build when the upstream project does not use tox at all or when the tox configuration is missing.
1 parent 94c7ff8 commit 5c627ae

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ The plugin is available also for tox 4. Differences in behavior between tox 3 an
167167
- The plugin does not check the requested Python version nor the environment name.
168168
If you let it run for multiple environments they'll all use the same Python.
169169
- Deprecated ``--print-deps-only`` option is no longer available.
170+
- Unlike tox 3, tox 4 can normally run without any tox configuration.
171+
When tox 4 runs with ``--print-deps-to`` or ``--print-extras-to`` without a tox configuration, it will fail.
172+
This was deliberately done to make Fedora packages misusing this option fail to build.
170173

171174
Use an isolated environment
172175
~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/tox_current_env/hooks4.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def tox_add_option(parser):
6161
@impl
6262
def tox_add_core_config(core_conf, state):
6363
opt = state.conf.options
64+
if (opt.print_deps_to or opt.print_extras_to) and not core_conf.loaders:
65+
raise RuntimeError(
66+
"--print-deps-to and/or --print-extras-to cannot be used without a tox config. "
67+
"Seeing this error indicates this project either does not use tox at all or the tox configuration is missing."
68+
)
6469

6570
if opt.current_env or opt.print_deps_to or opt.print_extras_to:
6671
# We do not want to install the main package.

tests/test_integration_tox4.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,24 @@ def test_report_installed(projdir):
430430
assert result.returncode == 0
431431
assert "tox==" in result.stdout
432432
assert "pytest==" in result.stdout
433+
434+
435+
@pytest.mark.parametrize("toxenv", envs_from_tox_ini())
436+
def test_print_deps_without_config_fails(projdir, toxenv, print_deps_stdout_arg):
437+
tox_ini = projdir / "tox.ini"
438+
tox_ini.unlink()
439+
# note: tox will traverse the filesystem up to find a config,
440+
# so if this (or the next) test fails,
441+
# check if you don't have a stray tox.ini in /tmp
442+
result = tox("-e", toxenv, print_deps_stdout_arg, check=False)
443+
assert result.returncode > 0
444+
assert "tox configuration is missing" in result.stderr
445+
446+
447+
@pytest.mark.parametrize("toxenv", envs_from_tox_ini())
448+
def test_print_extras_without_config_fails(projdir, toxenv):
449+
tox_ini = projdir / "tox.ini"
450+
tox_ini.unlink()
451+
result = tox("-e", toxenv, "--print-extras-to=-", check=False)
452+
assert result.returncode > 0
453+
assert "tox configuration is missing" in result.stderr

0 commit comments

Comments
 (0)