Skip to content

Commit 5425133

Browse files
authored
Add on platform constat to core (#3315)
1 parent 2cf190a commit 5425133

File tree

13 files changed

+46
-21
lines changed

13 files changed

+46
-21
lines changed

docs/changelog/3315.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add :ref:`on_platform` core configuration holding the tox platform and do not install package when exec an environment
2+
- by :user:`gaborbernat`.

docs/config.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ The following options are set in the ``[tox]`` section of ``tox.ini`` or the ``[
215215
test = py310, py39
216216
static = flake8, mypy
217217
218+
.. conf::
219+
:keys: on_platform
220+
:constant:
221+
222+
A constant holding the platform of the tox runtime environment.
223+
218224
Python language core options
219225
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220226

pyproject.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dynamic = [
5050
"version",
5151
]
5252
dependencies = [
53-
"cachetools>=5.3.3",
53+
"cachetools>=5.4",
5454
"chardet>=5.2",
5555
"colorama>=0.4.6",
5656
"filelock>=3.15.4",
@@ -62,10 +62,10 @@ dependencies = [
6262
"virtualenv>=20.26.3",
6363
]
6464
optional-dependencies.docs = [
65-
"furo>=2024.5.6",
66-
"sphinx>=7.3.7",
65+
"furo>=2024.7.18",
66+
"sphinx>=7.4.7",
6767
"sphinx-argparse-cli>=1.16",
68-
"sphinx-autodoc-typehints!=1.23.4,>=2.2.2",
68+
"sphinx-autodoc-typehints>=2.2.3",
6969
"sphinx-copybutton>=0.5.2",
7070
"sphinx-inline-tabs>=2023.4.21",
7171
"sphinxcontrib-towncrier>=0.2.1a0",
@@ -76,18 +76,18 @@ optional-dependencies.testing = [
7676
"covdefaults>=2.3",
7777
"detect-test-pollution>=1.2",
7878
"devpi-process>=1",
79-
"diff-cover>=9.1",
79+
"diff-cover>=9.1.1",
8080
"distlib>=0.3.8",
8181
"flaky>=3.8.1",
8282
"hatch-vcs>=0.4",
8383
"hatchling>=1.25",
8484
"psutil>=6",
85-
"pytest>=8.2.2",
85+
"pytest>=8.3.2",
8686
"pytest-cov>=5",
8787
"pytest-mock>=3.14",
8888
"pytest-xdist>=3.6.1",
8989
"re-assert>=1.1",
90-
"setuptools>=70.2",
90+
"setuptools>=70.3",
9191
"time-machine>=2.14.2; implementation_name!='pypy'",
9292
"wheel>=0.43",
9393
]
@@ -128,6 +128,8 @@ lint.ignore = [
128128
"D", # ignore documentation for now
129129
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
130130
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
131+
"DOC201", # broken with sphinx docs
132+
"DOC501", # broken with sphinx docs
131133
"INP001", # no implicit namespaces here
132134
"ISC001", # conflicts with formatter
133135
"PLR0914", ## Too many local variables

src/tox/config/cli/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Customize argparse logic for tox (also contains the base options)."""
1+
"""Customize argparse logic for tox (also contains the base options).""" # noqa: A005
22

33
from __future__ import annotations
44

src/tox/config/loader/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __str__(self) -> str:
4040
return f"{self.namespace}{'.' if self.namespace else ''}{self.key}={self.value}"
4141

4242
def __eq__(self, other: object) -> bool:
43-
if type(self) != type(other):
43+
if type(self) != type(other): # noqa: E721
4444
return False
4545
return (self.namespace, self.key, self.value) == (
4646
other.namespace, # type: ignore[attr-defined]

src/tox/config/of_type.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __call__(self, conf: Config, loaders: list[Loader[T]], args: ConfigLoadArgs)
2929
raise NotImplementedError
3030

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

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

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

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

121121
def __eq__(self, o: object) -> bool:
122122
return (
123-
type(self) == type(o)
123+
type(self) == type(o) # noqa: E721
124124
and super().__eq__(o)
125125
and (self.of_type, self.default, self.post_process) == (o.of_type, o.default, o.post_process) # type: ignore[attr-defined]
126126
)

src/tox/config/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import annotations
1+
from __future__ import annotations # noqa: A005
22

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

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

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

6161
def __ne__(self, other: object) -> bool:
6262
return not (self == other)

src/tox/report.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from contextlib import contextmanager
1010
from io import BytesIO, TextIOWrapper
1111
from pathlib import Path
12-
from threading import Thread, current_thread, enumerate, local
12+
from threading import Thread, current_thread, local
13+
from threading import enumerate as enumerate_threads
1314
from typing import IO, ClassVar, Iterator, Tuple
1415

1516
from colorama import Fore, Style, init
@@ -58,7 +59,7 @@ def name(self) -> str:
5859
def name(self, value: str) -> None:
5960
self._name = value
6061

61-
for ident in self._ident_to_data.keys() - {t.ident for t in enumerate()}:
62+
for ident in self._ident_to_data.keys() - {t.ident for t in enumerate_threads()}:
6263
self._ident_to_data.pop(ident)
6364
self._ident_to_data[current_thread().ident] = value
6465

src/tox/session/cmd/exec_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def tox_add_option(parser: ToxParser) -> None:
2828

2929

3030
def exec_(state: State) -> int:
31+
state.conf.options.skip_pkg_install = True # avoid package install
3132
envs = list(state.envs.iter())
3233
if len(envs) != 1:
3334
msg = f"exactly one target environment allowed in exec mode but found {', '.join(envs)}"

src/tox/session/env_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __repr__(self) -> str:
6666
return f"{self.__class__.__name__}({'' if self.is_default_list else repr(str(self))})"
6767

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

7171
def __ne__(self, other: object) -> bool:
7272
return not (self == other)

src/tox/session/state.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
from typing import TYPE_CHECKING, Sequence
45

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

1920
def __init__(self, options: Options, args: Sequence[str]) -> None:
2021
self.conf = Config.make(options.parsed, options.pos_args, options.source)
22+
self.conf.core.add_constant(
23+
keys=["on_platform"],
24+
desc="platform we are running on",
25+
value=sys.platform,
26+
)
2127
self._options = options
2228
self.args = args
2329
self._journal: Journal = Journal(getattr(options.parsed, "result_json", None) is not None)

tests/session/cmd/test_show_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,10 @@ def test_package_env_inherits_from_pkgenv(tox_project: ToxProjectCreator, demo_p
283283
"""
284284
exp = dedent(exp)
285285
assert exp in outcome.out
286+
287+
288+
def test_core_on_platform(tox_project: ToxProjectCreator) -> None:
289+
project = tox_project({"tox.ini": "[tox]\nno_package = true"})
290+
result = project.run("c", "-e", "py", "--core", "-k", "on_platform")
291+
result.assert_success()
292+
assert result.out == f"[testenv:py]\n\n[tox]\non_platform = {sys.platform}\n"

tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ commands =
4040
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
4141
skip_install = true
4242
deps =
43-
pre-commit>=3.7.1
43+
pre-commit>=3.8
4444
pass_env =
4545
{[testenv]passenv}
4646
PROGRAMDATA
@@ -51,8 +51,8 @@ commands =
5151
[testenv:type]
5252
description = run type check on code base
5353
deps =
54-
mypy==1.10.1
55-
types-cachetools>=5.3.0.7
54+
mypy==1.11
55+
types-cachetools>=5.4.0.20240717
5656
types-chardet>=5.0.4.6
5757
commands =
5858
mypy src/tox

0 commit comments

Comments
 (0)