diff --git a/README.rst b/README.rst index e8311d6..c77182e 100644 --- a/README.rst +++ b/README.rst @@ -167,6 +167,9 @@ The plugin is available also for tox 4. Differences in behavior between tox 3 an - The plugin does not check the requested Python version nor the environment name. If you let it run for multiple environments they'll all use the same Python. - Deprecated ``--print-deps-only`` option is no longer available. +- Unlike tox 3, tox 4 can normally run without any tox configuration. + When tox 4 runs with ``--print-deps-to`` or ``--print-extras-to`` without a tox configuration, it will fail. + This was deliberately done to make Fedora packages misusing this option fail to build. Use an isolated environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/tox_current_env/hooks4.py b/src/tox_current_env/hooks4.py index 5628eff..2992cc8 100644 --- a/src/tox_current_env/hooks4.py +++ b/src/tox_current_env/hooks4.py @@ -61,6 +61,11 @@ def tox_add_option(parser): @impl def tox_add_core_config(core_conf, state): opt = state.conf.options + if (opt.print_deps_to or opt.print_extras_to) and not core_conf.loaders: + raise RuntimeError( + "--print-deps-to and/or --print-extras-to cannot be used without a tox config. " + "Seeing this error indicates this project either does not use tox at all or the tox configuration is missing." + ) if opt.current_env or opt.print_deps_to or opt.print_extras_to: # We do not want to install the main package. diff --git a/tests/test_integration_tox4.py b/tests/test_integration_tox4.py index 34e8b0d..bd775e0 100644 --- a/tests/test_integration_tox4.py +++ b/tests/test_integration_tox4.py @@ -430,3 +430,24 @@ def test_report_installed(projdir): assert result.returncode == 0 assert "tox==" in result.stdout assert "pytest==" in result.stdout + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +def test_print_deps_without_config_fails(projdir, toxenv, print_deps_stdout_arg): + tox_ini = projdir / "tox.ini" + tox_ini.unlink() + # note: tox will traverse the filesystem up to find a config, + # so if this (or the next) test fails, + # check if you don't have a stray tox.ini in /tmp + result = tox("-e", toxenv, print_deps_stdout_arg, check=False) + assert result.returncode > 0 + assert "tox configuration is missing" in result.stderr + + +@pytest.mark.parametrize("toxenv", envs_from_tox_ini()) +def test_print_extras_without_config_fails(projdir, toxenv): + tox_ini = projdir / "tox.ini" + tox_ini.unlink() + result = tox("-e", toxenv, "--print-extras-to=-", check=False) + assert result.returncode > 0 + assert "tox configuration is missing" in result.stderr