From f5d92c4f50b07b829f6b634af422273482866b11 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Tue, 31 Mar 2020 18:01:42 +0200 Subject: [PATCH] Fix PEP-517 issues for projects using build scripts Resolves: python-poetry/poetry#1516 --- poetry/core/masonry/builders/wheel.py | 66 +++++++++++++-------------- tests/masonry/test_api.py | 25 ++++++++++ 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/poetry/core/masonry/builders/wheel.py b/poetry/core/masonry/builders/wheel.py index cb98dcdae..e7d11bacb 100644 --- a/poetry/core/masonry/builders/wheel.py +++ b/poetry/core/masonry/builders/wheel.py @@ -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 = """\ @@ -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( diff --git a/tests/masonry/test_api.py b/tests/masonry/test_api.py index a9c6796db..c95203ad3 100644 --- a/tests/masonry/test_api.py +++ b/tests/masonry/test_api.py @@ -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 @@ -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)