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

Support specifying build time executable for wheels #72

Merged
merged 1 commit into from
Sep 17, 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
11 changes: 9 additions & 2 deletions poetry/core/masonry/builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from typing import Optional
from typing import Union

from poetry.core.utils._compat import Path

from .builders.sdist import SdistBuilder
from .builders.wheel import WheelBuilder

Expand All @@ -11,7 +16,9 @@ class Builder:
def __init__(self, poetry):
self._poetry = poetry

def build(self, fmt="all"):
def build(
self, fmt, executable=None
): # type: (str, Optional[Union[str, Path]]) -> None
if fmt in self._FORMATS:
builders = [self._FORMATS[fmt]]
elif fmt == "all":
Expand All @@ -20,4 +27,4 @@ def build(self, fmt="all"):
raise ValueError("Invalid format: {}".format(fmt))

for builder in builders:
builder(self._poetry).build()
builder(self._poetry, executable=executable).build()
10 changes: 8 additions & 2 deletions poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import re
import shutil
import sys
import tempfile

from collections import defaultdict
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down
25 changes: 16 additions & 9 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import shutil
import stat
import subprocess
import sys
import tempfile
import zipfile

Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down