From 54aa2d57958442ec7f548aff378f98af444aba95 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Mon, 30 Nov 2020 00:30:04 +0100 Subject: [PATCH 1/5] Add Poetry.version method --- src/nox_poetry/poetry.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/nox_poetry/poetry.py b/src/nox_poetry/poetry.py index abb9f50e..73eb1c5a 100644 --- a/src/nox_poetry/poetry.py +++ b/src/nox_poetry/poetry.py @@ -69,3 +69,19 @@ def build(self, *, format: DistributionFormat) -> str: ) assert isinstance(output, str) # noqa: S101 return output.split()[-1] + + def version(self) -> str: + """Return the package name and version. + + Returns: + The package name and version. + """ + output = self.session.run( + "poetry", + "version", + external=True, + silent=True, + stderr=None, + ) + assert isinstance(output, str) # noqa: S101 + return output.strip() From dbc3716fc2c6c7202041908ba36c7a1e84b94553 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Mon, 30 Nov 2020 00:43:51 +0100 Subject: [PATCH 2/5] Include egg fragment in sdist URL --- src/nox_poetry/core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nox_poetry/core.py b/src/nox_poetry/core.py index 9bd65dc5..a9eea35d 100644 --- a/src/nox_poetry/core.py +++ b/src/nox_poetry/core.py @@ -75,8 +75,13 @@ def build_package(session: Session, *, distribution_format: DistributionFormat) poetry = Poetry(session) wheel = Path("dist") / poetry.build(format=distribution_format) digest = hashlib.sha256(wheel.read_bytes()).hexdigest() + url = f"file://{wheel.resolve().as_posix()}#sha256={digest}" - return f"file://{wheel.resolve().as_posix()}#sha256={digest}" + if distribution_format is DistributionFormat.SDIST: + name = poetry.version().split()[0] + url += f"&egg={name}" + + return url def install( From bad7fb5ca3f19ba29d9a4683285690b79dd32cdb Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Wed, 2 Dec 2020 03:04:20 +0100 Subject: [PATCH 3/5] Remove xfail marker --- tests/functional/test_functional.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/functional/test_functional.py b/tests/functional/test_functional.py index b4078481..58d120e9 100644 --- a/tests/functional/test_functional.py +++ b/tests/functional/test_functional.py @@ -1,6 +1,5 @@ """Functional tests.""" import nox.sessions -import pytest from tests.functional.conftest import ListPackages from tests.functional.conftest import Project from tests.functional.conftest import RunNoxWithNoxfile @@ -48,7 +47,6 @@ def test(session: nox.sessions.Session) -> None: assert set(expected) == set(packages) -@pytest.mark.xfail(reason="https://github.com/cjolowicz/nox-poetry/issues/127") def test_install_local_sdist( project: Project, run_nox_with_noxfile: RunNoxWithNoxfile, From 871303715da6e5265465fb10fb881d70c5ca3732 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Wed, 2 Dec 2020 03:04:29 +0100 Subject: [PATCH 4/5] Work around a Poetry bug Poetry does not include the src directory in the sdist archive, if a parent directory of the project also contains a Poetry project. This is the case because pytest-datadir copies the example project to a temporary directory, and nox_poetry sets TMPDIR to a location under the session directory, via session.create_tmp(). --- noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/noxfile.py b/noxfile.py index 628f1ed5..6c9dcabe 100644 --- a/noxfile.py +++ b/noxfile.py @@ -129,6 +129,7 @@ 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 4746059ab3b97cc33c6105c98fca156631648ee3 Mon Sep 17 00:00:00 2001 From: Claudio Jolowicz Date: Wed, 2 Dec 2020 03:14:40 +0100 Subject: [PATCH 5/5] Add unit test for sdist installation --- tests/unit/test_nox_poetry.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_nox_poetry.py b/tests/unit/test_nox_poetry.py index 701ad528..993281b6 100644 --- a/tests/unit/test_nox_poetry.py +++ b/tests/unit/test_nox_poetry.py @@ -1,12 +1,15 @@ """Unit tests.""" +import pytest from nox.sessions import Session import nox_poetry +from nox_poetry.poetry import DistributionFormat -def test_install(session: Session) -> None: +@pytest.mark.parametrize("distribution_format", [nox_poetry.WHEEL, nox_poetry.SDIST]) +def test_install(session: Session, distribution_format: DistributionFormat) -> None: """It installs the dependencies.""" - nox_poetry.install(session, nox_poetry.WHEEL, "pip") + nox_poetry.install(session, distribution_format, "pip") def test_export_requirements(session: Session) -> None: