Skip to content

Commit

Permalink
Fix PEP-517 issues for projects using build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Mar 31, 2020
1 parent 036a5d7 commit 0328610
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 33 deletions.
66 changes: 33 additions & 33 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ..utils.helpers import normalize_file_permissions
from ..utils.package_include import PackageInclude
from .builder import Builder
from .sdist import SdistBuilder


wheel_file_template = """\
Expand Down Expand Up @@ -92,39 +93,38 @@ def build(self):

def _build(self, wheel):
if self._package.build:
setup = self._path / "setup.py"

# We need to place ourselves in the temporary
# directory in order to build the package
current_path = os.getcwd()
try:
os.chdir(str(self._path))
self._run_build_command(setup)
finally:
os.chdir(current_path)

build_dir = self._path / "build"
lib = list(build_dir.glob("lib.*"))
if not lib:
# The result of building the extensions
# does not exist, this may due to conditional
# builds, so we assume that it's okay
return

lib = lib[0]

for pkg in lib.glob("**/*"):
if pkg.is_dir() or self.is_excluded(pkg):
continue

rel_path = str(pkg.relative_to(lib))

if rel_path in wheel.namelist():
continue

logger.debug(" - Adding: {}".format(rel_path))

self._add_file(wheel, pkg, rel_path)
with SdistBuilder(poetry=self._poetry).setup_py() as setup:
# We need to place ourselves in the temporary
# directory in order to build the package
current_path = os.getcwd()
try:
os.chdir(str(self._path))
self._run_build_command(setup)
finally:
os.chdir(current_path)

build_dir = self._path / "build"
lib = list(build_dir.glob("lib.*"))
if not lib:
# The result of building the extensions
# does not exist, this may due to conditional
# builds, so we assume that it's okay
return

lib = lib[0]

for pkg in lib.glob("**/*"):
if pkg.is_dir() or self.is_excluded(pkg):
continue

rel_path = str(pkg.relative_to(lib))

if rel_path in wheel.namelist():
continue

logger.debug(" - Adding: {}".format(rel_path))

self._add_file(wheel, pkg, rel_path)

def _run_build_command(self, setup):
subprocess.check_call(
Expand Down
25 changes: 25 additions & 0 deletions tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
from __future__ import unicode_literals

import os
import platform
import sys
import tarfile
import zipfile

from contextlib import contextmanager

import pytest

from poetry.core import __version__
from poetry.core.masonry import api
from poetry.core.utils._compat import Path
Expand Down Expand Up @@ -51,6 +55,27 @@ def test_build_wheel():
assert "my_package-1.2.3.dist-info/METADATA" in namelist


@pytest.mark.skipif(
sys.platform == "win32"
and sys.version_info <= (3, 6)
or platform.python_implementation().lower() == "pypy",
reason="Disable test on Windows for Python <=3.6 and for PyPy",
)
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


def test_build_sdist():
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "complete")):
filename = api.build_sdist(tmp_dir)
Expand Down

0 comments on commit 0328610

Please sign in to comment.