Skip to content

Commit e12aa8c

Browse files
committed
Added post-process cleanup to remove downloaded files
Re-run of build/setup could be compromised by the presence of previous libraries or headers
1 parent 197dde2 commit e12aa8c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

setup.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,19 @@ def _install_from(self, folder: pathlib.Path):
259259
file=sys.stderr,
260260
)
261261

262+
def cleanup(self):
263+
""" removes created files to prevent re-run issues"""
264+
# we downloaded libzim, so we must remove it
265+
if self.download_libzim:
266+
print("removing downloaded libraries")
267+
for fpath in self.dylib_file.parent.glob("*.[dylib|so]*"):
268+
print(">", fpath)
269+
fpath.unlink(missing_ok=True)
270+
if self.header_file.parent.exists():
271+
print("removing downloaded headers")
272+
shutil.rmtree(self.header_file.parent, ignore_errors=True)
273+
274+
262275
@property
263276
def header_file(self) -> pathlib.Path:
264277
return self.base_dir / "include" / "zim" / "zim.h"
@@ -475,7 +488,12 @@ def run(self):
475488
config.check_platform()
476489
ext_modules = get_cython_extension()
477490

478-
setup(
479-
cmdclass={"build_ext": LibzimBuildExt, "download_libzim": DownloadLibzim},
480-
ext_modules=ext_modules,
481-
)
491+
try:
492+
setup(
493+
cmdclass={"build_ext": LibzimBuildExt, "download_libzim": DownloadLibzim},
494+
ext_modules=ext_modules,
495+
)
496+
except Exception as exc:
497+
raise exc
498+
finally:
499+
config.cleanup()

0 commit comments

Comments
 (0)