From 01488682d89e4fadbf09d06c2fb37650f735fa6f Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Mon, 10 Aug 2020 12:52:38 +0200 Subject: [PATCH] Support specifying build time executable for wheels --- poetry/core/masonry/builder.py | 11 +++++++++-- poetry/core/masonry/builders/builder.py | 10 ++++++++-- poetry/core/masonry/builders/complete.py | 10 ++++++++-- poetry/core/masonry/builders/wheel.py | 25 +++++++++++++++--------- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/poetry/core/masonry/builder.py b/poetry/core/masonry/builder.py index d4243ba98..9fa355bfb 100644 --- a/poetry/core/masonry/builder.py +++ b/poetry/core/masonry/builder.py @@ -1,3 +1,8 @@ +from typing import Optional +from typing import Union + +from poetry.core.utils._compat import Path + from .builders.complete import CompleteBuilder from .builders.sdist import SdistBuilder from .builders.wheel import WheelBuilder @@ -10,10 +15,12 @@ class Builder: def __init__(self, poetry): self._poetry = poetry - def build(self, fmt): + def build( + self, fmt, executable=None + ): # type: (str, Optional[Union[str, Path]]) -> None if fmt not in self._FORMATS: raise ValueError("Invalid format: {}".format(fmt)) - builder = self._FORMATS[fmt](self._poetry) + builder = self._FORMATS[fmt](self._poetry, executable=executable) return builder.build() diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index 7089a1ae3..8d9eb0d54 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -2,6 +2,7 @@ import logging import re import shutil +import sys import tempfile from collections import defaultdict @@ -40,13 +41,14 @@ class Builder(object): format = None def __init__( - self, poetry, ignore_packages_formats=False - ): # type: ("Poetry", bool) -> None + self, poetry, ignore_packages_formats=False, executable=None + ): # type: ("Poetry", bool, Optional[Union[Path, str]]) -> None self._poetry = poetry self._package = poetry.package self._path = poetry.file.parent self._original_path = self._path self._excluded_files = None + self._executable = Path(executable or sys.executable) # type: Path packages = [] for p in self._package.packages: @@ -87,6 +89,10 @@ def __init__( self._meta = Metadata.from_package(self._package) + @property + def executable(self): # type: () -> Path + return self._executable + def build(self): raise NotImplementedError() diff --git a/poetry/core/masonry/builders/complete.py b/poetry/core/masonry/builders/complete.py index c99d851ed..7ce9da98a 100644 --- a/poetry/core/masonry/builders/complete.py +++ b/poetry/core/masonry/builders/complete.py @@ -38,12 +38,18 @@ def build(self): with self.unpacked_tarball(sdist_file) as tmpdir: WheelBuilder.make_in( - Factory().create_poetry(tmpdir), dist_dir, original=self._poetry + Factory().create_poetry(tmpdir), + dist_dir, + original=self._poetry, + executable=self.executable, ) else: with self.unpacked_tarball(sdist_file) as tmpdir: WheelBuilder.make_in( - Factory().create_poetry(tmpdir), dist_dir, original=self._poetry + Factory().create_poetry(tmpdir), + dist_dir, + original=self._poetry, + executable=self.executable, ) @classmethod diff --git a/poetry/core/masonry/builders/wheel.py b/poetry/core/masonry/builders/wheel.py index 0f15b1cce..673669068 100644 --- a/poetry/core/masonry/builders/wheel.py +++ b/poetry/core/masonry/builders/wheel.py @@ -8,7 +8,6 @@ import shutil import stat import subprocess -import sys import tempfile import zipfile @@ -43,8 +42,8 @@ class WheelBuilder(Builder): format = "wheel" - def __init__(self, poetry, target_dir=None, original=None): - super(WheelBuilder, self).__init__(poetry) + def __init__(self, poetry, target_dir=None, original=None, executable=None): + super(WheelBuilder, self).__init__(poetry, executable=executable) self._records = [] self._original_path = self._path @@ -53,16 +52,18 @@ def __init__(self, poetry, target_dir=None, original=None): self._original_path = original.file.parent @classmethod - def make_in(cls, poetry, directory=None, original=None): - wb = WheelBuilder(poetry, target_dir=directory, original=original) + def make_in(cls, poetry, directory=None, original=None, executable=None): + wb = WheelBuilder( + poetry, target_dir=directory, original=original, executable=executable + ) wb.build() return wb.wheel_filename @classmethod - def make(cls, poetry): + def make(cls, poetry, executable=None): """Build a wheel in the dist/ directory, and optionally upload it.""" - cls.make_in(poetry) + cls.make_in(poetry, executable=executable) def build(self): logger.info("Building wheel") @@ -146,12 +147,18 @@ def _build(self, wheel): def _run_build_command(self, setup): subprocess.check_call( - [sys.executable, str(setup), "build", "-b", str(self._path / "build")] + [ + self.executable.as_posix(), + str(setup), + "build", + "-b", + str(self._path / "build"), + ] ) def _run_build_script(self, build_script): logger.debug("Executing build script: {}".format(build_script)) - subprocess.check_call([sys.executable, build_script]) + subprocess.check_call([self.executable.as_posix(), build_script]) def _copy_module(self, wheel): # type: (zipfile.ZipFile) -> None to_add = self.find_files_to_add()