Skip to content

Commit cda713a

Browse files
author
Denis Jelovina
committed
Merge branch '358-python-api-metadata'
1 parent f58c94d commit cda713a

File tree

12 files changed

+145
-84
lines changed

12 files changed

+145
-84
lines changed

.github/workflows/pyalp-publish.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ jobs:
8585
# Use a per-ABI build directory to avoid cross-ABI contamination
8686
ABI_TAG=$(python -c 'import sys; print(f"cp{sys.version_info[0]}{sys.version_info[1]}")')
8787
BUILD_DIR="build/${ABI_TAG}"
88+
# Export the per-ABI build dir so setup.py (inside the wheel build) can find
89+
# the CMake-generated metadata file. cibuildwheel runs this before_build
90+
# inside the container and environment variables exported here are visible
91+
# to the subsequent packaging steps in that container.
92+
export CMAKE_BUILD_DIR="${BUILD_DIR}"
93+
echo "[cibw] Exported CMAKE_BUILD_DIR=${CMAKE_BUILD_DIR}"
8894
# Enable NUMA on Linux runners (for linux wheels), keep disabled elsewhere.
8995
if [ "$(uname -s)" = "Linux" ];
9096
then
@@ -148,6 +154,14 @@ jobs:
148154
LTO_FLAG="-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF"
149155
cmake -S . -B "${BUILD_DIR}" -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_PYALP=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_FIND_FRAMEWORK=NEVER ${MACOS_FLAGS} ${NUMA_FLAG} ${CMAKE_PREFIX_HINT:-} ${OSX_DEPLOY_FLAG:-} ${PORTABLE_FLAG} ${LTO_FLAG} -DPython3_EXECUTABLE="${PYEXEC}"
150156
cmake --build "${BUILD_DIR}" --target pyalp_ref --parallel
157+
# Debug: show the generated metadata file (if present) to the CI logs
158+
echo "[cibw] Checking for generated metadata file: ${CMAKE_BUILD_DIR}/pyalp_metadata.py"
159+
if [ -f "${CMAKE_BUILD_DIR}/pyalp_metadata.py" ]; then
160+
echo "[cibw] Found metadata file:"; ls -l "${CMAKE_BUILD_DIR}/pyalp_metadata.py"
161+
echo "[cibw] First 100 lines of metadata:"; sed -n '1,100p' "${CMAKE_BUILD_DIR}/pyalp_metadata.py" || true
162+
else
163+
echo "[cibw] Metadata file not found at ${CMAKE_BUILD_DIR}/pyalp_metadata.py"
164+
fi
151165
run: |
152166
# Build from repository root so the full CMake project is available in the container
153167
python -m cibuildwheel --output-dir wheelhouse .

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ paths.mk
99
[Oo]bj*/
1010
[Ii]nstall*/
1111
cmake-build-*/
12-
.venv/
12+
.venv/
13+
pyalp/src/pyalp.egg-info/

pyalp/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pyalp"
7-
version = "0.0.0"
7+
version = "0.8.1"
88
description = "Python bindings for ALP GraphBLAS (minimal package layout)"
99
authors = [ { name = "ALP" } ]
1010
readme = "README.md"

pyalp/setup.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
import shutil
88
import sysconfig
9+
import pathlib
910
bdist_wheel_cmd = None
1011
try:
1112
# Used to mark wheel as non-pure when bundling a prebuilt .so
@@ -66,6 +67,38 @@ def build_extension(self, ext):
6667
raise RuntimeError("Prebuilt pyalp shared object not found during build_ext")
6768
shutil.copyfile(src, target_path)
6869

