From 2aee3cf9a51a073ce603209480fd780686c9f39f Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 12 Jun 2021 21:58:01 +0200 Subject: [PATCH 1/3] Hide staleness check behind a feature flag --- nox/virtualenv.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nox/virtualenv.py b/nox/virtualenv.py index ab015268..3a427805 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -33,6 +33,7 @@ ["PIP_RESPECT_VIRTUALENV", "PIP_REQUIRE_VIRTUALENV", "__PYVENV_LAUNCHER__"] ) _SYSTEM = platform.system() +_ENABLE_STALENESS_CHECK = "NOX_ENABLE_STALENESS_CHECK" in os.environ class InterpreterNotFound(OSError): @@ -312,6 +313,8 @@ def __init__( def _clean_location(self) -> bool: """Deletes any existing virtual environment""" if os.path.exists(self.location): + if self.reuse_existing and not _ENABLE_STALENESS_CHECK: + return False if ( self.reuse_existing and self._check_reused_environment_type() From 8ae2d534581fd3da428ff74b4212e9243bf99339 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 12 Jun 2021 22:05:37 +0200 Subject: [PATCH 2/3] Set feature flag for staleness check in unit tests --- tests/test_virtualenv.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index ac0fa598..7499dd22 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -352,6 +352,15 @@ def test_create_reuse_environment(make_one): assert reused +@pytest.fixture +def _enable_staleness_check(monkeypatch): + monkeypatch.setattr("nox.virtualenv._ENABLE_STALENESS_CHECK", True) + + +enable_staleness_check = pytest.mark.usefixtures("_enable_staleness_check") + + +@enable_staleness_check def test_create_reuse_environment_with_different_interpreter(make_one, monkeypatch): venv, location = make_one(reuse_existing=True) venv.create() @@ -368,6 +377,7 @@ def test_create_reuse_environment_with_different_interpreter(make_one, monkeypat assert not location.join("marker").check() +@enable_staleness_check def test_create_reuse_stale_venv_environment(make_one): venv, location = make_one(reuse_existing=True) venv.create() @@ -387,6 +397,7 @@ def test_create_reuse_stale_venv_environment(make_one): assert not reused +@enable_staleness_check def test_create_reuse_stale_virtualenv_environment(make_one): venv, location = make_one(reuse_existing=True, venv=True) venv.create() @@ -411,6 +422,7 @@ def test_create_reuse_stale_virtualenv_environment(make_one): assert not reused +@enable_staleness_check def test_create_reuse_venv_environment(make_one): venv, location = make_one(reuse_existing=True, venv=True) venv.create() @@ -425,6 +437,7 @@ def test_create_reuse_venv_environment(make_one): assert reused +@enable_staleness_check @pytest.mark.skipif(IS_WINDOWS, reason="Avoid 'No pyvenv.cfg file' error on Windows.") def test_create_reuse_oldstyle_virtualenv_environment(make_one): venv, location = make_one(reuse_existing=True) From 3bb902d32009ba0805d404f26f20d54ba4d99cf2 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 12 Jun 2021 22:51:41 +0200 Subject: [PATCH 3/3] Set feature flag for staleness check in Python 2 test --- tests/test_virtualenv.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index 8354c8e2..c85c08bc 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -455,6 +455,7 @@ def test_create_reuse_oldstyle_virtualenv_environment(make_one): assert reused +@enable_staleness_check def test_create_reuse_python2_environment(make_one): venv, location = make_one(reuse_existing=True, interpreter="2.7")