From 49d970682a3a4fcd25be3319d55452d94d5e3592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Thu, 8 Dec 2022 08:02:54 -0800 Subject: [PATCH] Show host python under core section as constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- docs/changelog/2630.bugfix.rst | 2 ++ src/tox/config/sets.py | 2 ++ tests/session/cmd/test_show_config.py | 7 +++++++ 3 files changed, 11 insertions(+) create mode 100644 docs/changelog/2630.bugfix.rst diff --git a/docs/changelog/2630.bugfix.rst b/docs/changelog/2630.bugfix.rst new file mode 100644 index 000000000..a825a5da4 --- /dev/null +++ b/docs/changelog/2630.bugfix.rst @@ -0,0 +1,2 @@ +The core tox configuration now contains ``host_python`` key showing the host python executable path - +by :user:`gaborbernat`. diff --git a/src/tox/config/sets.py b/src/tox/config/sets.py index 0315369a7..d5e90c1f5 100644 --- a/src/tox/config/sets.py +++ b/src/tox/config/sets.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from abc import ABC, abstractmethod from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, Iterator, Mapping, Sequence, TypeVar, cast @@ -202,6 +203,7 @@ def work_dir_builder(conf: Config, env_name: str | None) -> Path: # noqa: U100 default=lambda conf, _: cast(Path, self["work_dir"]) / ".tmp", # noqa: U100, U101 desc="a folder for temporary files (is not cleaned at start)", ) + self.add_constant("host_python", "the host python executable path", sys.executable) def _on_duplicate_conf(self, key: str, definition: ConfigDefinition[V]) -> None: # noqa: U100 pass # core definitions may be defined multiple times as long as all their options match, first defined wins diff --git a/tests/session/cmd/test_show_config.py b/tests/session/cmd/test_show_config.py index 0fa430291..eaddf7200 100644 --- a/tests/session/cmd/test_show_config.py +++ b/tests/session/cmd/test_show_config.py @@ -219,3 +219,10 @@ def test_show_config_timeout_custom(tox_project: ToxProjectCreator) -> None: def test_show_config_help(tox_project: ToxProjectCreator) -> None: outcome = tox_project({"tox.ini": ""}).run("c", "-h") outcome.assert_success() + + +def test_show_config_core_host_python(tox_project: ToxProjectCreator) -> None: + project = tox_project({"tox.ini": ""}) + outcome = project.run("c", "--core", "-e", "py", "-k", "host_python") + outcome.assert_success() + assert f"host_python = {sys.executable}" in outcome.out