Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/2340.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow passing config directory without filename. - by :user:`ssbarnea`.
3 changes: 2 additions & 1 deletion docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ examples first and use this page as a reference.

.. code-block:: toml

[tool:tox]
[tool.tox]
legacy_tox_ini = """
[tox]
min_version = 4.0
env_list =
py310
Expand Down
2 changes: 1 addition & 1 deletion src/tox/config/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def add_core_arguments(parser: ArgumentParser) -> None:
default=None,
type=Path,
of_type=Optional[Path],
help="configuration file for tox (if not specified will discover one)",
help="configuration file/folder for tox (if not specified will discover one)",
)
parser.add_argument(
"--workdir",
Expand Down
11 changes: 11 additions & 0 deletions src/tox/config/source/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def discover_source(config_file: Path | None, root_dir: Path | None) -> Source:
src = _locate_source()
if src is None:
src = _create_default_source(root_dir)
elif config_file.is_dir():
src = None
for src_type in SOURCE_TYPES:
candidate: Path = config_file / src_type.FILENAME
try:
src = src_type(candidate)
break
except ValueError:
continue
if src is None:
raise HandledError(f"could not find any config file in {config_file}")
else:
src = _load_exact_source(config_file)
return src
Expand Down
31 changes: 31 additions & 0 deletions tests/config/cli/test_cli_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

from tox.config.cli.ini import IniConfig
from tox.config.cli.parse import get_options
from tox.config.cli.parser import Parsed
from tox.config.loader.api import Override
from tox.config.main import Config
from tox.config.source import discover_source
from tox.pytest import CaptureFixture, LogCaptureFixture, MonkeyPatch
from tox.session.env_select import CliEnv
from tox.session.state import State
Expand Down Expand Up @@ -199,3 +202,31 @@ def test_cli_ini_with_interpolated(tmp_path: Path, monkeypatch: MonkeyPatch) ->
monkeypatch.setenv("TOX_CONFIG_FILE", str(to))
conf = IniConfig()
assert conf.get("a", str)


@pytest.mark.parametrize(
("conf_arg", "filename", "content"),
[
pytest.param("", "tox.ini", "[tox]", id="ini-dir"),
pytest.param("tox.ini", "tox.ini", "[tox]", id="ini"),
pytest.param("", "setup.cfg", "[tox:tox]", id="cfg-dir"),
pytest.param("setup.cfg", "setup.cfg", "[tox:tox]", id="cfg"),
pytest.param("", "pyproject.toml", '[tool.tox]\nlegacy_tox_ini = """\n[tox]\n"""\n', id="toml-dir"),
pytest.param("pyproject.toml", "pyproject.toml", '[tool.tox]\nlegacy_tox_ini = """\n[tox]\n"""\n', id="toml"),
],
)
def test_conf_arg(tmp_path: Path, conf_arg: str, filename: str, content: str) -> None:
dest = tmp_path / "c"
dest.mkdir()
if filename:
cfg = dest / filename
cfg.write_bytes(content.encode(encoding="utf-8"))

config_file = dest / conf_arg
source = discover_source(config_file, None)

Config.make(
Parsed(work_dir=dest, override=[], config_file=config_file, root_dir=None),
pos_args=[],
source=source,
)