Skip to content

Commit 31dc5bc

Browse files
committed
Add setuptools to github action Build Wheel
1 parent 75d8dcf commit 31dc5bc

File tree

2 files changed

+38
-77
lines changed

2 files changed

+38
-77
lines changed

.github/workflows/build_wheel.yaml

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,12 @@
1212
#-*
1313
#-*
1414
#Z* -------------------------------------------------------------------
15-
#name: Build Wheel
16-
#
17-
#on: [push]
18-
#
19-
#jobs:
20-
# build:
21-
#
22-
# runs-on: macos-latest
23-
# strategy:
24-
# matrix:
25-
# python-version: ["3.10", "3.11", "3.12"]
26-
#
27-
# steps:
28-
# - uses: actions/checkout@v4
29-
# - name: Set up Python ${{ matrix.python-version }}
30-
# uses: actions/setup-python@v5
31-
# with:
32-
# python-version: ${{ matrix.python-version }}
33-
# # You can test your matrix by printing the current Python version
34-
# - name: Display Python version
35-
# run: python -c "import sys; print(sys.version)"
36-
#
37-
# - name: Install dependencies
38-
# run: |
39-
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
40-
# brew install cmake
41-
# python -m venv .venv
42-
# ./.venv/bin/pip install wheel setuptools
43-
# ./.venv/bin/pip install -r requirements.txt
44-
# ./automator.sh setup dev-env
45-
#
46-
# - name: Build wheel
47-
# run: |
48-
# ./automator.sh build so
49-
# ./automator.sh build wheel
50-
#
51-
# - name: Upload artifact
52-
# uses: actions/upload-artifact@v4
53-
# with:
54-
# name: wheel-${{ matrix.python-version }}
55-
# path: dist/*.whl
5615
name: Build Wheel
5716

5817
on: [push]
5918

6019
env:
61-
VCPKG_ROOT: ${{ github.workspace }}/vendor/vcpkg # Match your project structure
20+
VCPKG_ROOT: ${{ github.workspace }}/vendor/vcpkg
6221

6322
jobs:
6423
build:
@@ -86,7 +45,7 @@ jobs:
8645
run: |
8746
python -m venv .venv
8847
source .venv/bin/activate
89-
python -m pip install wheel # Add other build deps if needed
48+
python -m pip install wheel setuptools # setuptools needed for Python >=3.12
9049
python -m pip install -r requirements.txt
9150
9251
- name: Bootstrap vcpkg
@@ -102,26 +61,9 @@ jobs:
10261
python automations/my_automator.py setup dev-env
10362
python automations/my_automator.py build so
10463
python automations/my_automator.py build wheel
105-
# - name: Create universal binary
106-
# if: matrix.arch == 'x86_64' # Run once after both arch builds
107-
# run: |
108-
# lipo -create \
109-
# -output dist/_cmd_universal.so \
110-
# build/lib*/_cmd*.so
111-
# rm build/lib*/_cmd*.so # Clean individual arch builds
112-
# mv dist/_cmd_universal.so build/lib/
113-
#
114-
# - name: Package wheel
115-
# if: matrix.arch == 'x86_64'
116-
# run: |
117-
# source .venv/bin/activate
118-
# python setup.py bdist_wheel
64+
11965
- name: Upload artifact
12066
uses: actions/upload-artifact@v4
12167
with:
12268
name: macpymol-wheel-${{ matrix.os }}
12369
path: dist/*.whl
124-
125-
# VCPKG_TRIPLET: x64-osx # Use arm64-osx for Apple Silicon
126-
# TRIPLET=$([ "${{ matrix.arch }}" = "arm64" ] && echo "arm64-osx" || echo "x64-osx")
127-
# arch: [x86_64, arm64]

scripts/python/build_exe.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@
1818
import pathlib
1919
import shutil
2020
import zipfile
21+
import platform
22+
import subprocess
2123

2224
from cx_Freeze import Freezer, Executable
2325

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+
2439
FILE_ROOT_PATH = pathlib.Path(__file__).parent
2540

2641

@@ -59,29 +74,33 @@ def remove_dist_info_folders(directory: pathlib.Path):
5974

6075

6176
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}"
6281
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.")
7294
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"))
7897
shutil.copytree(
7998
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")),
81100
dirs_exist_ok=True
82101
)
83102
shutil.copytree(
84103
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")),
86105
dirs_exist_ok=True
87106
)

0 commit comments

Comments
 (0)