Skip to content

Commit c2b8b5d

Browse files
committed
🐛 Fix xmake-wheel
1 parent f3b2736 commit c2b8b5d

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "xmake_python"
66
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
77
[project]
88
name = "xmake-python"
9-
version = "0.0.4"
9+
version = "0.0.5"
1010
description = "xmake Python build system (PEP 517)"
1111
readme = "README.md"
1212
# from typing import Self

src/xmake_python/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.0.4"
1+
__version__ = "0.0.5"
22

33
if __name__ == "__main__":
44
print(__version__)

src/xmake_python/builder/get_requires.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
best_program,
1212
get_xmake_programs,
1313
)
14-
from ..sdist import SdistBuilder
14+
from ..wheel import WheelBuilder
1515

1616
if TYPE_CHECKING:
1717
from collections.abc import Generator, Mapping
@@ -27,13 +27,13 @@ def __dir__() -> list[str]:
2727

2828
def _load_scikit_build_settings(
2929
config_settings: Mapping[str, list[str] | str] | None = None,
30-
) -> SdistBuilder:
31-
return SdistBuilder.from_ini_path(Path("pyproject.toml"))
30+
) -> WheelBuilder:
31+
return WheelBuilder.from_ini_path(Path("pyproject.toml"), None)
3232

3333

3434
@dataclasses.dataclass(frozen=True)
3535
class GetRequires:
36-
settings: SdistBuilder = dataclasses.field(
36+
settings: WheelBuilder = dataclasses.field(
3737
default_factory=_load_scikit_build_settings
3838
)
3939

@@ -44,9 +44,7 @@ def from_config_settings(
4444
return cls(_load_scikit_build_settings(config_settings))
4545

4646
def xmake(self) -> Generator[str, None, None]:
47-
directory = Path("pyproject.toml").parent
48-
xmake_path = directory / "xmake.lua"
49-
if not xmake_path.exists():
47+
if self.settings.xmake is None:
5048
return
5149
if os.environ.get("XMAKE_EXECUTABLE", ""):
5250
return

src/xmake_python/wheel.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ def __init__(
7878
self.source_time_stamp = zip_timestamp_from_env()
7979

8080
# Open the zip file ready to write
81-
self.wheel_zip = zipfile.ZipFile(target_fp, 'w',
82-
compression=zipfile.ZIP_DEFLATED)
81+
self.wheel_zip = None
82+
# skip creating wheel for get_requires_for_build_wheel()
83+
if target_fp is not None:
84+
self.wheel_zip = zipfile.ZipFile(target_fp, 'w',
85+
compression=zipfile.ZIP_DEFLATED)
8386
self.xmake = xmake
8487
if xmake:
8588
self.output = xmake.output
@@ -144,13 +147,14 @@ def _add_file(self, full_path, rel_path):
144147
zinfo.compress_type = zipfile.ZIP_DEFLATED
145148

146149
hashsum = hashlib.sha256()
147-
with open(full_path, 'rb') as src, self.wheel_zip.open(zinfo, 'w') as dst:
148-
while True:
149-
buf = src.read(1024 * 8)
150-
if not buf:
151-
break
152-
hashsum.update(buf)
153-
dst.write(buf)
150+
if self.wheel_zip:
151+
with open(full_path, 'rb') as src, self.wheel_zip.open(zinfo, 'w') as dst:
152+
while True:
153+
buf = src.read(1024 * 8)
154+
if not buf:
155+
break
156+
hashsum.update(buf)
157+
dst.write(buf)
154158

155159
size = os.stat(full_path).st_size
156160
hash_digest = urlsafe_b64encode(hashsum.digest()).decode('ascii').rstrip('=')
@@ -172,7 +176,8 @@ def _write_to_zip(self, rel_path, mode=0o644):
172176
b = sio.getvalue().encode('utf-8')
173177
hashsum = hashlib.sha256(b)
174178
hash_digest = urlsafe_b64encode(hashsum.digest()).decode('ascii').rstrip('=')
175-
self.wheel_zip.writestr(zi, b, compress_type=zipfile.ZIP_DEFLATED)
179+
if self.wheel_zip:
180+
self.wheel_zip.writestr(zi, b, compress_type=zipfile.ZIP_DEFLATED)
176181
self.records.append((rel_path, hash_digest, len(b)))
177182

178183
def copy_module(self):
@@ -256,7 +261,8 @@ def build(self, editable=False):
256261
self.write_metadata()
257262
self.write_record()
258263
finally:
259-
self.wheel_zip.close()
264+
if self.wheel_zip:
265+
self.wheel_zip.close()
260266

261267
def make_wheel_in(ini_path, wheel_directory, editable=False):
262268
# We don't know the final filename until metadata is loaded, so write to

0 commit comments

Comments
 (0)