@@ -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):
503528class 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