Skip to content

Commit 0148868

Browse files
committed
Support specifying build time executable for wheels
1 parent a522953 commit 0148868

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

poetry/core/masonry/builder.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from typing import Optional
2+
from typing import Union
3+
4+
from poetry.core.utils._compat import Path
5+
16
from .builders.complete import CompleteBuilder
27
from .builders.sdist import SdistBuilder
38
from .builders.wheel import WheelBuilder
@@ -10,10 +15,12 @@ class Builder:
1015
def __init__(self, poetry):
1116
self._poetry = poetry
1217

13-
def build(self, fmt):
18+
def build(
19+
self, fmt, executable=None
20+
): # type: (str, Optional[Union[str, Path]]) -> None
1421
if fmt not in self._FORMATS:
1522
raise ValueError("Invalid format: {}".format(fmt))
1623

17-
builder = self._FORMATS[fmt](self._poetry)
24+
builder = self._FORMATS[fmt](self._poetry, executable=executable)
1825

1926
return builder.build()

poetry/core/masonry/builders/builder.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import re
44
import shutil
5+
import sys
56
import tempfile
67

78
from collections import defaultdict
@@ -40,13 +41,14 @@ class Builder(object):
4041
format = None
4142

4243
def __init__(
43-
self, poetry, ignore_packages_formats=False
44-
): # type: ("Poetry", bool) -> None
44+
self, poetry, ignore_packages_formats=False, executable=None
45+
): # type: ("Poetry", bool, Optional[Union[Path, str]]) -> None
4546
self._poetry = poetry
4647
self._package = poetry.package
4748
self._path = poetry.file.parent
4849
self._original_path = self._path
4950
self._excluded_files = None
51+
self._executable = Path(executable or sys.executable) # type: Path
5052

5153
packages = []
5254
for p in self._package.packages:
@@ -87,6 +89,10 @@ def __init__(
8789

8890
self._meta = Metadata.from_package(self._package)
8991

92+
@property
93+
def executable(self): # type: () -> Path
94+
return self._executable
95+
9096
def build(self):
9197
raise NotImplementedError()
9298

poetry/core/masonry/builders/complete.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ def build(self):
3838

3939
with self.unpacked_tarball(sdist_file) as tmpdir:
4040
WheelBuilder.make_in(
41-
Factory().create_poetry(tmpdir), dist_dir, original=self._poetry
41+
Factory().create_poetry(tmpdir),
42+
dist_dir,
43+
original=self._poetry,
44+
executable=self.executable,
4245
)
4346
else:
4447
with self.unpacked_tarball(sdist_file) as tmpdir:
4548
WheelBuilder.make_in(
46-
Factory().create_poetry(tmpdir), dist_dir, original=self._poetry
49+
Factory().create_poetry(tmpdir),
50+
dist_dir,
51+
original=self._poetry,
52+
executable=self.executable,
4753
)
4854

4955
@classmethod

poetry/core/masonry/builders/wheel.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import shutil
99
import stat
1010
import subprocess
11-
import sys
1211
import tempfile
1312
import zipfile
1413

@@ -43,8 +42,8 @@
4342
class WheelBuilder(Builder):
4443
format = "wheel"
4544

46-
def __init__(self, poetry, target_dir=None, original=None):
47-
super(WheelBuilder, self).__init__(poetry)
45+
def __init__(self, poetry, target_dir=None, original=None, executable=None):
46+
super(WheelBuilder, self).__init__(poetry, executable=executable)
4847

4948
self._records = []
5049
self._original_path = self._path
@@ -53,16 +52,18 @@ def __init__(self, poetry, target_dir=None, original=None):
5352
self._original_path = original.file.parent
5453

5554
@classmethod
56-
def make_in(cls, poetry, directory=None, original=None):
57-
wb = WheelBuilder(poetry, target_dir=directory, original=original)
55+
def make_in(cls, poetry, directory=None, original=None, executable=None):
56+
wb = WheelBuilder(
57+
poetry, target_dir=directory, original=original, executable=executable
58+
)
5859
wb.build()
5960

6061
return wb.wheel_filename
6162

6263
@classmethod
63-
def make(cls, poetry):
64+
def make(cls, poetry, executable=None):
6465
"""Build a wheel in the dist/ directory, and optionally upload it."""
65-
cls.make_in(poetry)
66+
cls.make_in(poetry, executable=executable)
6667

6768
def build(self):
6869
logger.info("Building wheel")
@@ -146,12 +147,18 @@ def _build(self, wheel):
146147

147148
def _run_build_command(self, setup):
148149
subprocess.check_call(
149-
[sys.executable, str(setup), "build", "-b", str(self._path / "build")]
150+
[
151+
self.executable.as_posix(),
152+
str(setup),
153+
"build",
154+
"-b",
155+
str(self._path / "build"),
156+
]
150157
)
151158

152159
def _run_build_script(self, build_script):
153160
logger.debug("Executing build script: {}".format(build_script))
154-
subprocess.check_call([sys.executable, build_script])
161+
subprocess.check_call([self.executable.as_posix(), build_script])
155162

156163
def _copy_module(self, wheel): # type: (zipfile.ZipFile) -> None
157164
to_add = self.find_files_to_add()

0 commit comments

Comments
 (0)