Skip to content

Commit

Permalink
Extract packaging virtualenv code to its own class (#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed Feb 17, 2024
1 parent 47bcea6 commit fa923ec
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/changelog/3200.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extract virtual environment packaging code to its own base class not tied to ``virtualenv`` - by :user:`gaborbernat`.
19 changes: 14 additions & 5 deletions src/tox/tox_env/python/virtual_env/package/cmd_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import glob
import tarfile
from abc import ABC
from functools import partial
from io import TextIOWrapper
from pathlib import Path
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
]
21 changes: 18 additions & 3 deletions src/tox/tox_env/python/virtual_env/package/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
]

0 comments on commit fa923ec

Please sign in to comment.