Skip to content

Commit

Permalink
fix: don't error if not installing to passthrough (#809)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Apr 7, 2024
1 parent 956f10c commit 11dac8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def conda_install(
prefix_args: tuple[str, ...] = ()
if isinstance(venv, CondaEnv):
prefix_args = ("--prefix", venv.location)
elif not isinstance(venv, PassthroughEnv): # pragma: no cover
elif not isinstance(venv, PassthroughEnv):
raise ValueError(
"A session without a conda environment can not install dependencies"
" from conda."
Expand All @@ -574,7 +574,9 @@ def conda_install(
if not args:
raise ValueError("At least one argument required to install().")

if self._runner.global_config.no_install and venv._reused:
if self._runner.global_config.no_install and (
isinstance(venv, PassthroughEnv) or venv._reused
):
return

# Escape args that should be (conda-specific; pip install does not need this)
Expand Down Expand Up @@ -648,6 +650,8 @@ def install(self, *args: str, **kwargs: Any) -> None:
"A session without a virtualenv can not install dependencies."
)
if isinstance(venv, PassthroughEnv):
if self._runner.global_config.no_install:
return
raise ValueError(
f"Session {self.name} does not have a virtual environment, so use of"
" session.install() is no longer allowed since it would modify the"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,20 @@ def test_run_install_bad_args(self):
exc_args = exc_info.value.args
assert exc_args == ("At least one argument required to run_install().",)

def test_run_no_install_passthrough(self):
session, runner = self.make_session_and_runner()
runner.venv = nox.virtualenv.PassthroughEnv()
runner.global_config.no_install = True

session.install("numpy")
session.conda_install("numpy")

def test_run_no_conda_install(self):
session, runner = self.make_session_and_runner()

with pytest.raises(ValueError, match="A session without a conda"):
session.conda_install("numpy")

def test_run_install_success(self):
session, _ = self.make_session_and_runner()

Expand Down

0 comments on commit 11dac8c

Please sign in to comment.