Skip to content

Commit 68ed8ef

Browse files
authored
Merge pull request #177 from openzim/musl2
musl support
2 parents 6a7e19f + a0c335e commit 68ed8ef

3 files changed

Lines changed: 29 additions & 7 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: "8.2.1-1"
5+
LIBZIM_DL_VERSION: "nightly"
66

77
jobs:
88
lint:

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- main
88

99
env:
10-
LIBZIM_DL_VERSION: "8.2.1-1"
10+
LIBZIM_DL_VERSION: "nightly"
1111
MACOSX_DEPLOYMENT_TARGET: "11.0"
1212
CIBW_ENVIRONMENT_PASS_LINUX: "LIBZIM_DL_VERSION"
1313
CIBW_BUILD_VERBOSITY: "3"

setup.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import subprocess
1818
import sys
1919
import sysconfig
20+
import tarfile
2021
import urllib.request
2122
from ctypes.util import find_library
2223
from pathlib import Path
@@ -67,9 +68,16 @@ def libzim_major(self) -> str:
6768
def found_libzim(self) -> str:
6869
return find_library("zim")
6970

71+
@property
72+
def is_latest_nightly(self) -> bool:
73+
"""will use redirect to latest available nightly"""
74+
return self.libzim_dl_version == "nightly"
75+
7076
@property
7177
def is_nightly(self) -> bool:
72-
return re.match(r"\d{4}-\d{2}-\d{2}", self.libzim_dl_version)
78+
return self.is_latest_nightly or re.match(
79+
r"\d{4}-\d{2}-\d{2}", self.libzim_dl_version
80+
)
7381

7482
@property
7583
def platform(self) -> str:
@@ -122,7 +130,7 @@ def is_musl(self) -> bool:
122130
["/usr/bin/env", "ldd", "--version"], capture_output=True, text=True
123131
)
124132
try:
125-
return "musl libc" in ps.stdout.readlines()[0]
133+
return "musl libc" in ps.stderr.splitlines()[0]
126134
except Exception:
127135
return False
128136

@@ -143,8 +151,13 @@ def get_download_filename(self, arch: Optional[str] = None) -> str:
143151
if self.platform == "Linux":
144152
variant = "-musl" if self.is_musl else "-bionic"
145153

154+
if self.is_latest_nightly:
155+
version_suffix = ""
156+
else:
157+
version_suffix = f"-{self.libzim_dl_version}"
158+
146159
return pathlib.Path(
147-
f"libzim_{lzplatform}-{arch}{variant}-{self.libzim_dl_version}.tar.gz"
160+
f"libzim_{lzplatform}-{arch}{variant}{version_suffix}.tar.gz"
148161
).name
149162

150163
def download_to_dest(self):
@@ -196,7 +209,9 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
196209

197210
fpath = self.base_dir / filename
198211
source_url = "http://download.openzim.org/release/libzim"
199-
if self.is_nightly:
212+
if self.is_latest_nightly:
213+
source_url = "http://download.openzim.org/nightly"
214+
elif self.is_nightly:
200215
source_url = f"http://download.openzim.org/nightly/{self.libzim_dl_version}"
201216
url = f"{source_url}/{fpath.name}"
202217

@@ -213,7 +228,14 @@ def _download_and_extract(self, filename: str) -> pathlib.Path:
213228
print("> extracting archive")
214229
# extract into current folder (all files are inside an in-tar folder)
215230
shutil.unpack_archive(fpath, self.base_dir, "gztar")
216-
folder = fpath.with_name(fpath.name.replace(".tar.gz", ""))
231+
232+
# nightly have different download name and extracted folder name as it
233+
# uses a redirect
234+
if self.is_latest_nightly:
235+
tar = tarfile.open(fpath)
236+
folder = pathlib.Path(pathlib.Path(tar.firstmember.name).parts[0])
237+
else:
238+
folder = fpath.with_name(fpath.name.replace(".tar.gz", ""))
217239

218240
return folder
219241

0 commit comments

Comments
 (0)