70+
# The _metadata.py file is generated by CMake in the build directory.
71+
# We need to find it and copy it to the same directory as the extension.
72+
ext_build_dir = os.path.dirname(target_path)
73+
# CMAKE_BUILD_DIR is set by the cibuildwheel before_build script to the per-ABI build directory
74+
cmake_build_dir = os.environ.get("CMAKE_BUILD_DIR")
75+
if cmake_build_dir:
76+
metadata_src_path = os.path.join(cmake_build_dir, "pyalp_metadata.py")
77+
metadata_dest_path = os.path.join(ext_build_dir, "_metadata.py")
78+
if os.path.exists(metadata_src_path):
79+
print(f"Copying generated metadata from {metadata_src_path} to {metadata_dest_path}")
80+
shutil.copyfile(metadata_src_path, metadata_dest_path)
81+
else:
82+
print(f"Warning: Generated metadata file not found at {metadata_src_path}. Skipping copy.")
83+
else:
84+
# Fall back: try to locate the generated metadata under any per-ABI
85+
# build directory (e.g. ../build/cp310, ../build/cp39, ...).
86+
# This avoids relying strictly on the CMAKE_BUILD_DIR env var which
87+
# may not always be propagated into the isolated build environment.
88+
search_pattern = os.path.join(here, '..', 'build', '**', 'pyalp_metadata.py')
89+
candidates = glob.glob(search_pattern, recursive=True)
90+
# Prefer candidate matching the current Python ABI tag if present
91+
py_tag = f"cp{sys.version_info[0]}{sys.version_info[1]}"
92+
matching = [c for c in candidates if py_tag in os.path.basename(os.path.dirname(c)) or py_tag in os.path.basename(c)]
93+
chosen = (matching or candidates)[:1]
94+
if chosen:
95+
metadata_src_path = os.path.abspath(chosen[0])
96+
metadata_dest_path = os.path.join(ext_build_dir, "_metadata.py")
97+
print(f"Copying generated metadata from {metadata_src_path} to {metadata_dest_path} (discovered by glob search)")
98+
shutil.copyfile(metadata_src_path, metadata_dest_path)
99+
else:
100+
print("Warning: CMAKE_BUILD_DIR not set and no generated metadata found under ../build. Skipping metadata file copy.")
101+
69102
if prebuilt_so:
70103
if not os.path.exists(prebuilt_so):
71104
raise FileNotFoundError(f"PREBUILT_PYALP_SO set but file not found: {prebuilt_so}")
@@ -92,10 +125,13 @@ def build_extension(self, ext):
92125

93126
setup_kwargs = {
94127
"name": "pyalp",
95-
"version": "0.0.0",
128+
"version": "0.8.1",
96129
"description": "pyalp package (C++ bindings)",
97130
"packages": find_packages(where="src"),
98131
"package_dir": {"": "src"},
132+
# Ensure generated metadata is included in the wheel. The build process
133+
# will copy the generated file to the package build dir as `_metadata.py`.
134+
"package_data": {"pyalp": ["_metadata.py"]},
99135
"ext_modules": ext_modules,
100136
"include_package_data": True,
101137
}

pyalp/src/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,43 @@ if( WITH_NONBLOCKING_BACKEND )
109109

110110
endif()
111111

112+
# --- Metadata generation ---
113+
# These variables are expected to be set by the top-level CMakeLists.txt,
114+
# but we provide defaults for standalone builds.
115+
if(NOT DEFINED pyalp_VERSION)
116+
set(pyalp_VERSION "0.0.0")
117+
endif()
118+
if(NOT DEFINED ALP_VERSION)
119+
set(ALP_VERSION "unknown")
120+
endif()
121+
if(NOT DEFINED ALP_BUILD_TYPE)
122+
set(ALP_BUILD_TYPE "unknown")
123+
endif()
124+
if(NOT DEFINED ALP_GIT_COMMIT_SHA)
125+
set(ALP_GIT_COMMIT_SHA "unknown")
126+
endif()
127+
if(NOT DEFINED ALP_GIT_BRANCH)
128+
set(ALP_GIT_BRANCH "unknown")
129+
endif()
130+
131+
# Get Python and pybind11 versions
132+
find_package(PythonInterp REQUIRED)
133+
set(PYTHON_VERSION ${PYTHON_VERSION_STRING})
134+
set(pybind11_VERSION ${pybind11_VERSION})
135+
136+
# This is a simplified list. A more robust solution would inspect the build targets.
137+
set(pyalp_ALGORITHMS "conjugate_gradient")
138+
set(pyalp_BACKENDS "reference, reference_omp")
139+
140+
# Configure the metadata file from the template
141+
set(METADATA_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/pyalp/_metadata.py.in")
142+
set(METADATA_OUTPUT "${CMAKE_BINARY_DIR}/pyalp_metadata.py")
143+
configure_file(${METADATA_TEMPLATE} ${METADATA_OUTPUT} @ONLY)
144+
145+
# This command is useful for debugging inside a cibuildwheel container
146+
# to verify that the file is being generated correctly.
147+
# add_custom_command(TARGET ${PYALP_MODULE_NAME} POST_BUILD
148+
# COMMAND ${CMAKE_COMMAND} -E echo "Generated metadata file content:"
149+
# COMMAND ${CMAKE_COMMAND} -E cat ${METADATA_OUTPUT}
150+
# )
151+

pyalp/src/pyalp.egg-info/PKG-INFO

Lines changed: 0 additions & 65 deletions
This file was deleted.

pyalp/src/pyalp.egg-info/SOURCES.txt

Lines changed: 0 additions & 12 deletions
This file was deleted.

pyalp/src/pyalp.egg-info/dependency_links.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

pyalp/src/pyalp.egg-info/requires.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

pyalp/src/pyalp.egg-info/top_level.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)