diff --git a/docs/changelog/3200.feature.rst b/docs/changelog/3200.feature.rst new file mode 100644 index 000000000..dbd39da38 --- /dev/null +++ b/docs/changelog/3200.feature.rst @@ -0,0 +1 @@ +Extract virtual environment packaging code to its own base class not tied to ``virtualenv`` - by :user:`gaborbernat`. diff --git a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py index a73ebf1a5..8b57b31d4 100644 --- a/src/tox/tox_env/python/virtual_env/package/cmd_builder.py +++ b/src/tox/tox_env/python/virtual_env/package/cmd_builder.py @@ -2,6 +2,7 @@ import glob import tarfile +from abc import ABC from functools import partial from io import TextIOWrapper from pathlib import Path @@ -35,15 +36,11 @@ from importlib.metadata import Distribution -class VirtualEnvCmdBuilder(PythonPackageToxEnv, VirtualEnv): +class VenvCmdBuilder(PythonPackageToxEnv, ABC): def __init__(self, create_args: ToxEnvCreateArgs) -> None: super().__init__(create_args) self._sdist_meta_tox_env: Pep517VirtualEnvPackager | None = None - @staticmethod - def id() -> str: - return "virtualenv-cmd-builder" - def register_config(self) -> None: super().register_config() root = self.core["toxinidir"] @@ -131,6 +128,12 @@ def child_pkg_envs(self, run_conf: EnvConfigSet) -> Iterator[PackageToxEnv]: # yield self._sdist_meta_tox_env +class VirtualEnvCmdBuilder(VenvCmdBuilder, VirtualEnv): + @staticmethod + def id() -> str: + return "virtualenv-cmd-builder" + + class WheelDistribution(Distribution): # cannot subclass has type Any def __init__(self, wheel: Path) -> None: self._wheel = wheel @@ -165,3 +168,9 @@ def locate_file(self, path: str | PathLike[str]) -> PathLike[str]: @impl def tox_register_tox_env(register: ToxEnvRegister) -> None: register.add_package_env(VirtualEnvCmdBuilder) + + +__all__ = [ + "VenvCmdBuilder", + "VirtualEnvCmdBuilder", +] diff --git a/src/tox/tox_env/python/virtual_env/package/pyproject.py b/src/tox/tox_env/python/virtual_env/package/pyproject.py index ead82c096..dc1e30cc0 100644 --- a/src/tox/tox_env/python/virtual_env/package/pyproject.py +++ b/src/tox/tox_env/python/virtual_env/package/pyproject.py @@ -3,6 +3,7 @@ import logging import os import sys +from abc import ABC from collections import defaultdict from contextlib import contextmanager from itertools import chain @@ -94,8 +95,8 @@ def out_err(self) -> tuple[str, str]: return status.outcome.out_err() -class Pep517VirtualEnvPackager(PythonPackageToxEnv, VirtualEnv): - """local file system python virtual environment via the virtualenv package.""" +class Pep517VenvPackager(PythonPackageToxEnv, ABC): + """local file system python virtual environment package builder.""" def __init__(self, create_args: ToxEnvCreateArgs) -> None: super().__init__(create_args) @@ -360,8 +361,16 @@ def requires(self) -> tuple[Requirement, ...]: return self._frontend.requires +class Pep517VirtualEnvPackager(Pep517VenvPackager, VirtualEnv): + """local file system python virtual environment via the virtualenv package.""" + + @staticmethod + def id() -> str: + return "virtualenv-pep-517" + + class Pep517VirtualEnvFrontend(Frontend): - def __init__(self, root: Path, env: Pep517VirtualEnvPackager) -> None: + def __init__(self, root: Path, env: Pep517VenvPackager) -> None: super().__init__(*Frontend.create_args_from_folder(root)) self._tox_env = env self._backend_executor_: LocalSubProcessPep517Executor | None = None @@ -454,3 +463,9 @@ def _wheel_directory(self) -> Iterator[Path]: @impl def tox_register_tox_env(register: ToxEnvRegister) -> None: register.add_package_env(Pep517VirtualEnvPackager) + + +__all__ = [ + "Pep517VenvPackager", + "Pep517VirtualEnvPackager", +]