Skip to content

Commit cd35053

Browse files
committed
feat: add venv_backend property
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 545a621 commit cd35053

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

nox/sessions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ def virtualenv(self) -> ProcessEnv:
193193
raise ValueError("A virtualenv has not been created for this session")
194194
return venv
195195

196+
@property
197+
def venv_backend(self) -> str:
198+
"""The venv_backend selected."""
199+
venv = self._runner.venv
200+
if venv is None:
201+
return "none"
202+
return venv.venv_backend
203+
196204
@property
197205
def python(self) -> str | Sequence[str] | bool | None:
198206
"""The python version passed into ``@nox.session``."""

nox/virtualenv.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def create(self) -> bool:
9393
Returns True if the environment is new, and False if it was reused.
9494
"""
9595

96+
@property
97+
@abc.abstractmethod
98+
def venv_backend(self) -> str:
99+
"""
100+
Returns the string used to select this environment.
101+
"""
102+
96103

97104
def locate_via_py(version: str) -> str | None:
98105
"""Find the Python executable using the Windows Launcher.
@@ -180,6 +187,10 @@ def create(self) -> bool:
180187
False since it's always reused."""
181188
return False
182189

190+
@property
191+
def venv_backend(self) -> str:
192+
return "none"
193+
183194

184195
class CondaEnv(ProcessEnv):
185196
"""Conda environment management class.
@@ -303,6 +314,10 @@ def is_offline() -> bool:
303314
except BaseException: # pragma: no cover
304315
return True
305316

317+
@property
318+
def venv_backend(self) -> str:
319+
return self.conda_cmd
320+
306321

307322
class VirtualEnv(ProcessEnv):
308323
"""Virtualenv management class.
@@ -341,7 +356,7 @@ def __init__(
341356
self.interpreter = interpreter
342357
self._resolved: None | str | InterpreterNotFound = None
343358
self.reuse_existing = reuse_existing
344-
self.venv_backend = venv_backend
359+
self._venv_backend = venv_backend
345360
self.venv_params = venv_params or []
346361
if venv_backend not in {"virtualenv", "venv", "uv"}:
347362
msg = f"venv_backend {venv_backend} not recognized"
@@ -544,6 +559,10 @@ def create(self) -> bool:
544559

545560
return True
546561

562+
@property
563+
def venv_backend(self) -> str:
564+
return self._venv_backend
565+
547566

548567
ALL_VENVS: dict[str, Callable[..., ProcessEnv]] = {
549568
"conda": functools.partial(CondaEnv, conda_cmd="conda"),

tests/test_sessions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ class SessionNoSlots(nox.sessions.Session):
641641

642642
session = SessionNoSlots(runner=runner)
643643

644+
assert session.venv_backend == "venv"
645+
644646
with mock.patch.object(session, "_run", autospec=True) as run:
645647
session.install("requests", "urllib3")
646648
run.assert_called_once_with(

0 commit comments

Comments
 (0)