Skip to content

Commit e012cf8

Browse files
committed
Remove support for installing and creating venv entirely
1 parent cedd574 commit e012cf8

File tree

3 files changed

+7
-263
lines changed

3 files changed

+7
-263
lines changed

tests/plugins/test_py_envs.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,22 @@
66
import venv
77
from pathlib import Path
88

9-
import pytest
10-
119
from variantlib.plugins.py_envs import python_env
1210

1311

1412
def test_system_env() -> None:
15-
with python_env(isolated=False) as env:
13+
with python_env() as env:
1614
assert env.venv_path is None
1715
assert env.python_executable == Path(sys.executable)
1816

1917

20-
@pytest.mark.parametrize("custom", [False, True])
21-
def test_isolated_env(
22-
custom: bool, tmp_path: Path, test_plugin_package_req: str
23-
) -> None:
24-
if custom:
25-
venv.create(tmp_path, with_pip=True)
26-
with python_env(isolated=True, venv_path=tmp_path if custom else None) as env:
27-
assert env.venv_path is not None
28-
if custom:
29-
assert env.venv_path == tmp_path
18+
def test_isolated_env(tmp_path: Path, test_plugin_package_req: str) -> None:
19+
venv.create(tmp_path, with_pip=True)
20+
with python_env(venv_path=tmp_path) as env:
21+
assert env.venv_path == tmp_path
3022
script_dir = Path(
3123
sysconfig.get_path("scripts", vars={"base": str(env.venv_path)})
3224
)
3325
assert env.python_executable == script_dir / (
3426
"python.exe" if os.name == "nt" else "python"
3527
)
36-
37-
env.install([test_plugin_package_req])
38-
39-
purelib = Path(sysconfig.get_path("purelib", vars={"base": str(env.venv_path)}))
40-
assert (purelib / "test_plugin_package.py").exists()

variantlib/plugins/py_backends.py

Lines changed: 0 additions & 171 deletions
This file was deleted.

variantlib/plugins/py_envs.py

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,19 @@
11
from __future__ import annotations
22

3-
import functools
43
import logging
54
import os
65
import pathlib
76
import sys
87
import sysconfig
9-
import tempfile
10-
import typing
118
from contextlib import contextmanager
129
from typing import TYPE_CHECKING
1310

14-
from variantlib.plugins.py_backends import AutoInstallBackend
15-
from variantlib.plugins.py_backends import PipBackend
16-
from variantlib.plugins.py_backends import UvBackend
17-
1811
if TYPE_CHECKING:
19-
from collections.abc import Collection
2012
from collections.abc import Generator
2113

2214

2315
logger = logging.getLogger(__name__)
2416

25-
Installer = typing.Literal["pip", "uv"]
26-
27-
INSTALLERS = typing.get_args(Installer)
28-
2917

3018
def _find_executable(path: pathlib.Path) -> pathlib.Path:
3119
"""
@@ -78,52 +66,10 @@ def _find_executable(path: pathlib.Path) -> pathlib.Path:
7866
return executable
7967

8068

81-
@functools.cache
82-
def _fs_supports_symlink() -> bool:
83-
"""Return True if symlinks are supported"""
84-
# Using definition used by venv.main()
85-
if os.name != "nt":
86-
return True
87-
88-
# Windows may support symlinks (setting in Windows 10)
89-
with tempfile.NamedTemporaryFile(prefix="variant-symlink-") as tmp_file:
90-
dest = f"{tmp_file}-b"
91-
try:
92-
os.symlink(tmp_file.name, dest)
93-
os.unlink(dest) # noqa: PTH108
94-
except (OSError, NotImplementedError, AttributeError):
95-
return False
96-
return True
97-
98-
9969
class PythonEnv:
100-
_env_backend: UvBackend | PipBackend = AutoInstallBackend()
101-
10270
def __init__(self, venv_path: pathlib.Path | None = None):
10371
self.venv_path = venv_path
10472

105-
def install(self, requirements: Collection[str]) -> None:
106-
"""
107-
Install packages from PEP 508 requirements in the isolated variant plugin
108-
environment.
109-
110-
:param requirements: PEP 508 requirement specification to install
111-
112-
:note: Passing non-PEP 508 strings will result in undefined behavior, you
113-
*should not* rely on it. It is merely an implementation detail, it may
114-
change any time without warning.
115-
"""
116-
if not requirements:
117-
return
118-
119-
logger.info(
120-
"Installing packages in current environment:\n%(reqs)s",
121-
{"reqs": "\n".join(f"- {r}" for r in sorted(requirements))},
122-
)
123-
self._env_backend.install_requirements(
124-
requirements, py_exec=self.python_executable
125-
)
126-
12773
@property
12874
def python_executable(self) -> pathlib.Path:
12975
if self.venv_path is not None:
@@ -134,23 +80,5 @@ def python_executable(self) -> pathlib.Path:
13480

13581

13682
@contextmanager
137-
def python_env(
138-
isolated: bool = False, venv_path: pathlib.Path | None = None
139-
) -> Generator[PythonEnv]:
140-
if venv_path is None and isolated:
141-
import venv
142-
143-
with tempfile.TemporaryDirectory(prefix="variantlib-venv") as temp_dir:
144-
logger.info(
145-
"Creating virtual environment in %(path)s ...",
146-
{"path": str(temp_dir)},
147-
)
148-
venv.EnvBuilder(
149-
symlinks=_fs_supports_symlink(),
150-
with_pip=True,
151-
system_site_packages=False,
152-
clear=True,
153-
).create(temp_dir)
154-
yield PythonEnv(pathlib.Path(temp_dir))
155-
else:
156-
yield PythonEnv(venv_path)
83+
def python_env(venv_path: pathlib.Path | None = None) -> Generator[PythonEnv]:
84+
yield PythonEnv(venv_path)

0 commit comments

Comments
 (0)