Skip to content

Commit

Permalink
Extract packaging virtualenv code to its own class
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Feb 17, 2024
1 parent 47bcea6 commit 874d958
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions 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`.
13 changes: 8 additions & 5 deletions src/tox/tox_env/python/virtual_env/package/cmd_builder.py
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
13 changes: 11 additions & 2 deletions src/tox/tox_env/python/virtual_env/package/pyproject.py
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,6 +361,14 @@ 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:
super().__init__(*Frontend.create_args_from_folder(root))
Expand Down

0 comments on commit 874d958

Please sign in to comment.