|
18 | 18 | import pathlib |
19 | 19 | import shutil |
20 | 20 | import zipfile |
| 21 | +import platform |
| 22 | +import subprocess |
21 | 23 |
|
22 | 24 | from cx_Freeze import Freezer, Executable |
23 | 25 |
|
| 26 | + |
| 27 | +def get_mac_architecture(): |
| 28 | + try: |
| 29 | + # Get the hardware architecture using sysctl |
| 30 | + arch = subprocess.check_output( |
| 31 | + ['sysctl', '-n', 'hw.machine'], |
| 32 | + stderr=subprocess.DEVNULL |
| 33 | + ).decode().strip() |
| 34 | + return arch |
| 35 | + except subprocess.CalledProcessError: |
| 36 | + # Fallback to platform.machine() if sysctl isn't available (unlikely on macOS) |
| 37 | + return platform.machine() |
| 38 | + |
24 | 39 | FILE_ROOT_PATH = pathlib.Path(__file__).parent |
25 | 40 |
|
26 | 41 |
|
@@ -59,29 +74,33 @@ def remove_dist_info_folders(directory: pathlib.Path): |
59 | 74 |
|
60 | 75 |
|
61 | 76 | if __name__ == '__main__': |
| 77 | + tmp_python_version = f"{sys.version_info.major}.{sys.version_info.minor}" |
| 78 | + tmp_shared_suffix = f".cpython-{tmp_python_version.replace('.', '')}-darwin.so" |
| 79 | + tmp_arch = get_mac_architecture() |
| 80 | + tmp_build_dir_name = f"exe.macosx-{tmp_arch}-{tmp_python_version}" |
62 | 81 | freezer.freeze() |
63 | | - with zipfile.ZipFile(pathlib.Path(f"{FILE_ROOT_PATH}/build/exe.linux-x86_64-3.11/lib/library.zip"), 'r') as zip_ref: |
64 | | - zip_ref.extractall(pathlib.Path(f"{FILE_ROOT_PATH}/build/exe.linux-x86_64-3.11/lib")) |
65 | | - _CMD_FROM_BUILD_DIR = pathlib.Path(FILE_ROOT_PATH.parent / "cmake-build-release" / "_cmd.cpython-311-x86_64-linux-gnu.so") |
66 | | - _CMD_FROM_PRE_BUILT_DIR = pathlib.Path(FILE_ROOT_PATH.parent / "pre-built" / "_cmd.cpython-311-x86_64-linux-gnu.so") |
67 | | - if _CMD_FROM_BUILD_DIR.exists(): |
68 | | - shutil.copy( |
69 | | - _CMD_FROM_BUILD_DIR, |
70 | | - pathlib.Path(FILE_ROOT_PATH / "build/exe.linux-x86_64-3.11/lib/pymol" / "_cmd.cpython-311-x86_64-linux-gnu.so") |
71 | | - ) |
| 82 | + with zipfile.ZipFile(pathlib.Path(f"{FILE_ROOT_PATH}/build/{tmp_build_dir_name}/lib/library.zip"), 'r') as zip_ref: |
| 83 | + zip_ref.extractall(pathlib.Path(f"{FILE_ROOT_PATH}/build/{tmp_build_dir_name}/lib")) |
| 84 | + if not pathlib.Path(const.PROJECT_ROOT_DIR / "src/python/pymol").exists(): |
| 85 | + utils.copy_pymol_sources() |
| 86 | + _CMD_FROM_BUILD_DIR = pathlib.Path(const.PROJECT_ROOT_DIR / "cmake-build-release" / f"_cmd{tmp_shared_suffix}") |
| 87 | + if _CMD_FROM_BUILD_DIR.exists(): |
| 88 | + shutil.copy( |
| 89 | + _CMD_FROM_BUILD_DIR, |
| 90 | + pathlib.Path(const.PROJECT_ROOT_DIR / "src/python/pymol" / f"_cmd{tmp_shared_suffix}") |
| 91 | + ) |
| 92 | + else: |
| 93 | + print(f"Could not find _cmd{tmp_shared_suffix} for building the EXE file.") |
72 | 94 | else: |
73 | | - shutil.copy( |
74 | | - _CMD_FROM_PRE_BUILT_DIR, |
75 | | - pathlib.Path(FILE_ROOT_PATH / "build/exe.linux-x86_64-3.11/lib/pymol" / "_cmd.cpython-311-x86_64-linux-gnu.so") |
76 | | - ) |
77 | | - remove_dist_info_folders(pathlib.Path(FILE_ROOT_PATH / "build/exe.linux-x86_64-3.11/lib")) |
| 95 | + print("The src/python/pymol directory already exists, that might mean a self compiled _cmd module was built.") |
| 96 | + remove_dist_info_folders(pathlib.Path(FILE_ROOT_PATH / f"build/{tmp_build_dir_name}/lib")) |
78 | 97 | shutil.copytree( |
79 | 98 | str(pathlib.Path(FILE_ROOT_PATH / "pymol/wizard")), |
80 | | - str(pathlib.Path(FILE_ROOT_PATH / "build/exe.linux-x86_64-3.11/lib/pymol/wizard")), |
| 99 | + str(pathlib.Path(FILE_ROOT_PATH / f"build/{tmp_build_dir_name}/lib/pymol/wizard")), |
81 | 100 | dirs_exist_ok=True |
82 | 101 | ) |
83 | 102 | shutil.copytree( |
84 | 103 | str(pathlib.Path(FILE_ROOT_PATH / "pymol/data/startup")), |
85 | | - str(pathlib.Path(FILE_ROOT_PATH / "build/exe.linux-x86_64-3.11/lib/pymol/data/startup")), |
| 104 | + str(pathlib.Path(FILE_ROOT_PATH / f"build/{tmp_build_dir_name}/lib/pymol/data/startup")), |
86 | 105 | dirs_exist_ok=True |
87 | 106 | ) |
0 commit comments