-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
243 additions
and
1 deletion.
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
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,199 @@ | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
import tomlkit | ||
|
||
IGNORES = ["MaaHttp*", "MaaPiCli*"] | ||
|
||
|
||
def set_toml_ver(): | ||
TOML_FILE = "pyproject.toml" | ||
|
||
version = sys.argv[1] | ||
if "ci" in version: | ||
base_ver, ci_ver = version.split("ci") | ||
version = base_ver + "dev" + ci_ver.split("-")[0] | ||
|
||
print("Setting version to:", version) | ||
|
||
with open(TOML_FILE, "r") as f: | ||
py_project = tomlkit.load(f) | ||
py_project["project"]["version"] = version | ||
|
||
with open(TOML_FILE, "w") as f: | ||
tomlkit.dump(py_project, f) | ||
|
||
|
||
WHL_DIR = "wheel" | ||
DIST_DIR = "dist" | ||
SRC_DIR = "src" | ||
|
||
|
||
def clean_cwd(): | ||
print("Cleaning working dir...") | ||
|
||
for root, dirs, files in os.walk(os.getcwd()): | ||
for dir_name in dirs: | ||
if ( | ||
dir_name | ||
in ( | ||
SRC_DIR, | ||
DIST_DIR, | ||
WHL_DIR, | ||
"__pycache__", | ||
".cache", | ||
"build", | ||
) | ||
or ".egg-info" in dir_name | ||
): | ||
|
||
shutil.rmtree(os.path.join(root, dir_name)) | ||
print(" Removing", dir_name) | ||
for file_name in files: | ||
if file_name.endswith( | ||
(".pyc", ".pyo", ".whl", ".md"), | ||
): | ||
os.remove(os.path.join(root, file_name)) | ||
print(" Removing", file_name) | ||
|
||
print("done") | ||
|
||
|
||
def gen_base_whl(): | ||
print("Generating base wheel...", end="") | ||
subprocess.check_output( | ||
[sys.executable, "-m", "build", "-w"], | ||
) | ||
print("done") | ||
|
||
|
||
def unpack_base_whl() -> str: | ||
"""Return: unpack path""" | ||
|
||
print("Unpacking base wheel...", end="") | ||
|
||
whl_name = os.listdir(DIST_DIR)[0] | ||
subprocess.check_output( | ||
[sys.executable, "-m", "wheel", "unpack", whl_name], | ||
cwd=DIST_DIR, | ||
) | ||
|
||
for file in os.listdir(DIST_DIR): | ||
unpack_path = os.path.join(DIST_DIR, file) | ||
if os.path.isdir(unpack_path): | ||
unpack_dir = file | ||
break | ||
|
||
for file in os.listdir(unpack_path): | ||
if ".dist-info" in file: | ||
info_dir = file | ||
break | ||
|
||
info_path = os.path.join(unpack_path, info_dir) | ||
os.remove(os.path.join(info_path, "RECORD")) | ||
|
||
print("done") | ||
return unpack_dir, info_path | ||
|
||
|
||
ASSETS_PATH = os.path.join("..", "..", "assets") | ||
|
||
|
||
def pack(pack_dir: str, info_path: str): | ||
WHL_TAGS = { | ||
"win-x86_64": "win_amd64", | ||
"win-aarch64": "win_arm64", | ||
"macos-x86_64": "macosx_13_0_x86_64", | ||
"macos-aarch64": "macosx_13_0_arm64", | ||
"linux-x86_64": "manylinux2014_x86_64", | ||
"linux-aarch64": "manylinux2014_aarch64", | ||
} | ||
|
||
os.mkdir(WHL_DIR) | ||
|
||
wheel_path = os.path.join(info_path, "WHEEL") | ||
|
||
def edit_whl_tag(whl_tag: str): | ||
print(f" Editing wheel tag to: {whl_tag}...", end="") | ||
|
||
lines = [] | ||
for line in open(wheel_path, "r"): | ||
if line.startswith("Tag:"): | ||
line = "Tag: " + "py3-none-" + whl_tag | ||
lines.append(line.rstrip()) | ||
with open(wheel_path, "w") as f: | ||
f.write("\n".join(lines)) | ||
|
||
print("done") | ||
|
||
pack_bin_path = os.path.join(DIST_DIR, pack_dir, "maa", "bin") | ||
|
||
def copy_bin(platform: str): | ||
print(f" Copying bin for: {platform}...", end="") | ||
|
||
bin_path = os.path.join(ASSETS_PATH, "MAA-" + platform, "bin") | ||
shutil.copytree( | ||
bin_path, | ||
pack_bin_path, | ||
ignore=shutil.ignore_patterns(*IGNORES), | ||
) | ||
|
||
print("done") | ||
|
||
def clean_bin(): | ||
print(" Cleaning bin...", end="") | ||
shutil.rmtree(pack_bin_path) | ||
print("done") | ||
|
||
def pack_whl(whl_tag: str): | ||
print(f" Packing whl for: {whl_tag}...", end="") | ||
|
||
pack_path = os.path.join("..", DIST_DIR, pack_dir) | ||
subprocess.check_output( | ||
[sys.executable, "-m", "wheel", "pack", pack_path], | ||
cwd=WHL_DIR, | ||
) | ||
|
||
print("done") | ||
|
||
for platform, whl_tag in WHL_TAGS.items(): | ||
print(f"Packing for: {platform}...") | ||
|
||
edit_whl_tag(whl_tag) | ||
copy_bin(platform) | ||
pack_whl(whl_tag) | ||
clean_bin() | ||
|
||
print("done") | ||
|
||
|
||
def copy_base(): | ||
print("Copying base...", end="") | ||
|
||
asset_dir = os.listdir(ASSETS_PATH)[0] | ||
asset_path = os.path.join(ASSETS_PATH, asset_dir) | ||
src_path = os.path.join(asset_path, "binding", "Python") | ||
shutil.copytree(src_path, SRC_DIR) | ||
|
||
readme_path = os.path.join(asset_path, "README.md") | ||
shutil.copy(readme_path, "README.md") | ||
|
||
license_path = os.path.join(asset_path, "LICENSE.md") | ||
shutil.copy(license_path, "LICENSE.md") | ||
|
||
print("done") | ||
|
||
|
||
def main(): | ||
clean_cwd() | ||
set_toml_ver() | ||
copy_base() | ||
gen_base_whl() | ||
paths = unpack_base_whl() | ||
pack(*paths) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,12 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "MaaFw" | ||
version = "0" | ||
authors = [{ name = "MaaXYZ" }] | ||
description = "An automation black-box testing framework based on image recognition" | ||
readme = "README.md" | ||
urls = { Homepage = "https://github.com/MaaXYZ/MaaFramework" } | ||
dependencies = ["numpy", "Pillow", "MaaAgentBinary"] |