Skip to content

Commit

Permalink
Add on platform constat to core (#3315)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Aug 5, 2024
1 parent 2cf190a commit 5425133
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 21 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
16 changes: 9 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 Expand Up @@ -128,6 +128,8 @@ lint.ignore = [
"D", # ignore documentation for now
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"DOC201", # broken with sphinx docs
"DOC501", # broken with sphinx docs
"INP001", # no implicit namespaces here
"ISC001", # conflicts with formatter
"PLR0914", ## Too many local variables
Expand Down
2 changes: 1 addition & 1 deletion src/tox/config/cli/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Customize argparse logic for tox (also contains the base options)."""
"""Customize argparse logic for tox (also contains the base options).""" # noqa: A005

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion src/tox/config/loader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __str__(self) -> str:
return f"{self.namespace}{'.' if self.namespace else ''}{self.key}={self.value}"

def __eq__(self, other: object) -> bool:
if type(self) != type(other):
if type(self) != type(other): # noqa: E721
return False
return (self.namespace, self.key, self.value) == (
other.namespace, # type: ignore[attr-defined]
Expand Down
6 changes: 3 additions & 3 deletions src/tox/config/of_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __call__(self, conf: Config, loaders: list[Loader[T]], args: ConfigLoadArgs)
raise NotImplementedError

def __eq__(self, o: object) -> bool:
return type(self) == type(o) and (self.keys, self.desc) == (o.keys, o.desc) # type: ignore[attr-defined]
return type(self) == type(o) and (self.keys, self.desc) == (o.keys, o.desc) # type: ignore[attr-defined] # noqa: E721

def __ne__(self, o: object) -> bool:
return not (self == o)
Expand All @@ -56,7 +56,7 @@ def __call__(
return self.value() if callable(self.value) else self.value

def __eq__(self, o: object) -> bool:
return type(self) == type(o) and super().__eq__(o) and self.value == o.value # type: ignore[attr-defined]
return type(self) == type(o) and super().__eq__(o) and self.value == o.value # type: ignore[attr-defined] # noqa: E721

def __repr__(self) -> str:
values = ((k, v) for k, v in vars(self).items() if v is not None)
Expand Down Expand Up @@ -120,7 +120,7 @@ def __repr__(self) -> str:

def __eq__(self, o: object) -> bool:
return (
type(self) == type(o)
type(self) == type(o) # noqa: E721
and super().__eq__(o)
and (self.of_type, self.default, self.post_process) == (o.of_type, o.default, o.post_process) # type: ignore[attr-defined]
)
Expand Down
6 changes: 3 additions & 3 deletions src/tox/config/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import annotations
from __future__ import annotations # noqa: A005

from collections import OrderedDict
from typing import Iterator, Sequence
Expand Down Expand Up @@ -26,7 +26,7 @@ def __repr__(self) -> str:
return f"{type(self).__name__}(args={args!r})"

def __eq__(self, other: object) -> bool:
return type(self) == type(other) and (self.args, self.ignore_exit_code, self.invert_exit_code) == (
return type(self) == type(other) and (self.args, self.ignore_exit_code, self.invert_exit_code) == ( # noqa: E721
other.args, # type: ignore[attr-defined]
other.ignore_exit_code, # type: ignore[attr-defined]
other.invert_exit_code, # type: ignore[attr-defined]
Expand Down Expand Up @@ -56,7 +56,7 @@ def __repr__(self) -> str:
return f"{type(self).__name__}({self.envs!r})"

def __eq__(self, other: object) -> bool:
return type(self) == type(other) and self.envs == other.envs # type: ignore[attr-defined]
return type(self) == type(other) and self.envs == other.envs # type: ignore[attr-defined] # noqa: E721

def __ne__(self, other: object) -> bool:
return not (self == other)
Expand Down
5 changes: 3 additions & 2 deletions src/tox/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from contextlib import contextmanager
from io import BytesIO, TextIOWrapper
from pathlib import Path
from threading import Thread, current_thread, enumerate, local
from threading import Thread, current_thread, local
from threading import enumerate as enumerate_threads
from typing import IO, ClassVar, Iterator, Tuple

from colorama import Fore, Style, init
Expand Down Expand Up @@ -58,7 +59,7 @@ def name(self) -> str:
def name(self, value: str) -> None:
self._name = value

for ident in self._ident_to_data.keys() - {t.ident for t in enumerate()}:
for ident in self._ident_to_data.keys() - {t.ident for t in enumerate_threads()}:
self._ident_to_data.pop(ident)
self._ident_to_data[current_thread().ident] = value

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
2 changes: 1 addition & 1 deletion src/tox/session/env_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __repr__(self) -> str:
return f"{self.__class__.__name__}({'' if self.is_default_list else repr(str(self))})"

def __eq__(self, other: object) -> bool:
return type(self) == type(other) and self._names == other._names # type: ignore[attr-defined]
return type(self) == type(other) and self._names == other._names # type: ignore[attr-defined] # noqa: E721

def __ne__(self, other: object) -> bool:
return not (self == other)
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 5425133

Please sign in to comment.