Skip to content

Commit c88d497

Browse files
authored
Better selection support (#2290)
1 parent e62a717 commit c88d497

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+944
-576
lines changed

.github/workflows/check.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v2
1717
- uses: actions/setup-python@v2
18-
- uses: pre-commit/[email protected].0
18+
- uses: pre-commit/[email protected].3
1919

2020
test:
21-
name: test ${{ matrix.py }} - ${{ matrix.os }}
22-
runs-on: ${{ matrix.os }}-latest
21+
name: test ${{ matrix.py }} on ${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
2323
strategy:
2424
fail-fast: false
2525
matrix:
@@ -29,9 +29,9 @@ jobs:
2929
- "3.8"
3030
- "3.7"
3131
os:
32-
- Ubuntu
33-
- Windows
34-
- MacOs
32+
- ubuntu-20.04
33+
- windows-2022
34+
- macos-11
3535
steps:
3636
- name: Setup python for tox
3737
uses: actions/setup-python@v2
@@ -78,21 +78,21 @@ jobs:
7878
name: ${{ matrix.py }} - ${{ matrix.os }}
7979

8080
check:
81-
name: check ${{ matrix.tox_env }} - ${{ matrix.os }}
82-
runs-on: ${{ matrix.os }}-latest
81+
name: tox env ${{ matrix.tox_env }} on ${{ matrix.os }}
82+
runs-on: ${{ matrix.os }}
8383
strategy:
8484
fail-fast: false
8585
matrix:
86-
os:
87-
- Windows
88-
- Ubuntu
8986
tox_env:
9087
- type
9188
- dev
9289
- docs
9390
- pkg_meta
91+
os:
92+
- ubuntu-20.04
93+
- windows-2022
9494
exclude:
95-
- { os: windows, tox_env: pkg_meta }
95+
- { os: windows-2022, tox_env: pkg_meta }
9696
steps:
9797
- uses: actions/checkout@v2
9898
with:
@@ -111,7 +111,7 @@ jobs:
111111
publish:
112112
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
113113
needs: [check, test, pre_commit]
114-
runs-on: ubuntu-latest
114+
runs-on: ubuntu-20.04
115115
steps:
116116
- name: Setup python to build package
117117
uses: actions/setup-python@v2

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.0.1
3+
rev: v4.1.0
44
hooks:
55
- id: check-builtin-literals
66
- id: check-docstring-first
@@ -17,7 +17,7 @@ repos:
1717
- id: add-trailing-comma
1818
args: [--py36-plus]
1919
- repo: https://github.com/asottile/pyupgrade
20-
rev: v2.29.1
20+
rev: v2.30.1
2121
hooks:
2222
- id: pyupgrade
2323
args: ["--py37-plus"]
@@ -43,7 +43,7 @@ repos:
4343
- id: prettier
4444
additional_dependencies:
4545
46-
- "@prettier/plugin-xml@1.1.0"
46+
- "@prettier/plugin-xml@1.2.0"
4747
args: ["--print-width=120", "--prose-wrap=always"]
4848
- repo: https://github.com/asottile/blacken-docs
4949
rev: v1.12.0
@@ -55,7 +55,7 @@ repos:
5555
hooks:
5656
- id: setup-cfg-fmt
5757
- repo: https://github.com/tox-dev/tox-ini-fmt
58-
rev: "0.5.1"
58+
rev: "0.5.2"
5959
hooks:
6060
- id: tox-ini-fmt
6161
args: ["-p", "fix"]

docs/changelog/2275.removal.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``tox_add_core_config`` and ``tox_add_env_config`` now take a ``state: State`` argument instead of a configuration one,
2+
and ``Config`` not longer provides the ``envs`` property (instead users should migrate to ``State.envs``) - by
3+
:user:`gaborbernat`.

docs/changelog/2290.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Support for selecting target environments with a given factor via the :ref:`-m <tox-run--f>` CLI environment flag - by
2+
:user:`gaborbernat`.

docs/changelog/238.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Support for grouping environment values together by applying labels to them either at :ref:`core <labels>` and
2+
:ref:`environment <labels-env>` level, and allow selecting them via the :ref:`-m <tox-run--m>` flag from the CLI - by
3+
:user:`gaborbernat`.

docs/conf.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,16 @@ def resolve_xref(
142142
"tox.tox_env.installer.T": "typing.TypeVar",
143143
"ToxParserT": "typing.TypeVar",
144144
"_Section": "Section",
145+
"ArgumentParser": "argparse.ArgumentParser",
146+
"Factory": "tox.config.loader.convert.Factory",
145147
}
146148
if target in mapping:
149+
if target == "Factory":
150+
type = "attr"
147151
node["reftarget"] = mapping[target]
148-
if target == "_Section":
149-
target = "Section"
150-
contnode = Text(target, target)
151-
152+
if target == "_Section":
153+
target = "Section"
154+
contnode = Text(target, target)
152155
return super().resolve_xref(env, fromdocname, builder, type, target, node, contnode)
153156

154157
app.connect("autodoc-skip-member", skip_member)

docs/config.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ Core
195195

196196
Indicates where the packaging root file exists (historically setup.py file or pyproject.toml now).
197197

198+
.. conf::
199+
:keys: labels
200+
:default: <empty dictionary>
201+
202+
A mapping of label names to environments it applies too. For example:
203+
204+
.. code-block:: ini
205+
206+
[tox]
207+
labels =
208+
test = py310, py39
209+
static = flake8, mypy
210+
198211
Python language core options
199212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200213

@@ -304,6 +317,20 @@ Base options
304317
``allowlist_externals=make`` or ``allowlist_externals=/usr/bin/make``. If you want to allow all external commands
305318
you can use ``allowlist_externals=*`` which will match all commands (not recommended).
306319

320+
.. conf::
321+
:keys: labels
322+
:default: <empty list>
323+
:ref_suffix: env
324+
325+
A list of labels to apply for this environment. For example:
326+
327+
.. code-block:: ini
328+
329+
[testenv]
330+
labels = test, core
331+
[testenv:flake8]
332+
labels = mypy
333+
307334
Execute
308335
~~~~~~~
309336

docs/plugins_api.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ config
7373
.. autoclass:: tox.config.types.Command
7474
:members:
7575

76+
.. autoclass:: tox.config.loader.convert.Factory
77+
:members:
78+
7679
environments
7780
------------
7881
.. autoclass:: tox.tox_env.api.ToxEnv
@@ -128,3 +131,14 @@ installer
128131

129132
.. autoclass:: tox.tox_env.installer.Installer
130133
:members:
134+
135+
session
136+
-------
137+
.. autoclass:: tox.session.state.State
138+
:members:
139+
140+
.. autoclass:: tox.session.env_select.EnvSelector
141+
:members:
142+
143+
.. autoclass:: tox.tox_env.info.Info
144+
:members:

src/tox/config/cli/parse.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@
33
"""
44
from __future__ import annotations
55

6-
from typing import Dict, Sequence, cast
6+
from typing import TYPE_CHECKING, Callable, NamedTuple, Sequence, cast
77

88
from tox.config.source import Source, discover_source
99
from tox.report import ToxHandler, setup_report
1010

11-
from .parser import Handler, Parsed, ToxParser
11+
from .parser import Parsed, ToxParser
1212

13-
Handlers = Dict[str, Handler]
13+
if TYPE_CHECKING:
14+
from tox.session.state import State
1415

1516

16-
def get_options(*args: str) -> tuple[Parsed, Handlers, Sequence[str] | None, ToxHandler, Source]:
17+
class Options(NamedTuple):
18+
parsed: Parsed
19+
pos_args: Sequence[str] | None
20+
source: Source
21+
cmd_handlers: dict[str, Callable[[State], int]]
22+
log_handler: ToxHandler
23+
24+
25+
def get_options(*args: str) -> Options:
1726
pos_args: tuple[str, ...] | None = None
1827
try: # remove positional arguments passed to parser if specified, they are pulled directly from sys.argv
1928
pos_arg_at = args.index("--")
@@ -27,7 +36,7 @@ def get_options(*args: str) -> tuple[Parsed, Handlers, Sequence[str] | None, Tox
2736
parsed, cmd_handlers = _get_all(args)
2837
if guess_verbosity != parsed.verbosity:
2938
setup_report(parsed.verbosity, parsed.is_colored) # pragma: no cover
30-
return parsed, cmd_handlers, pos_args, log_handler, source
39+
return Options(parsed, pos_args, source, cmd_handlers, log_handler)
3140

3241

3342
def _get_base(args: Sequence[str]) -> tuple[int, ToxHandler, Source]:
@@ -45,7 +54,7 @@ def _get_base(args: Sequence[str]) -> tuple[int, ToxHandler, Source]:
4554
return guess_verbosity, handler, source
4655

4756

48-
def _get_all(args: Sequence[str]) -> tuple[Parsed, Handlers]:
57+
def _get_all(args: Sequence[str]) -> tuple[Parsed, dict[str, Callable[[State], int]]]:
4958
"""Parse all the options."""
5059
tox_parser = _get_parser()
5160
parsed = cast(Parsed, tox_parser.parse_args(args))
@@ -75,5 +84,5 @@ def _get_parser_doc() -> ToxParser:
7584

7685
__all__ = (
7786
"get_options",
78-
"Handlers",
87+
"Options",
7988
)

src/tox/config/cli/parser.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
import sys
1010
from argparse import SUPPRESS, Action, ArgumentDefaultsHelpFormatter, ArgumentParser, Namespace
1111
from pathlib import Path
12-
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, TypeVar, cast
12+
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, TypeVar, cast
1313

1414
from tox.config.loader.str_convert import StrConvert
1515
from tox.plugin import NAME
16-
from tox.session.state import State
1716

1817
from .env_var import get_env_var
1918
from .ini import IniConfig
@@ -23,6 +22,9 @@
2322
else: # pragma: no cover (py38+)
2423
from typing_extensions import Literal
2524

25+
if TYPE_CHECKING:
26+
from tox.session.state import State
27+
2628

2729
class ArgumentParserWithEnvAndConfig(ArgumentParser):
2830
"""
@@ -93,8 +95,6 @@ def _get_help_string(self, action: Action) -> str | None:
9395
return text
9496

9597

96-
Handler = Callable[[State], int]
97-
9898
ToxParserT = TypeVar("ToxParserT", bound="ToxParser")
9999
DEFAULT_VERBOSITY = 2
100100

@@ -122,7 +122,7 @@ class ToxParser(ArgumentParserWithEnvAndConfig):
122122

123123
def __init__(self, *args: Any, root: bool = False, add_cmd: bool = False, **kwargs: Any) -> None:
124124
self.of_cmd: str | None = None
125-
self.handlers: dict[str, tuple[Any, Handler]] = {}
125+
self.handlers: dict[str, tuple[Any, Callable[[State], int]]] = {}
126126
self._arguments: list[ArgumentArgs] = []
127127
self._groups: list[tuple[Any, dict[str, Any], list[tuple[dict[str, Any], list[ArgumentArgs]]]]] = []
128128
super().__init__(*args, **kwargs)
@@ -136,7 +136,13 @@ def __init__(self, *args: Any, root: bool = False, add_cmd: bool = False, **kwar
136136
else:
137137
self._cmd = None
138138

139-
def add_command(self, cmd: str, aliases: Sequence[str], help_msg: str, handler: Handler) -> ArgumentParser:
139+
def add_command(
140+
self,
141+
cmd: str,
142+
aliases: Sequence[str],
143+
help_msg: str,
144+
handler: Callable[[State], int],
145+
) -> ArgumentParser:
140146
if self._cmd is None:
141147
raise RuntimeError("no sub-command group allowed")
142148
sub_parser: ToxParser = self._cmd.add_parser(
@@ -217,7 +223,7 @@ def _add_base_options(self) -> None:
217223

218224
def parse_known_args( # type: ignore[override]
219225
self,
220-
args: Sequence[str] | None,
226+
args: Sequence[str] | None = None,
221227
namespace: Parsed | None = None,
222228
) -> tuple[Parsed, list[str]]:
223229
if args is None:
@@ -315,5 +321,4 @@ def add_core_arguments(parser: ArgumentParser) -> None:
315321
"DEFAULT_VERBOSITY",
316322
"Parsed",
317323
"ToxParser",
318-
"Handler",
319324
)

0 commit comments

Comments
 (0)