Skip to content

Commit

Permalink
Support specifying build time executable for wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Aug 30, 2020
1 parent a522953 commit 0148868
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
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.complete import CompleteBuilder
from .builders.sdist import SdistBuilder
from .builders.wheel import WheelBuilder
Expand All @@ -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()
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
10 changes: 8 additions & 2 deletions poetry/core/masonry/builders/complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 0148868

Please sign in to comment.