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

fix: don't error if not installing to passthrough #809

Merged
merged 1 commit into from
Apr 7, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading