Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tox-dev/tox
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4.1.1
Choose a base ref
...
head repository: tox-dev/tox
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4.1.2
Choose a head ref
  • 4 commits
  • 16 files changed
  • 2 contributors

Commits on Dec 30, 2022

  1. Fix --skip-missing-interpreters (#2793)

    Closes #2649
    q0w authored Dec 30, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d8c4cb0 View commit details

Commits on Dec 31, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a3d3ec0 View commit details
  2. Fix extracting extras from markers with many extras (#2792)

    Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
    q0w and gaborbernat authored Dec 31, 2022

    Partially verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
    Copy the full SHA
    196b20d View commit details
  3. release 4.1.2

    gaborbernat committed Dec 31, 2022

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    6253d62 View commit details
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -4,6 +4,17 @@ Release History

.. towncrier release notes start
v4.1.2 (2022-12-30)
-------------------

Bugfixes - 4.1.2
~~~~~~~~~~~~~~~~
- Fix ``--skip-missing-interpreters`` behaviour - by :user:`q0w`. (:issue:`2649`)
- Restore tox 3 behaviour of showing the output of pip freeze, however now only active when running inside a CI
environment - by :user:`gaborbernat`. (:issue:`2685`)
- Fix extracting extras from markers with many extras - by :user:`q0w`. (:issue:`2791`)


v4.1.1 (2022-12-29)
-------------------

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling>=1.11.1", "hatch-vcs>=0.3"]
requires = ["hatchling>=1.12", "hatch-vcs>=0.3"]

[project]
name = "tox"
@@ -25,18 +25,18 @@ dependencies = [
"chardet>=5.1",
"colorama>=0.4.6",
"packaging>=22",
"platformdirs>=2.6",
"platformdirs>=2.6.2",
"pluggy>=1",
"pyproject-api>=1.2.1",
'tomli>=2.0.1; python_version < "3.11"',
"virtualenv>=20.17.1",
"filelock>=3.8.2",
"filelock>=3.9",
'importlib-metadata>=5.2; python_version < "3.8"',
'typing-extensions>=4.4; python_version < "3.8"',
]
optional-dependencies.docs = [
"furo>=2022.12.7",
"sphinx>=5.3",
"sphinx>=6",
"sphinx-argparse-cli>=1.10",
"sphinx-autodoc-typehints>=1.19.5",
"sphinx-copybutton>=0.5.1",
@@ -52,7 +52,7 @@ optional-dependencies.testing = [
"distlib>=0.3.6",
"flaky>=3.7",
"hatch-vcs>=0.3",
"hatchling>=1.11.1",
"hatchling>=1.12",
"psutil>=5.9.4",
"pytest>=7.2",
"pytest-cov>=4",
1 change: 1 addition & 0 deletions src/tox/session/cmd/run/single.py
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ def _evaluate(tox_env: RunToxEnv, no_test: bool) -> tuple[bool, int, list[Outcom
code, outcomes = run_commands(tox_env, no_test)
except Skip as exception:
LOGGER.warning("skipped because %s", exception)
code = 0
skipped = True
except ToxBackendFailed as exception:
LOGGER.error("%s", exception)
10 changes: 8 additions & 2 deletions src/tox/tox_env/python/api.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"""
from __future__ import annotations

import logging
import sys
from abc import ABC, abstractmethod
from pathlib import Path
@@ -14,6 +15,7 @@
from tox.config.main import Config
from tox.tox_env.api import ToxEnv, ToxEnvCreateArgs
from tox.tox_env.errors import Fail, Recreate, Skip
from tox.util.ci import is_ci


class VersionInfo(NamedTuple):
@@ -212,9 +214,13 @@ def prepend_env_var_path(self) -> list[Path]:
def _done_with_setup(self) -> None:
"""called when setup is done"""
super()._done_with_setup()
if self.journal:
running_in_ci = is_ci()
if self.journal or running_in_ci:
outcome = self.installer.installed()
self.journal["installed_packages"] = outcome
if self.journal:
self.journal["installed_packages"] = outcome
if running_in_ci:
logging.warning(",".join(outcome))

def python_cache(self) -> dict[str, Any]:
return {
8 changes: 1 addition & 7 deletions src/tox/tox_env/python/pip/pip_install.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@

from packaging.requirements import Requirement

from tox.config.cli.parser import DEFAULT_VERBOSITY
from tox.config.main import Config
from tox.config.types import Command
from tox.execute.request import StdinSource
@@ -69,12 +68,7 @@ def post_process_install_command(self, cmd: Command) -> Command:

def installed(self) -> list[str]:
cmd: Command = self._env.conf["list_dependencies_command"]
result = self._env.execute(
cmd=cmd.args,
stdin=StdinSource.OFF,
run_id="freeze",
show=self._env.options.verbosity > DEFAULT_VERBOSITY,
)
result = self._env.execute(cmd=cmd.args, stdin=StdinSource.OFF, run_id="freeze", show=False)
result.assert_success()
return result.out.splitlines()

8 changes: 8 additions & 0 deletions src/tox/tox_env/python/runner.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
from tox.tox_env.package import Package
from tox.tox_env.python.pip.req_file import PythonDeps

from ...config.loader.str_convert import StrConvert
from ..api import ToxEnvCreateArgs
from ..runner import RunToxEnv
from .api import Python
@@ -32,10 +33,17 @@ def register_config(self) -> None:
default=PythonDeps("", root),
desc="Name of the python dependencies as specified by PEP-440",
)

def skip_missing_interpreters_post_process(value: bool) -> bool:
if getattr(self.options, "skip_missing_interpreters", "config") != "config":
return StrConvert().to_bool(self.options.skip_missing_interpreters)
return value

self.core.add_config(
keys=["skip_missing_interpreters"],
default=True,
of_type=bool,
post_process=skip_missing_interpreters_post_process,
desc="skip running missing interpreters",
)

3 changes: 1 addition & 2 deletions src/tox/tox_env/python/virtual_env/package/util.py
Original file line number Diff line number Diff line change
@@ -45,10 +45,9 @@ def extract_extra_markers(deps: list[Requirement]) -> list[tuple[Requirement, se
extra_markers.add(marker_value.value)
del markers[_at]
_at -= 1
if _at > 0 and (isinstance(markers[_at], str) and markers[_at] in ("and", "or")):
if _at >= 0 and (isinstance(markers[_at], str) and markers[_at] in ("and", "or")):
del markers[_at]
if len(markers) == 0:
req.marker = None
break
result.append((req, extra_markers or {None}))
return result
29 changes: 29 additions & 0 deletions src/tox/util/ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations

import os

_ENV_VARS = { # per https://adamj.eu/tech/2020/03/09/detect-if-your-tests-are-running-on-ci
"CI": None, # generic flag
"TF_BUILD": "true", # Azure Pipelines
"bamboo.buildKey": None, # Bamboo
"BUILDKITE": "true", # Buildkite
"CIRCLECI": "true", # Circle CI
"CIRRUS_CI": "true", # Cirrus CI
"CODEBUILD_BUILD_ID": None, # CodeBuild
"GITHUB_ACTIONS": "true", # GitHub Actions
"GITLAB_CI": None, # GitLab CI
"HEROKU_TEST_RUN_ID": None, # Heroku CI
"BUILD_ID": None, # Hudson
"TEAMCITY_VERSION": None, # TeamCity
"TRAVIS": "true", # Travis CI
}


def is_ci() -> bool:
""":return: a flag indicating if running inside a CI env or not"""
return any(e in os.environ if v is None else os.environ.get(e) == v for e, v in _ENV_VARS.items())


__all__ = [
"is_ci",
]
10 changes: 10 additions & 0 deletions tests/tox_env/python/test_python_api.py
Original file line number Diff line number Diff line change
@@ -179,3 +179,13 @@ def test_python_set_hash_seed_incorrect(tox_project: ToxProjectCreator) -> None:
result = tox_project({"tox.ini": ""}).run("r", "-e", "py", "--hashseed", "ok")
result.assert_failed(2)
assert "tox run: error: argument --hashseed: invalid literal for int() with base 10: 'ok'" in result.err


@pytest.mark.parametrize("in_ci", [True, False])
def test_list_installed_deps(in_ci: bool, tox_project: ToxProjectCreator, mocker: MockerFixture) -> None:
mocker.patch("tox.tox_env.python.api.is_ci", return_value=in_ci)
result = tox_project({"tox.ini": "[testenv]\nskip_install = true"}).run("r", "-e", "py")
if in_ci:
assert "py: pip==" in result.out
else:
assert "py: pip==" not in result.out
12 changes: 12 additions & 0 deletions tests/tox_env/python/test_python_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from pathlib import Path

import pytest
@@ -121,3 +122,14 @@ def test_extras_are_normalized(
result = project.run("c", "-e", "py", "--root", str(demo_pkg_inline), "-k", "extras")
result.assert_success()
assert result.out == f"[testenv:py]\nextras = {used_extra}\n"


@pytest.mark.parametrize(
("config", "cli", "expected"),
[("false", "true", True), ("true", "false", False), ("false", "config", False), ("true", "config", True)],
)
def test_config_skip_missing_interpreters(tox_project: ToxProjectCreator, config: str, cli: str, expected: str) -> None:
py_ver = ".".join(str(i) for i in sys.version_info[0:2])
project = tox_project({"tox.ini": f"[tox]\nenvlist=py4,py{py_ver}\nskip_missing_interpreters={config}"})
result = project.run("--skip-missing-interpreters", cli)
assert result.code == 0 if expected else 1
Original file line number Diff line number Diff line change
@@ -63,3 +63,9 @@ def test_loads_deps_recursive_extras() -> None:
]
result = dependencies_with_extras(requires, {"dev"}, "name")
assert [str(i) for i in result] == ["no-extra", "dep1[magic]", "dep1", "dep2[a,b]"]


def test_load_dependency_requirement_or_extras() -> None:
requires = [Requirement('filelock<4.0.0,>=3.9.0; extra == "extras1" or extra == "extras2"')]
result = dependencies_with_extras(requires, {"extras1"}, "")
assert [str(r) for r in result] == ["filelock<4.0.0,>=3.9.0"]
2 changes: 2 additions & 0 deletions tests/tox_env/test_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from pathlib import Path

from tox.pytest import ToxProjectCreator
2 changes: 2 additions & 0 deletions tests/tox_env/test_tox_env_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from pathlib import Path

from tox.pytest import ToxProjectCreator
56 changes: 56 additions & 0 deletions tests/util/test_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from __future__ import annotations

import pytest

from tox.util.ci import _ENV_VARS, is_ci


@pytest.mark.parametrize(
"env_var",
{
"CI": None, # generic flag
"TF_BUILD": "true", # Azure Pipelines
"bamboo.buildKey": None, # Bamboo
"BUILDKITE": "true", # Buildkite
"CIRCLECI": "true", # Circle CI
"CIRRUS_CI": "true", # Cirrus CI
"CODEBUILD_BUILD_ID": None, # CodeBuild
"GITHUB_ACTIONS": "true", # GitHub Actions
"GITLAB_CI": None, # GitLab CI
"HEROKU_TEST_RUN_ID": None, # Heroku CI
"BUILD_ID": None, # Hudson
"TEAMCITY_VERSION": None, # TeamCity
"TRAVIS": "true", # Travis CI
}.items(),
ids=lambda v: v[0], # type: ignore
)
def test_is_ci(env_var: tuple[str, str | None], monkeypatch: pytest.MonkeyPatch) -> None:
for var in _ENV_VARS:
monkeypatch.delenv(var, raising=False)
monkeypatch.setenv(env_var[0], env_var[1] or "")
assert is_ci()


@pytest.mark.parametrize(
"env_var",
{
"TF_BUILD": "", # Azure Pipelines
"BUILDKITE": "", # Buildkite
"CIRCLECI": "", # Circle CI
"CIRRUS_CI": "", # Cirrus CI
"GITHUB_ACTIONS": "", # GitHub Actions
"TRAVIS": "", # Travis CI
}.items(),
ids=lambda v: v[0], # type: ignore
)
def test_is_ci_bad_set(env_var: tuple[str, str], monkeypatch: pytest.MonkeyPatch) -> None:
for var in _ENV_VARS:
monkeypatch.delenv(var, raising=False)
monkeypatch.setenv(env_var[0], env_var[1])
assert not is_ci()


def test_is_ci_not(monkeypatch: pytest.MonkeyPatch) -> None:
for var in _ENV_VARS:
monkeypatch.delenv(var, raising=False)
assert not is_ci()
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -60,7 +60,6 @@ commands =

[testenv:docs]
description = build documentation
basepython = python3.10
extras =
docs
commands =
@@ -83,7 +82,7 @@ commands =
description = do a release, required posarg of the version number
skip_install = true
deps =
gitpython>=3.1.29
gitpython>=3.1.30
packaging>=22
towncrier>=22.12
commands =
7 changes: 3 additions & 4 deletions whitelist.txt
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ autouse
binprm
buf
bufsize
buildkite
cachetools
canonicalize
capfd
@@ -78,7 +79,6 @@ getresult
getsockname
getsourcelines
groupby
hardlink
hookimpl
hookspec
hookspecs
@@ -92,7 +92,6 @@ isatty
isnumeric
isspace
iterdir
levelname
levelno
libs
lightred
@@ -159,12 +158,12 @@ string2lines
stringify
subparsers
tcgetattr
TCSANOW
tcsanow
tcsetattr
TIOCSWINSZ
termios
termux
testenv
tiocswinsz
tmpdir
toml
tomli