Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract packaging virtualenv code to its own class #3221

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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",
]