Skip to content

Commit 0621b95

Browse files
committed
Testing windows
- self.arch to use lowercase as we expect cibuildwheel to pass amd64 while platform.machine() returns AMD64 on windows - Added Windows and amd64 as supported (list check) - Added archive suffix and archive format to support ZIP archive - Custom rename of arch in filename as openZIM uses x86_64 - Copying dll from bin/ folder (tree is different) and .lib file (not sure if needed) - Cleaning dll/lib as well - Setting to the exact nightly date we have it for (not targetting lastest nightly as it requires addtional ZIP handling TBD) - forcing cibuildwheel to only do windows py312 on amd64 for tests speed - forcing those wheels on windows branch
1 parent 0f77346 commit 0621b95

4 files changed

Lines changed: 41 additions & 17 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: test
22
on: [push]
33

44
env:
5-
LIBZIM_DL_VERSION: "9.1.0"
5+
LIBZIM_DL_VERSION: "2024-08-27"
66
MACOSX_DEPLOYMENT_TARGET: "12.0"
77

88
jobs:

.github/workflows/wheels.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ on:
55
push:
66
branches:
77
- main
8+
- windows
89

910
env:
10-
LIBZIM_DL_VERSION: "9.1.0"
11+
LIBZIM_DL_VERSION: "2024-08-27"
1112
MACOSX_DEPLOYMENT_TARGET: "12.0"
1213
CIBW_ENVIRONMENT_PASS_LINUX: "LIBZIM_DL_VERSION"
1314
CIBW_BUILD_VERBOSITY: "3"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ testpaths = ["tests"]
1111
pythonpath = ["."]
1212

1313
[tool.cibuildwheel]
14-
build = "*"
14+
build = "cp312-win_amd64"
1515
# disabling windows until hhttps://github.com/kiwix/kiwix-build/issues/466
1616
# disabling PyPy due to 2 failing tests
1717
skip = "pp* *-win*"

setup.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Config:
4646
"Darwin": ["x86_64", "arm64"],
4747
"Linux": ["x86_64", "aarch64"],
4848
"Linux-musl": ["x86_64", "aarch64"],
49+
"Windows": ["amd64"],
4950
}
5051

5152
base_dir: pathlib.Path = Path(__file__).parent
@@ -101,7 +102,7 @@ def arch(self) -> str:
101102
# we extract the cross-compile arch from it
102103
return (
103104
os.getenv("_PYTHON_HOST_PLATFORM", "").rsplit("-", 1)[-1]
104-
or sysplatform.machine()
105+
or sysplatform.machine().lower()
105106
)
106107

107108
def check_platform(self):
@@ -121,8 +122,19 @@ def libzim_fname(self):
121122
return {
122123
"Darwin": f"libzim.{self.libzim_major}.dylib",
123124
"Linux": f"libzim.so.{self.libzim_major}",
125+
"Windows": f"zim-{self.libzim_major}.dll",
124126
}[self.platform]
125127

128+
@property
129+
def archive_suffix(self):
130+
if self.platform == "Windows":
131+
return ".zip"
132+
return ".tar.gz"
133+
134+
@property
135+
def archive_format(self):
136+
return {".zip": "zip", ".tar.gz": "gztar"}.get(self.archive_suffix)
137+
126138
@property
127139
def is_musl(self) -> bool:
128140
"""whether running on a musl system (Alpine)"""
@@ -145,7 +157,13 @@ def get_download_filename(self, arch: Optional[str] = None) -> str:
145157
"""filename to download to get binary libzim for platform/arch"""
146158
arch = arch or self.arch
147159

148-
lzplatform = {"Darwin": "macos", "Linux": "linux"}.get(self.platform)
160+
# believe this is incorrect naming at openZIM ; will open ticket
161+
if self.platform == "Windows" and arch == "amd64":
162+
arch = "x86_64"
163+
164+
lzplatform = {"Darwin": "macos", "Linux": "linux", "Windows": "win"}.get(
165+
self.platform
166+
)
149167

150168
variant = ""
151169
if self.platform == "Linux":
@@ -157,7 +175,7 @@ def get_download_filename(self, arch: Optional[str] = None) -> str:
157175
version_suffix = f"-{self.libzim_dl_version}"
158176

159177
return pathlib.Path(
160-
f"libzim_{lzplatform}-{arch}{variant}{version_suffix}.tar.gz"
178+
f"libzim_{lzplatform}-{arch}{variant}{version_suffix}{self.archive_suffix}"
161179
).name
162180

163181
def download_to_dest(self):
@@ -227,15 +245,16 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
227245

228246
print("> extracting archive")
229247
# extract into current folder (all files are inside an in-tar folder)
230-
shutil.unpack_archive(fpath, self.base_dir, "gztar")
248+
shutil.unpack_archive(fpath, self.base_dir, self.archive_format)
231249

232250
# nightly have different download name and extracted folder name as it
233251
# uses a redirect
252+
# TODO: FIX for zip
234253
if self.is_latest_nightly:
235254
tar = tarfile.open(fpath)
236255
folder = pathlib.Path(pathlib.Path(tar.firstmember.name).parts[0])
237256
else:
238-
folder = fpath.with_name(fpath.name.replace(".tar.gz", ""))
257+
folder = fpath.with_name(fpath.name.replace(self.archive_suffix, ""))
239258

240259
return folder
241260

@@ -254,6 +273,14 @@ def _install_from(self, folder: pathlib.Path):
254273
for fpath in folder.joinpath("lib").rglob("libzim.*"):
255274
print(f"{fpath} -> {libzim_dir / fpath.name}")
256275
os.replace(fpath, libzim_dir / fpath.name)
276+
# windows has different folder and name
277+
for fpath in folder.joinpath("bin").rglob("zim-*.dll"):
278+
print(f"{fpath} -> {libzim_dir / fpath.name}")
279+
os.replace(fpath, libzim_dir / fpath.name)
280+
# windows again, not sure its required at all
281+
for fpath in folder.joinpath("lib").rglob("zim.lib"):
282+
print(f"{fpath} -> {libzim_dir / fpath.name}")
283+
os.replace(fpath, libzim_dir / fpath.name)
257284

258285
# remove temp folder
259286
shutil.rmtree(folder, ignore_errors=True)
@@ -284,7 +311,7 @@ def cleanup(self):
284311
# we downloaded libzim, so we must remove it
285312
if self.download_libzim:
286313
print("removing downloaded libraries")
287-
for fpath in self.dylib_file.parent.glob("*.[dylib|so]*"):
314+
for fpath in self.dylib_file.parent.glob("*.[dylib|so|dll|lib]*"):
288315
print(">", fpath)
289316
fpath.unlink(missing_ok=True)
290317
if self.header_file.parent.exists():
@@ -490,11 +517,9 @@ class DownloadLibzim(Command):
490517

491518
user_options = []
492519

493-
def initialize_options(self):
494-
...
520+
def initialize_options(self): ...
495521

496-
def finalize_options(self):
497-
...
522+
def finalize_options(self): ...
498523

499524
def run(self):
500525
config.download_to_dest()
@@ -503,11 +528,9 @@ def run(self):
503528
class LibzimClean(Command):
504529
user_options = []
505530

506-
def initialize_options(self):
507-
...
531+
def initialize_options(self): ...
508532

509-
def finalize_options(self):
510-
...
533+
def finalize_options(self): ...
511534

512535
def run(self):
513536
config.cleanup()

0 commit comments

Comments
 (0)