Skip to content

Commit

Permalink
Add on platform constat to core
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
  • Loading branch information
gaborbernat committed Aug 5, 2024
1 parent 17435df commit 00ff1be
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/3315.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :ref:`on_platform` core configuration holding the tox platform and do not install package when exec an environment
- by :user:`gaborbernat`.
6 changes: 6 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ The following options are set in the ``[tox]`` section of ``tox.ini`` or the ``[
test = py310, py39
static = flake8, mypy
.. conf::
:keys: on_platform
:constant:

A constant holding the platform of the tox runtime environment.

Python language core options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dynamic = [
"version",
]
dependencies = [
"cachetools>=5.3.3",
"cachetools>=5.4",
"chardet>=5.2",
"colorama>=0.4.6",
"filelock>=3.15.4",
Expand All @@ -62,10 +62,10 @@ dependencies = [
"virtualenv>=20.26.3",
]
optional-dependencies.docs = [
"furo>=2024.5.6",
"sphinx>=7.3.7",
"furo>=2024.7.18",
"sphinx>=7.4.7",
"sphinx-argparse-cli>=1.16",
"sphinx-autodoc-typehints!=1.23.4,>=2.2.2",
"sphinx-autodoc-typehints>=2.2.3",
"sphinx-copybutton>=0.5.2",
"sphinx-inline-tabs>=2023.4.21",
"sphinxcontrib-towncrier>=0.2.1a0",
Expand All @@ -76,18 +76,18 @@ optional-dependencies.testing = [
"covdefaults>=2.3",
"detect-test-pollution>=1.2",
"devpi-process>=1",
"diff-cover>=9.1",
"diff-cover>=9.1.1",
"distlib>=0.3.8",
"flaky>=3.8.1",
"hatch-vcs>=0.4",
"hatchling>=1.25",
"psutil>=6",
"pytest>=8.2.2",
"pytest>=8.3.2",
"pytest-cov>=5",
"pytest-mock>=3.14",
"pytest-xdist>=3.6.1",
"re-assert>=1.1",
"setuptools>=70.2",
"setuptools>=70.3",
"time-machine>=2.14.2; implementation_name!='pypy'",
"wheel>=0.43",
]
Expand Down
1 change: 1 addition & 0 deletions src/tox/session/cmd/exec_.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def tox_add_option(parser: ToxParser) -> None:


def exec_(state: State) -> int:
state.conf.options.skip_pkg_install = True # avoid package install
envs = list(state.envs.iter())
if len(envs) != 1:
msg = f"exactly one target environment allowed in exec mode but found {', '.join(envs)}"
Expand Down
6 changes: 6 additions & 0 deletions src/tox/session/state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING, Sequence

from tox.config.main import Config
Expand All @@ -18,6 +19,11 @@ class State:

def __init__(self, options: Options, args: Sequence[str]) -> None:
self.conf = Config.make(options.parsed, options.pos_args, options.source)
self.conf.core.add_constant(
keys=["on_platform"],
desc="platform we are running on",
value=sys.platform,
)
self._options = options
self.args = args
self._journal: Journal = Journal(getattr(options.parsed, "result_json", None) is not None)
Expand Down
7 changes: 7 additions & 0 deletions tests/session/cmd/test_show_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,10 @@ def test_package_env_inherits_from_pkgenv(tox_project: ToxProjectCreator, demo_p
"""
exp = dedent(exp)
assert exp in outcome.out


def test_core_on_platform(tox_project: ToxProjectCreator) -> None:
project = tox_project({"tox.ini": "[tox]\nno_package = true"})
result = project.run("c", "-e", "py", "--core", "-k", "on_platform")
result.assert_success()
assert result.out == f"[testenv:py]\n\n[tox]\non_platform = {sys.platform}\n"
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ commands =
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
skip_install = true
deps =
pre-commit>=3.7.1
pre-commit>=3.8
pass_env =
{[testenv]passenv}
PROGRAMDATA
Expand All @@ -51,8 +51,8 @@ commands =
[testenv:type]
description = run type check on code base
deps =
mypy==1.10.1
types-cachetools>=5.3.0.7
mypy==1.11
types-cachetools>=5.4.0.20240717
types-chardet>=5.0.4.6
commands =
mypy src/tox
Expand Down

0 comments on commit 00ff1be

Please sign in to comment.