66import glob
77import shutil
88import sysconfig
9+ import pathlib
910bdist_wheel_cmd = None
1011try :
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+
69102if 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
93126setup_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}
0 commit comments