-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate release zipfile
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |