import zipfile import os import json EXAMPLES_DIR = os.path.dirname(os.path.abspath(__file__)) def make_pure_wheel(name, version, out_dir): dist_info = f"{name}-{version}.dist-info" os.makedirs(f"/tmp/{dist_info}", exist_ok=True) metadata = f"""Metadata-Version: 2.1 Name: {name} Version: {version} Summary: Test pure-Python wheel """ with open(f"/tmp/{dist_info}/METADATA", "w") as f: f.write(metadata) with open(f"/tmp/{dist_info}/WHEEL", "w") as f: f.write("Wheel-Version: 1.0\nGenerator: test\nRoot-Is-Purelib: true\nTag: py3-none-any\n") with open(f"/tmp/{dist_info}/RECORD", "w") as f: f.write("") wheel_name = f"{name}-{version}-py3-none-any.whl" wheel_path = os.path.join(out_dir, wheel_name) with zipfile.ZipFile(wheel_path, "w", zipfile.ZIP_DEFLATED) as zf: zf.write(f"/tmp/{dist_info}/METADATA", f"{dist_info}/METADATA") zf.write(f"/tmp/{dist_info}/WHEEL", f"{dist_info}/WHEEL") zf.write(f"/tmp/{dist_info}/RECORD", f"{dist_info}/RECORD") pkg_dir = f"{name}" zf.writestr(f"{pkg_dir}/__init__.py", "def hello(): return 'hello'\n") for f in os.listdir(f"/tmp/{dist_info}"): os.remove(f"/tmp/{dist_info}/{f}") os.rmdir(f"/tmp/{dist_info}") return wheel_path def make_native_wheel(name, version, out_dir): dist_info = f"{name}-{version}.dist-info" os.makedirs(f"/tmp/{dist_info}", exist_ok=True) metadata = f"""Metadata-Version: 2.1 Name: {name} Version: {version} Summary: Test native wheel """ with open(f"/tmp/{dist_info}/METADATA", "w") as f: f.write(metadata) with open(f"/tmp/{dist_info}/WHEEL", "w") as f: f.write("Wheel-Version: 1.0\nGenerator: test\nRoot-Is-Purelib: false\nTag: cp38-cp38-manylinux_2_17_x86_64\n") with open(f"/tmp/{dist_info}/RECORD", "w") as f: f.write("") wheel_name = f"{name}-{version}-cp38-cp38-manylinux_2_17_x86_64.whl" wheel_path = os.path.join(out_dir, wheel_name) with zipfile.ZipFile(wheel_path, "w", zipfile.ZIP_DEFLATED) as zf: zf.write(f"/tmp/{dist_info}/METADATA", f"{dist_info}/METADATA") zf.write(f"/tmp/{dist_info}/WHEEL", f"{dist_info}/WHEEL") zf.write(f"/tmp/{dist_info}/RECORD", f"{dist_info}/RECORD") zf.writestr(f"{name}/__init__.py", "def hello(): return 'hello'\n") zf.writestr(f"{name}/_native.cpython-38-x86_64-linux-gnu.so", b"\x7fELF...fake") for f in os.listdir(f"/tmp/{dist_info}"): os.remove(f"/tmp/{dist_info}/{f}") os.rmdir(f"/tmp/{dist_info}") return wheel_path if __name__ == "__main__": out = EXAMPLES_DIR pure = make_pure_wheel("ecoark_demo", "0.1.0", out) native = make_native_wheel("ecoark_native_demo", "0.1.0", out) print(json.dumps({"pure": pure, "native": native}, indent=2))