diff options
author | Bernát Gábor <gaborjbernat@gmail.com> | 2023-01-03 18:05:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 18:05:12 -0800 |
commit | 82dcd45af55af239a7be81ee2e86948c6fe75518 (patch) | |
tree | fc35818cc20bf04b64e77c046b8726bc280ce320 /src | |
parent | 31c8d1fc48ccf95f66b2920b356f9490686ccfc7 (diff) | |
download | tox-git-82dcd45af55af239a7be81ee2e86948c6fe75518.tar.gz |
Packaging inherits from pkgenv, deps and document tox 4 packaging changes (#2813)
Resolves https://github.com/tox-dev/tox/issues/2543
Diffstat (limited to 'src')
-rw-r--r-- | src/tox/config/main.py | 6 | ||||
-rw-r--r-- | src/tox/config/source/api.py | 2 | ||||
-rw-r--r-- | src/tox/config/source/ini.py | 6 | ||||
-rw-r--r-- | src/tox/config/source/ini_section.py | 2 | ||||
-rw-r--r-- | src/tox/tox_env/python/package.py | 11 | ||||
-rw-r--r-- | src/tox/util/ci.py | 7 |
6 files changed, 25 insertions, 9 deletions
diff --git a/src/tox/config/main.py b/src/tox/config/main.py index 38efb600..00aaaed8 100644 --- a/src/tox/config/main.py +++ b/src/tox/config/main.py @@ -152,10 +152,10 @@ class Config: :param loaders: loaders to use for this configuration (only used for creation) :return: the tox environments config """ - section, base = self._src.get_tox_env_section(item) + section, base_test, base_pkg = self._src.get_tox_env_section(item) conf_set = self.get_section_config( section, - base=None if package else base, + base=base_pkg if package else base_test, of_type=EnvConfigSet, for_env=item, loaders=loaders, @@ -163,7 +163,7 @@ class Config: return conf_set def clear_env(self, name: str) -> None: - section, _ = self._src.get_tox_env_section(name) + section, _, __ = self._src.get_tox_env_section(name) del self._key_to_conf_set[(section.key, name)] diff --git a/src/tox/config/source/api.py b/src/tox/config/source/api.py index 3b95d504..e762d479 100644 --- a/src/tox/config/source/api.py +++ b/src/tox/config/source/api.py @@ -98,7 +98,7 @@ class Source(ABC): raise NotImplementedError @abstractmethod - def get_tox_env_section(self, item: str) -> tuple[Section, list[str]]: + def get_tox_env_section(self, item: str) -> tuple[Section, list[str], list[str]]: """:returns: the section for a tox environment""" raise NotImplementedError diff --git a/src/tox/config/source/ini.py b/src/tox/config/source/ini.py index f3e0c083..df6c2876 100644 --- a/src/tox/config/source/ini.py +++ b/src/tox/config/source/ini.py @@ -14,7 +14,7 @@ from ..loader.ini import IniLoader from ..loader.section import Section from ..sets import ConfigSet from .api import Source -from .ini_section import CORE, TEST_ENV_PREFIX, IniSection +from .ini_section import CORE, PKG_ENV_PREFIX, TEST_ENV_PREFIX, IniSection class IniSource(Source): @@ -62,8 +62,8 @@ class IniSource(Source): if in_section.prefix is not None: # no prefix specified, so this could imply our own prefix yield IniSection(in_section.prefix, a_base) - def get_tox_env_section(self, item: str) -> tuple[Section, list[str]]: - return IniSection.test_env(item), [TEST_ENV_PREFIX] + def get_tox_env_section(self, item: str) -> tuple[Section, list[str], list[str]]: + return IniSection.test_env(item), [TEST_ENV_PREFIX], [PKG_ENV_PREFIX] def envs(self, core_config: ConfigSet) -> Iterator[str]: seen = set() diff --git a/src/tox/config/source/ini_section.py b/src/tox/config/source/ini_section.py index 33a71863..a155dc1f 100644 --- a/src/tox/config/source/ini_section.py +++ b/src/tox/config/source/ini_section.py @@ -20,10 +20,12 @@ class IniSection(Section): TEST_ENV_PREFIX = "testenv" +PKG_ENV_PREFIX = "pkgenv" CORE = IniSection(None, "tox") __all__ = [ "IniSection", "CORE", "TEST_ENV_PREFIX", + "PKG_ENV_PREFIX", ] diff --git a/src/tox/tox_env/python/package.py b/src/tox/tox_env/python/package.py index 910554a8..289bd774 100644 --- a/src/tox/tox_env/python/package.py +++ b/src/tox/tox_env/python/package.py @@ -5,7 +5,7 @@ from __future__ import annotations from abc import ABC, abstractmethod from pathlib import Path -from typing import TYPE_CHECKING, Any, Generator, Iterator, Sequence, cast +from typing import TYPE_CHECKING, Any, Generator, Iterator, List, Sequence, cast from packaging.requirements import Requirement @@ -56,6 +56,7 @@ class PythonPackageToxEnv(Python, PackageToxEnv, ABC): """setup the tox environment""" super()._setup_env() self._install(self.requires(), PythonPackageToxEnv.__name__, "requires") + self._install(self.conf["deps"], PythonPackageToxEnv.__name__, "deps") @abstractmethod def requires(self) -> tuple[Requirement, ...] | PythonDeps: @@ -63,6 +64,14 @@ class PythonPackageToxEnv(Python, PackageToxEnv, ABC): def register_run_env(self, run_env: RunToxEnv) -> Generator[tuple[str, str], PackageToxEnv, None]: yield from super().register_run_env(run_env) + if run_env.conf["package"] != "skip" and "deps" not in self.conf: + self.conf.add_config( + keys="deps", + of_type=List[Requirement], + default=[], + desc="Name of the python dependencies as specified by PEP-440", + ) + if ( not isinstance(run_env, Python) or run_env.conf["package"] not in {"wheel", "editable"} diff --git a/src/tox/util/ci.py b/src/tox/util/ci.py index b65b2be6..30ba80ed 100644 --- a/src/tox/util/ci.py +++ b/src/tox/util/ci.py @@ -21,7 +21,12 @@ _ENV_VARS = { # per https://adamj.eu/tech/2020/03/09/detect-if-your-tests-are-r 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()) + for env_key, value in _ENV_VARS.items(): + if env_key in os.environ if value is None else os.environ.get(env_key) == value: + if env_key == "TEAMCITY_VERSION" and os.environ.get(env_key) == "LOCAL": + continue + return True + return False __all__ = [ |