60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
"""Build wheel and source distribution for publishing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parent
|
|
DIST_DIR = PROJECT_ROOT / "dist"
|
|
BUILD_DIR = PROJECT_ROOT / "build"
|
|
|
|
|
|
def run(cmd: list[str]) -> None:
|
|
print(f"[+] Running: {' '.join(cmd)}")
|
|
result = subprocess.run(cmd, cwd=PROJECT_ROOT)
|
|
if result.returncode != 0:
|
|
raise SystemExit(result.returncode)
|
|
|
|
|
|
def ensure_package(package: str) -> None:
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "pip", "show", package],
|
|
cwd=PROJECT_ROOT,
|
|
stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL,
|
|
)
|
|
if result.returncode != 0:
|
|
print(f"[+] Installing missing dependency: {package}")
|
|
run([sys.executable, "-m", "pip", "install", package])
|
|
|
|
|
|
def main() -> None:
|
|
print()
|
|
print("=" * 72)
|
|
print("Booklooker Client - Build Python Distribution")
|
|
print("=" * 72)
|
|
print()
|
|
|
|
ensure_package("build")
|
|
|
|
if DIST_DIR.exists():
|
|
shutil.rmtree(DIST_DIR)
|
|
if BUILD_DIR.exists():
|
|
shutil.rmtree(BUILD_DIR)
|
|
|
|
run([sys.executable, "-m", "build"])
|
|
|
|
files = sorted(path.name for path in DIST_DIR.glob("*"))
|
|
print()
|
|
print("Built artifacts:")
|
|
for name in files:
|
|
print(f" - {name}")
|
|
print()
|
|
print("Build completed successfully.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|