|
| 1 | +# Use python setup.py bdist_wheel |
| 2 | +import os |
| 3 | +import sys |
| 4 | +import re |
| 5 | +import pathlib |
| 6 | +import shutil |
| 7 | + |
| 8 | +try: |
| 9 | + # noinspection PyUnusedImports |
| 10 | + from setuptools import setup, find_packages |
| 11 | + import wheel |
| 12 | +except ImportError: |
| 13 | + sys.exit( |
| 14 | + f"[x] Missing required dependencies (either wheel or setuptools)\n" |
| 15 | + " Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building." |
| 16 | + ) |
| 17 | + |
| 18 | +print("[*] Starting setup.py script for pyCTools...\n") |
| 19 | + |
| 20 | +# Change to the script's root directory |
| 21 | +os.chdir(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) |
| 22 | + |
| 23 | + |
| 24 | +def prompt_version(): |
| 25 | + try: |
| 26 | + pattern = re.compile(r"^\d+\.\d+\.\d+(-[A-Za-z0-9]+)?$") |
| 27 | + while True: |
| 28 | + version = input("[?] Enter package version (format x.x.x or x.x.x-suffix): ").strip() |
| 29 | + if pattern.match(version): |
| 30 | + print("\033[90m") |
| 31 | + return version |
| 32 | + else: |
| 33 | + print("[!] Invalid version format. Expected something like 1.0.0 or 1.0.0-beta => Trying again...\n") |
| 34 | + except KeyboardInterrupt: |
| 35 | + sys.exit("\n[!] Version input interrupted. Exiting setup.\n") |
| 36 | + |
| 37 | + |
| 38 | +# Path to the bin folder inside pyCTools |
| 39 | +bin_path = os.path.join("pyCTools", "bin") |
| 40 | + |
| 41 | +# Check that bin exists and has x86 & x64 DLLs |
| 42 | +if not os.path.isdir(bin_path): |
| 43 | + sys.exit( |
| 44 | + "[x] 'pyCTools/bin/' folder not found.\n" |
| 45 | + " Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building.\n" |
| 46 | + ) |
| 47 | + |
| 48 | +# Check subfolders and DLL presence |
| 49 | +for arch in ("x86", "x64"): |
| 50 | + arch_path = os.path.join(bin_path, arch) |
| 51 | + if not os.path.isdir(arch_path) or not any(f.lower().endswith(".dll") for f in os.listdir(arch_path)): |
| 52 | + sys.exit( |
| 53 | + f"[x] Missing DLLs in pyCTools/bin/{arch}/\n" |
| 54 | + " Suggested action: Run 'compilerHelper.ps1' to generate the DLLs before building.\n" |
| 55 | + ) |
| 56 | + |
| 57 | +# Ensure ../dist/pip/ exists |
| 58 | +output_dir = pathlib.Path(__file__).parent.parent / "dist" / "pip" |
| 59 | +output_dir.mkdir(parents=True, exist_ok=True) |
| 60 | + |
| 61 | +try: |
| 62 | + setup( |
| 63 | + name="pyCTools", |
| 64 | + version=prompt_version(), |
| 65 | + packages=find_packages(), |
| 66 | + include_package_data=True, |
| 67 | + package_data={ |
| 68 | + "pyCTools": ["bin/x86/*.dll", "bin/x64/*.dll"], |
| 69 | + }, |
| 70 | + description="Your pyCTools package with bundled DLLs", |
| 71 | + author="Shahm Najeeb", |
| 72 | + |
| 73 | + url="https://github.com/DefinetlyNotAI/PyCTools", |
| 74 | + classifiers=[ |
| 75 | + "Programming Language :: Python :: 3", |
| 76 | + "Operating System :: Microsoft :: Windows", |
| 77 | + ], |
| 78 | + options={ |
| 79 | + "bdist_wheel": {"dist_dir": str(output_dir)}, |
| 80 | + "sdist": {"dist_dir": str(output_dir)}, |
| 81 | + }, |
| 82 | + ) |
| 83 | + |
| 84 | + print("\033[0m\n[*] Completed setup.py execution successfully [To cleanup now].") |
| 85 | + if not os.path.isfile("../dist/bin.zip"): |
| 86 | + print( |
| 87 | + " Suggested action: Run 'distributionHelper.ps1' to create the distribution package for github releases.") |
| 88 | + print(" Suggested action: Execute the following to test in VENV:\n\033[96m" |
| 89 | + " cd ..\n" |
| 90 | + " python -m venv dist/venv_test\n" |
| 91 | + " dist\\venv_test\\Scripts\\Activate.ps1\n" |
| 92 | + " python -m pip install --upgrade pip\n" |
| 93 | + " pip install dist/pip/pyctools-0.2.0b0-py3-none-any.whl\n" |
| 94 | + " python example/hwrng_example.py\n" |
| 95 | + " python example/process_inspect_example.py\n" |
| 96 | + " deactivate\n" |
| 97 | + " Remove-Item -Recurse -Force dist\\venv_test\n\033[0m") |
| 98 | +except Exception as e: |
| 99 | + sys.exit(f"\033[0m[x] An error occurred during setup: {e}\n") |
| 100 | + |
| 101 | +# Cleanup: remove pyCTools.egg-info and build directories if they exist |
| 102 | +for cleanup_dir in ["pyCTools.egg-info", "build", "../pyCTools.egg-info", "../build", "dist"]: |
| 103 | + cleanup_path = pathlib.Path(__file__).parent / cleanup_dir |
| 104 | + if cleanup_path.exists() and cleanup_path.is_dir(): |
| 105 | + shutil.rmtree(cleanup_path) |
| 106 | +print("\033[90m[*] Completed setup.py script cleanup successfully.\033[0m") |
0 commit comments