Skip to content

Commit

Permalink
Add script to generate release zipfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Sep 27, 2024
1 parent 3b1200d commit 88c6f0c
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pack_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding:utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import os
from pathlib import Path
import pip
from zipfile import ZipFile, ZIP_DEFLATED


INSTALL_BAT = """
pip install {}
pause
"""


def package(root: Path, whl_path: Path, pack_files: [Path | str]):
fpath_zip = whl_path.with_suffix(whl_path.suffix + ".zip")
package_root = Path(whl_path.with_suffix("").name)

with ZipFile(fpath_zip, "w", compression=ZIP_DEFLATED) as package:
with open(whl_path, "rb") as fp:
package.writestr(str(package_root / whl_path.name),
fp.read())

for pack_file in pack_files:
pack_file = Path(pack_file)
with open(pack_file, "r") as fp:
package.writestr(str(package_root / pack_file.name),
fp.read())

package.writestr(str(package_root / "install.bat"),
INSTALL_BAT.format(whl_path.name))
print(f"Package written to `{fpath_zip}`")


def whl_files(root):
for entry in os.scandir(root):
if entry.is_file() and os.path.splitext(entry.path)[1] == ".whl":
yield Path(entry.path)


def main():
root = Path(__file__).parent

for whl in whl_files(root):
os.remove(whl)

pip.main(["wheel", str(root)])

for whl in whl_files(root):
if whl.name.startswith("production_planner"):
package(root, whl, [root / "run.bat", root / "README.md", root / "LICENSE"])
break


if __name__ == "__main__":
main()

0 comments on commit 88c6f0c

Please sign in to comment.