From 3fc6842fb8c6b5e928c5b65a3ccee9c2b3a68af6 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 24 Feb 2022 12:43:44 -0600 Subject: [PATCH 1/3] Disable running `session.install` outside a venv --- nox/sessions.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nox/sessions.py b/nox/sessions.py index 4bea8e8d..9291c287 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -532,6 +532,12 @@ def install(self, *args: str, **kwargs: Any) -> None: session.install('-e', '.') Additional keyword args are the same as for :meth:`run`. + + .. warning:: + + Running ``session.install`` without a virtual environment + is no longer supported. If you still want to do that, please + use ``session.run("pip", "install", ...)`` instead. .. _pip: https://pip.readthedocs.org """ @@ -544,13 +550,11 @@ def install(self, *args: str, **kwargs: Any) -> None: "A session without a virtualenv can not install dependencies." ) if isinstance(venv, PassthroughEnv): - warnings.warn( + raise ValueError ( f"Session {self.name} does not have a virtual environment, " - "so use of session.install() is deprecated since it would modify " + "so use of session.install() is no longer allowed since it would modify " "the global Python environment. If you're really sure that is " - 'what you want to do, use session.run("pip", "install", ...) instead.', - category=FutureWarning, - stacklevel=2, + 'what you want to do, use session.run("pip", "install", ...) instead.' ) if not args: raise ValueError("At least one argument required to install().") From 635f20293546d6858a73178a2f3356d7aeb82892 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 24 Feb 2022 13:05:28 -0600 Subject: [PATCH 2/3] Fix linting --- nox/sessions.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/nox/sessions.py b/nox/sessions.py index 9291c287..7391851e 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -22,7 +22,6 @@ import re import sys import unicodedata -import warnings from types import TracebackType from typing import Any, Callable, Iterable, Mapping, Sequence @@ -532,7 +531,7 @@ def install(self, *args: str, **kwargs: Any) -> None: session.install('-e', '.') Additional keyword args are the same as for :meth:`run`. - + .. warning:: Running ``session.install`` without a virtual environment @@ -550,11 +549,11 @@ def install(self, *args: str, **kwargs: Any) -> None: "A session without a virtualenv can not install dependencies." ) if isinstance(venv, PassthroughEnv): - 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 global Python environment. If you're really sure that is " - 'what you want to do, use session.run("pip", "install", ...) instead.' + 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" + " global Python environment. If you're really sure that is what you" + ' want to do, use session.run("pip", "install", ...) instead.' ) if not args: raise ValueError("At least one argument required to install().") From 09f6c22ed8d2632374b461f2d4d1721a2fd1ec95 Mon Sep 17 00:00:00 2001 From: Diego Ramirez Date: Thu, 24 Feb 2022 13:16:26 -0600 Subject: [PATCH 3/3] Replace the old test by a new one (almost) --- tests/test_sessions.py | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 688b8f18..f7535958 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -646,7 +646,7 @@ class SessionNoSlots(nox.sessions.Session): external="error", ) - def test_install_no_venv_deprecated(self): + def test_install_no_venv_failure(self): runner = nox.sessions.SessionRunner( name="test", signatures=["test"], @@ -662,25 +662,14 @@ class SessionNoSlots(nox.sessions.Session): session = SessionNoSlots(runner=runner) - with mock.patch.object(session, "_run", autospec=True) as run: - with pytest.warns( - FutureWarning, - match=( - r"use of session\.install\(\) is deprecated since it would modify" - r" the global Python environment" - ), - ): - session.install("requests", "urllib3") - run.assert_called_once_with( - "python", - "-m", - "pip", - "install", - "requests", - "urllib3", - silent=True, - external="error", - ) + with pytest.raises( + ValueError, + match=( + r"use of session\.install\(\) is no longer allowed since" + r" it would modify the global Python environment" + ), + ): + session.install("requests", "urllib3") def test_notify(self): session, runner = self.make_session_and_runner()