Skip to content

Commit b8acbaf

Browse files
committed
Fix PEP-517 issues for projects using build scripts
Resolves: python-poetry/poetry#1516
1 parent f900aa1 commit b8acbaf

File tree

2 files changed

+58
-33
lines changed

2 files changed

+58
-33
lines changed

poetry/core/masonry/builders/wheel.py

+33-33
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ..utils.helpers import normalize_file_permissions
2626
from ..utils.package_include import PackageInclude
2727
from .builder import Builder
28+
from .sdist import SdistBuilder
2829

2930

3031
wheel_file_template = """\
@@ -92,39 +93,38 @@ def build(self):
9293

9394
def _build(self, wheel):
9495
if self._package.build:
95-
setup = self._path / "setup.py"
96-
97-
# We need to place ourselves in the temporary
98-
# directory in order to build the package
99-
current_path = os.getcwd()
100-
try:
101-
os.chdir(str(self._path))
102-
self._run_build_command(setup)
103-
finally:
104-
os.chdir(current_path)
105-
106-
build_dir = self._path / "build"
107-
lib = list(build_dir.glob("lib.*"))
108-
if not lib:
109-
# The result of building the extensions
110-
# does not exist, this may due to conditional
111-
# builds, so we assume that it's okay
112-
return
113-
114-
lib = lib[0]
115-
116-
for pkg in lib.glob("**/*"):
117-
if pkg.is_dir() or self.is_excluded(pkg):
118-
continue
119-
120-
rel_path = str(pkg.relative_to(lib))
121-
122-
if rel_path in wheel.namelist():
123-
continue
124-
125-
logger.debug(" - Adding: {}".format(rel_path))
126-
127-
self._add_file(wheel, pkg, rel_path)
96+
with SdistBuilder(poetry=self._poetry).setup_py() as setup:
97+
# We need to place ourselves in the temporary
98+
# directory in order to build the package
99+
current_path = os.getcwd()
100+
try:
101+
os.chdir(str(self._path))
102+
self._run_build_command(setup)
103+
finally:
104+
os.chdir(current_path)
105+
106+
build_dir = self._path / "build"
107+
lib = list(build_dir.glob("lib.*"))
108+
if not lib:
109+
# The result of building the extensions
110+
# does not exist, this may due to conditional
111+
# builds, so we assume that it's okay
112+
return
113+
114+
lib = lib[0]
115+
116+
for pkg in lib.glob("**/*"):
117+
if pkg.is_dir() or self.is_excluded(pkg):
118+
continue
119+
120+
rel_path = str(pkg.relative_to(lib))
121+
122+
if rel_path in wheel.namelist():
123+
continue
124+
125+
logger.debug(" - Adding: {}".format(rel_path))
126+
127+
self._add_file(wheel, pkg, rel_path)
128128

129129
def _run_build_command(self, setup):
130130
subprocess.check_call(

tests/masonry/test_api.py

+25
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
from __future__ import unicode_literals
33

44
import os
5+
import platform
6+
import sys
57
import tarfile
68
import zipfile
79

810
from contextlib import contextmanager
911

12+
import pytest
13+
1014
from poetry.core import __version__
1115
from poetry.core.masonry import api
1216
from poetry.core.utils._compat import Path
@@ -51,6 +55,27 @@ def test_build_wheel():
5155
assert "my_package-1.2.3.dist-info/METADATA" in namelist
5256

5357

58+
@pytest.mark.skipif(
59+
sys.platform == "win32"
60+
and sys.version_info <= (3, 6)
61+
or platform.python_implementation().lower() == "pypy",
62+
reason="Disable test on Windows for Python <=3.6 and for PyPy",
63+
)
64+
def test_build_wheel_extended():
65+
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "extended")):
66+
filename = api.build_wheel(tmp_dir)
67+
68+
whl = Path(tmp_dir) / filename
69+
assert whl.exists()
70+
71+
with zipfile.ZipFile(str(os.path.join(tmp_dir, filename))) as zip:
72+
namelist = zip.namelist()
73+
74+
assert "extended-0.1.dist-info/RECORD" in namelist
75+
assert "extended-0.1.dist-info/WHEEL" in namelist
76+
assert "extended-0.1.dist-info/METADATA" in namelist
77+
78+
5479
def test_build_sdist():
5580
with temporary_directory() as tmp_dir, cwd(os.path.join(fixtures, "complete")):
5681
filename = api.build_sdist(tmp_dir)

0 commit comments

Comments
 (0)