|
23 | 23 | from os.path import join as pjoin |
24 | 24 | import re |
25 | 25 | import shlex |
| 26 | +import shutil |
26 | 27 | import sys |
27 | 28 | import warnings |
28 | 29 |
|
@@ -119,8 +120,37 @@ def build_extensions(self): |
119 | 120 |
|
120 | 121 | def run(self): |
121 | 122 | self._run_cmake() |
| 123 | + self._copy_stubs() |
122 | 124 | _build_ext.run(self) |
123 | 125 |
|
| 126 | + def _copy_stubs(self): |
| 127 | + """Copy .pyi stub files from pyarrow-stubs to the build directory.""" |
| 128 | + build_cmd = self.get_finalized_command('build') |
| 129 | + build_lib = os.path.abspath(build_cmd.build_lib) |
| 130 | + |
| 131 | + stubs_src = pjoin(setup_dir, 'pyarrow-stubs', 'pyarrow') |
| 132 | + stubs_dest = pjoin(build_lib, 'pyarrow') |
| 133 | + |
| 134 | + if os.path.exists(stubs_src): |
| 135 | + print(f"-- Copying stub files from {stubs_src} to {stubs_dest}") |
| 136 | + for root, dirs, files in os.walk(stubs_src): |
| 137 | + # Calculate relative path from stubs_src |
| 138 | + rel_dir = os.path.relpath(root, stubs_src) |
| 139 | + dest_dir = pjoin(stubs_dest, rel_dir) if rel_dir != '.' else stubs_dest |
| 140 | + |
| 141 | + # Create destination directory if needed |
| 142 | + if not os.path.exists(dest_dir): |
| 143 | + os.makedirs(dest_dir) |
| 144 | + |
| 145 | + # Copy .pyi files |
| 146 | + for file in files: |
| 147 | + if file.endswith('.pyi'): |
| 148 | + src_file = pjoin(root, file) |
| 149 | + dest_file = pjoin(dest_dir, file) |
| 150 | + shutil.copy2(src_file, dest_file) |
| 151 | + print(f" Copied {file} to {os.path.relpath(dest_file, build_lib)}") |
| 152 | + |
| 153 | + |
124 | 154 | # adapted from cmake_build_ext in dynd-python |
125 | 155 | # github.com/libdynd/dynd-python |
126 | 156 |
|
|
0 commit comments