Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with PEP 517 builds failing when projects have includes #47

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions poetry/core/masonry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_requires_for_build_wheel(config_settings=None):


def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
poetry = Factory().create_poetry(Path("."))
poetry = Factory().create_poetry(Path(".").resolve())
builder = WheelBuilder(poetry)

dist_info = Path(metadata_directory, builder.dist_info)
Expand All @@ -52,14 +52,14 @@ def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):

def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
"""Builds a wheel, places it in wheel_directory"""
poetry = Factory().create_poetry(Path("."))
poetry = Factory().create_poetry(Path(".").resolve())

return unicode(WheelBuilder.make_in(poetry, Path(wheel_directory)))


def build_sdist(sdist_directory, config_settings=None):
"""Builds an sdist, places it in sdist_directory"""
poetry = Factory().create_poetry(Path("."))
poetry = Factory().create_poetry(Path(".").resolve())

path = SdistBuilder(poetry).build(Path(sdist_directory))

Expand Down
51 changes: 33 additions & 18 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
import platform
import sys
import tarfile
import zipfile

from contextlib import contextmanager

Expand All @@ -16,6 +14,8 @@
from poetry.core.utils._compat import Path
from poetry.core.utils._compat import decode
from poetry.core.utils.helpers import temporary_directory
from tests.testutils import validate_sdist_contents
from tests.testutils import validate_wheel_contents


@contextmanager
Expand Down Expand Up @@ -46,13 +46,23 @@ def test_get_requires_for_build_sdist():
def test_build_wheel():
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "complete")):
filename = api.build_wheel(tmp_dir)
validate_wheel_contents(
name="my_package",
version="1.2.3",
path=str(os.path.join(tmp_dir, filename)),
files=["entry_points.txt"],
)

with zipfile.ZipFile(str(os.path.join(tmp_dir, filename))) as zip:
namelist = zip.namelist()

assert "my_package-1.2.3.dist-info/entry_points.txt" in namelist
assert "my_package-1.2.3.dist-info/WHEEL" in namelist
assert "my_package-1.2.3.dist-info/METADATA" in namelist
def test_build_wheel_with_include():
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "with-include")):
filename = api.build_wheel(tmp_dir)
validate_wheel_contents(
name="with_include",
version="1.2.3",
path=str(os.path.join(tmp_dir, filename)),
files=["entry_points.txt"],
)


@pytest.mark.skipif(
Expand All @@ -64,26 +74,31 @@ def test_build_wheel():
def test_build_wheel_extended():
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "extended")):
filename = api.build_wheel(tmp_dir)

whl = Path(tmp_dir) / filename
assert whl.exists()

with zipfile.ZipFile(str(os.path.join(tmp_dir, filename))) as zip:
namelist = zip.namelist()

assert "extended-0.1.dist-info/RECORD" in namelist
assert "extended-0.1.dist-info/WHEEL" in namelist
assert "extended-0.1.dist-info/METADATA" in namelist
validate_wheel_contents(name="extended", version="0.1", path=whl.as_posix())


def test_build_sdist():
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "complete")):
filename = api.build_sdist(tmp_dir)
validate_sdist_contents(
name="my-package",
version="1.2.3",
path=str(os.path.join(tmp_dir, filename)),
files=["LICENSE"],
)

with tarfile.open(str(os.path.join(tmp_dir, filename))) as tar:
namelist = tar.getnames()

assert "my-package-1.2.3/LICENSE" in namelist
def test_build_sdist_with_include():
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "with-include")):
filename = api.build_sdist(tmp_dir)
validate_sdist_contents(
name="with-include",
version="1.2.3",
path=str(os.path.join(tmp_dir, filename)),
files=["LICENSE"],
)


def test_prepare_metadata_for_build_wheel():
Expand Down
25 changes: 25 additions & 0 deletions tests/testutils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import shutil
import subprocess
import tarfile
import zipfile

from contextlib import contextmanager
from typing import Any
from typing import ContextManager
from typing import Dict
from typing import List
from typing import Optional

from poetry.core.utils._compat import Path
Expand Down Expand Up @@ -62,3 +65,25 @@ def subprocess_run(*args, **kwargs): # type: (str, Any) -> subprocess.Completed
)
assert result.returncode == 0
return result


def validate_wheel_contents(
name, version, path, files=None
): # type: (str, str, str, Optional[List[str]]) -> None
dist_info = "{}-{}.dist-info".format(name, version)
files = files or []

with zipfile.ZipFile(path) as z:
namelist = z.namelist()
# we use concatenation here for PY2 compat
for filename in ["WHEEL", "METADATA", "RECORD"] + files:
assert "{}/{}".format(dist_info, filename) in namelist


def validate_sdist_contents(
name, version, path, files
): # type: (str, str, str, List[str]) -> None
with tarfile.open(path) as tar:
namelist = tar.getnames()
for filename in files:
assert "{}-{}/{}".format(name, version, filename) in namelist