Skip to content

Commit

Permalink
Add factor support
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 Jan 4, 2022
1 parent d6966d4 commit 997cd24
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 37 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].3

test:
name: test ${{ matrix.py }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
name: test ${{ matrix.py }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
Expand All @@ -29,9 +29,9 @@ jobs:
- "3.8"
- "3.7"
os:
- Ubuntu
- Windows
- MacOs
- ubuntu-20.04
- windows-2022
- macos-11
steps:
- name: Setup python for tox
uses: actions/setup-python@v2
Expand Down Expand Up @@ -78,21 +78,21 @@ jobs:
name: ${{ matrix.py }} - ${{ matrix.os }}

check:
name: check ${{ matrix.tox_env }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
name: tox env ${{ matrix.tox_env }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- Windows
- Ubuntu
tox_env:
- type
- dev
- docs
- pkg_meta
os:
- ubuntu-20.04
- windows-2022
exclude:
- { os: windows, tox_env: pkg_meta }
- { os: windows-2022, tox_env: pkg_meta }
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -111,7 +111,7 @@ jobs:
publish:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [check, test, pre_commit]
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Setup python to build package
uses: actions/setup-python@v2
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2275.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop python 3.6 support - by :user:`gaborbernat`.
27 changes: 27 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ Core

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

.. conf::
:keys: lables
:default: <empty dictionary>

A mapping of label names to environments it applies too. For example:

.. code-block:: ini
[tox]
labels =
test = py310, py39
static = flake8, mypy
Python language core options
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

.. conf::
:keys: lables
:default: <empty list>
:ref_suffix: env

A list of labels to apply for this environment. For example:

.. code-block:: ini
[testenv]
labels = test, core
[testenv:flake8]
labels = mypy
Execute
~~~~~~~

Expand Down
36 changes: 20 additions & 16 deletions src/tox/session/env_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _env_name_to_active(self) -> dict[str, bool]:
if name not in env_name_to_active_map:
env_name_to_active_map[name] = is_active
# for factor/label selection update the active flag
if not (self._state.conf.options.labels or self._state.conf.options.factors):
if not (getattr(self._state.conf.options, "labels", []) or getattr(self._state.conf.options, "factors", [])):
# if no active environment is defined fallback to py
if self.on_empty_fallback_py and not any(env_name_to_active_map.values()):
env_name_to_active_map["py"] = True
Expand Down Expand Up @@ -209,21 +209,6 @@ def _defined_envs(self) -> dict[str, _ToxEnvInfo]:
self._mark_active()
return self._defined_envs_

def _mark_active(self):
labels, factors = set(self._state.conf.options.labels), set(self._state.conf.options.factors)
if labels or factors:
for env_info in self._defined_envs_.values():
env_info.is_active = False # if any was selected reset
if labels:
for label in labels:
for env_name in self._state.conf.core["labels"].get(label, []):
self._defined_envs_[env_name].is_active = True
for env_info in self._defined_envs_.values():
if labels.intersection(env_info.env.conf["labels"]):
env_info.is_active = True
if self._state.conf.options.factors: # if matches mark it active
raise NotImplementedError

def _build_run_env(self, name: str) -> RunToxEnv | None:
if self._provision is not None and self._provision[0] is False and name == self._provision[1]:
return None
Expand Down Expand Up @@ -285,6 +270,25 @@ def _get_package_env(self, packager: str, name: str, is_active: bool) -> Package
self._manager.tox_add_env_config(pkg_conf, self._state)
return pkg_env

def _mark_active(self) -> None:
labels = set(getattr(self._state.conf.options, "labels", []))
factors = set(getattr(self._state.conf.options, "factors", []))
assert self._defined_envs_ is not None
if labels or factors:
for env_info in self._defined_envs_.values():
env_info.is_active = False # if any was selected reset
if labels:
for label in labels:
for env_name in self._state.conf.core["labels"].get(label, []):
self._defined_envs_[env_name].is_active = True
for env_info in self._defined_envs_.values():
if labels.intersection(env_info.env.conf["labels"]):
env_info.is_active = True
if self._state.conf.options.factors: # if matches mark it active
for name, env_info in self._defined_envs_.items():
if factors.issubset(set(name.split("-"))):
env_info.is_active = True

def __getitem__(self, item: str) -> RunToxEnv | PackageToxEnv:
"""
:param item: the name of the environment
Expand Down
4 changes: 4 additions & 0 deletions tests/config/cli/test_cli_env_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_verbose_no_test() -> None:
"parallel_no_spinner": False,
"pre": False,
"index_url": [],
"factors": [],
"labels": [],
}


Expand Down Expand Up @@ -114,6 +116,8 @@ def test_env_var_exhaustive_parallel_values(
"work_dir": None,
"root_dir": None,
"config_file": None,
"factors": [],
"labels": [],
}
assert options.parsed.verbosity == 4
assert options.cmd_handlers == core_handlers
Expand Down
4 changes: 4 additions & 0 deletions tests/config/cli/test_cli_ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def default_options(tmp_path: Path) -> dict[str, Any]:
"work_dir": None,
"root_dir": None,
"config_file": (tmp_path / "tox.ini").absolute(),
"factors": [],
"labels": [],
}


Expand Down Expand Up @@ -124,6 +126,8 @@ def test_ini_exhaustive_parallel_values(exhaustive_ini: Path, core_handlers: dic
"work_dir": None,
"root_dir": None,
"config_file": exhaustive_ini,
"factors": [],
"labels": [],
}
assert options.parsed.verbosity == 4
assert options.cmd_handlers == core_handlers
Expand Down
11 changes: 11 additions & 0 deletions tests/session/test_env_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ def test_label_core_and_trait(tox_project: ToxProjectCreator) -> None:
outcome = project.run("l", "--no-desc", "-m", "test", "static")
outcome.assert_success()
outcome.assert_out_err("py310\npy39\nflake8\ntype\n", "")


def test_factor_select(tox_project: ToxProjectCreator) -> None:
ini = """
[tox]
env_list = py3{10,9}-{django20,django21}{-cov,}
"""
project = tox_project({"tox.ini": ini})
outcome = project.run("l", "--no-desc", "-f", "cov", "django20")
outcome.assert_success()
outcome.assert_out_err("py310-django20-cov\npy39-django20-cov\n", "")
9 changes: 1 addition & 8 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ doc2path
docname
docutils
dotall
dpkg
e3
e4
ebadf
Expand Down Expand Up @@ -114,10 +113,8 @@ intersphinx
isalpha
isatty
isspace
issubset
iterdir
iwgrp
iwoth
iwusr
kernel32
levelname
levelno
Expand Down Expand Up @@ -161,7 +158,6 @@ prog
proj
psutil
purelib
py37
py38
py39
pygments
Expand Down Expand Up @@ -219,13 +215,10 @@ trylast
tty
typehints
typeshed
unbuffered
unescaped
unimported
unittest
unlink
unregister
untyped
url2pathname
usedevelop
usefixtures
Expand Down

0 comments on commit 997cd24

Please sign in to comment.