From e518654ffdfbe2d0564a71e4c992c68e6591828f Mon Sep 17 00:00:00 2001 From: The Metaist Date: Fri, 13 Sep 2024 05:30:31 -0400 Subject: [PATCH] fix: newer python syntax, methods (#1) --- src/cosmofy/bundler.py | 8 +++++--- src/cosmofy/zipfile2.py | 29 ++++++++++++++--------------- test/test_bundler.py | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/cosmofy/bundler.py b/src/cosmofy/bundler.py index da165e8..75b2acd 100644 --- a/src/cosmofy/bundler.py +++ b/src/cosmofy/bundler.py @@ -86,7 +86,8 @@ def compile_python(path: Path, source: Optional[bytes] = None) -> bytearray: def move_set_executable(src: Path, dest: Path) -> Path: """Move a file and set its executable bit.""" dest.parent.mkdir(parents=True, exist_ok=True) - shutil.move(src, dest) + # TODO 2024-10-31 @ py3.8 EOL: use `Path` instead of `str` + shutil.move(str(src), str(dest)) mode = dest.stat().st_mode | stat.S_IEXEC dest.chmod(mode) return dest @@ -159,9 +160,10 @@ def archive_from_cache( if self.args.for_real: download_if_newer(COSMOFY_PYTHON_URL, self.args.cache / "python") - log.debug(f"{self.banner}copy: {self.args.cache / "python"} to {dest}") + src = self.args.cache / "python" + log.debug(f"{self.banner}copy: {src} to {dest}") if self.args.for_real: - shutil.copy(self.args.cache / "python", dest) + shutil.copy(src, dest) return archive or _archive(dest) diff --git a/src/cosmofy/zipfile2.py b/src/cosmofy/zipfile2.py index 182c4be..013f794 100644 --- a/src/cosmofy/zipfile2.py +++ b/src/cosmofy/zipfile2.py @@ -19,21 +19,20 @@ class ZipFile2(ZipFile): """Extension of `zipfile.ZipFile` that allows removing members.""" - def add_dir(self, name: str, mode: int = 0o777, date: datetime = now) -> ZipFile2: - """Add a directory to an archive with permissions.""" - - if not name.endswith("/"): - name += "/" - - info = ZipInfo(name, date.timetuple()[:6]) - info.compress_size = 0 - info.CRC = 0 - info.external_attr = ((0o40000 | mode) & 0xFFFF) << 16 - info.external_attr |= 0x10 - info.file_size = 0 - info.flag_bits |= 0x800 - self.mkdir(info) - return self + # NOTE: This function only works on python >= 3.11 + # def add_dir(self, name: str, mode: int = 0o777, date: datetime = now) -> ZipFile2: + # """Add a directory to an archive with permissions.""" + # if not name.endswith("/"): + # name += "/" + # info = ZipInfo(name, date.timetuple()[:6]) + # info.compress_size = 0 + # info.CRC = 0 + # info.external_attr = ((0o40000 | mode) & 0xFFFF) << 16 + # info.external_attr |= 0x10 + # info.file_size = 0 + # info.flag_bits |= 0x800 + # self.mkdir(info) + # return self def add_file( self, diff --git a/test/test_bundler.py b/test/test_bundler.py index 44f7274..502241c 100644 --- a/test/test_bundler.py +++ b/test/test_bundler.py @@ -1,8 +1,8 @@ """Test bundler.""" # std -import io from pathlib import Path +import io # pkg from cosmofy.bundler import RE_MAIN