From 5425133459e9c0194c536eac332c06178ac0700e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Mon, 5 Aug 2024 12:46:29 -0700 Subject: [PATCH] Add on platform constat to core (#3315) --- docs/changelog/3315.feature.rst | 2 ++ docs/config.rst | 6 ++++++ pyproject.toml | 16 +++++++++------- src/tox/config/cli/parser.py | 2 +- src/tox/config/loader/api.py | 2 +- src/tox/config/of_type.py | 6 +++--- src/tox/config/types.py | 6 +++--- src/tox/report.py | 5 +++-- src/tox/session/cmd/exec_.py | 1 + src/tox/session/env_select.py | 2 +- src/tox/session/state.py | 6 ++++++ tests/session/cmd/test_show_config.py | 7 +++++++ tox.ini | 6 +++--- 13 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 docs/changelog/3315.feature.rst diff --git a/docs/changelog/3315.feature.rst b/docs/changelog/3315.feature.rst new file mode 100644 index 000000000..7f3a8f708 --- /dev/null +++ b/docs/changelog/3315.feature.rst @@ -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`. diff --git a/docs/config.rst b/docs/config.rst index 49d7b9b09..ecbbd2d92 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pyproject.toml b/pyproject.toml index 21bf402ca..af6802593 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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", @@ -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", ] @@ -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 diff --git a/src/tox/config/cli/parser.py b/src/tox/config/cli/parser.py index c8d13f797..45ede3cdc 100644 --- a/src/tox/config/cli/parser.py +++ b/src/tox/config/cli/parser.py @@ -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 diff --git a/src/tox/config/loader/api.py b/src/tox/config/loader/api.py index 84a17c6e1..d0437357b 100644 --- a/src/tox/config/loader/api.py +++ b/src/tox/config/loader/api.py @@ -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] diff --git a/src/tox/config/of_type.py b/src/tox/config/of_type.py index a53456c82..27752ef0f 100644 --- a/src/tox/config/of_type.py +++ b/src/tox/config/of_type.py @@ -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) @@ -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) @@ -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] ) diff --git a/src/tox/config/types.py b/src/tox/config/types.py index 8086ea66f..571372596 100644 --- a/src/tox/config/types.py +++ b/src/tox/config/types.py @@ -1,4 +1,4 @@ -from __future__ import annotations +from __future__ import annotations # noqa: A005 from collections import OrderedDict from typing import Iterator, Sequence @@ -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] @@ -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) diff --git a/src/tox/report.py b/src/tox/report.py index 1d4bf0c6e..07c8e8b64 100644 --- a/src/tox/report.py +++ b/src/tox/report.py @@ -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 @@ -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 diff --git a/src/tox/session/cmd/exec_.py b/src/tox/session/cmd/exec_.py index 69a332acd..4ce3e947e 100644 --- a/src/tox/session/cmd/exec_.py +++ b/src/tox/session/cmd/exec_.py @@ -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)}" diff --git a/src/tox/session/env_select.py b/src/tox/session/env_select.py index 4d5327eed..fe4d1c5ba 100644 --- a/src/tox/session/env_select.py +++ b/src/tox/session/env_select.py @@ -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) diff --git a/src/tox/session/state.py b/src/tox/session/state.py index c1719cc2d..f81c9031a 100644 --- a/src/tox/session/state.py +++ b/src/tox/session/state.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from typing import TYPE_CHECKING, Sequence from tox.config.main import Config @@ -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) diff --git a/tests/session/cmd/test_show_config.py b/tests/session/cmd/test_show_config.py index f2272cda8..721ad5ffd 100644 --- a/tests/session/cmd/test_show_config.py +++ b/tests/session/cmd/test_show_config.py @@ -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" diff --git a/tox.ini b/tox.ini index 3e1ce61ee..dc96c5af9 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -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