From 6eb826c8b8e2c5e9743683d4c9389462778be4e4 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 13 Mar 2021 14:08:43 +0100 Subject: [PATCH 1/4] Do not set TMPDIR when exporting to requirements.txt --- src/nox_poetry/sessions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nox_poetry/sessions.py b/src/nox_poetry/sessions.py index d137bf2a..f0d25e18 100644 --- a/src/nox_poetry/sessions.py +++ b/src/nox_poetry/sessions.py @@ -160,7 +160,9 @@ def export_requirements(self) -> Path: Returns: The path to the requirements file. """ - tmpdir = Path(self.session.create_tmp()) + tmpdir = Path(self.session.virtualenv.location) / "tmp" + tmpdir.mkdir(exist_ok=True) + path = tmpdir / "requirements.txt" hashfile = tmpdir / f"{path.name}.hash" From 7b0b9760aedcf233c70ce2c8b10bbf182f776c07 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 13 Mar 2021 15:31:17 +0100 Subject: [PATCH 2/4] Adapt unit tests --- tests/unit/conftest.py | 15 +++++++++------ tests/unit/test_sessions.py | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 187fcd95..6989bd06 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -8,12 +8,20 @@ from nox.sessions import Session +class FakeVirtualenv: + """Fake virtual environment.""" + + def __init__(self, path: Path) -> None: + """Initialize.""" + self.location = str(path) + + class FakeSession: """Fake session.""" def __init__(self, path: Path) -> None: """Initialize.""" - self.path = path + self.virtualenv = FakeVirtualenv(path) def run(self, *args: str, **kargs: Any) -> str: """Run.""" @@ -23,11 +31,6 @@ def run(self, *args: str, **kargs: Any) -> str: def install(self, *args: str, **kargs: Any) -> None: """Install.""" - pass - - def create_tmp(self, *args: str, **kargs: Any) -> str: - """Create temporary directory.""" - return str(self.path) @pytest.fixture diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index 135a3fe9..52179163 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -114,7 +114,7 @@ def proxy(session: nox.Session) -> nox_poetry.Session: def test_session_getattr(proxy: nox_poetry.Session) -> None: """It delegates to the real session.""" - assert proxy.create_tmp() + assert proxy.virtualenv.location def test_session_install(proxy: nox_poetry.Session) -> None: From 4854b748dbf3377834cafa063d6f8f08458ff466 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 13 Mar 2021 14:10:50 +0100 Subject: [PATCH 3/4] Remove obsolete workaround from #178 --- noxfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index c8c96bfa..c623d312 100644 --- a/noxfile.py +++ b/noxfile.py @@ -131,7 +131,6 @@ def tests(session: Session) -> None: session.install("dataclasses") try: - session.env.pop("TMPDIR", None) session.run("coverage", "run", "--parallel", "-m", "pytest", *session.posargs) finally: if session.interactive: From 212f81b505c3b43bb7007c3eae5f202c5fd20b49 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Sat, 13 Mar 2021 16:08:55 +0100 Subject: [PATCH 4/4] Workaround an issue in Nox's types --- tests/unit/test_sessions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_sessions.py b/tests/unit/test_sessions.py index 52179163..0f25d201 100644 --- a/tests/unit/test_sessions.py +++ b/tests/unit/test_sessions.py @@ -114,7 +114,8 @@ def proxy(session: nox.Session) -> nox_poetry.Session: def test_session_getattr(proxy: nox_poetry.Session) -> None: """It delegates to the real session.""" - assert proxy.virtualenv.location + # Fixed in https://github.com/theacodes/nox/pull/377 + assert proxy.virtualenv.location # type: ignore[attr-defined] def test_session_install(proxy: nox_poetry.Session) -> None: