Skip to content

Commit

Permalink
Fix broken sdist support due to missing egg fragment (#178)
Browse files Browse the repository at this point in the history
* Add Poetry.version method

* Include egg fragment in sdist URL

* Remove xfail marker

* 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().

* Add unit test for sdist installation
  • Loading branch information
cjolowicz authored Dec 2, 2020
1 parent 2b83a8e commit 2135094
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion src/nox_poetry/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions src/nox_poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 0 additions & 2 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/test_nox_poetry.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 2135094

Please sign in to comment.