Skip to content

Commit ccaf24e

Browse files
committed
Configure how to patch the windows files
Signed-off-by: Cristian Le <[email protected]>
1 parent b4652c5 commit ccaf24e

File tree

5 files changed

+71
-14
lines changed

5 files changed

+71
-14
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ wheel.repair.cross-wheel = false
232232
# A list of external library files that will be bundled in the wheel.
233233
wheel.repair.bundle-external = []
234234

235+
# Automatically patch every top-level packages/modules to import the dlls on Windows wheels.
236+
wheel.repair.patch-imports = true
237+
238+
# The generated file containing any necessary top-level imports.
239+
wheel.repair.imports-file = ""
240+
235241
# If CMake is less than this value, backport a copy of FindPython.
236242
backport.find-python = "3.26.1"
237243

docs/reference/configs.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,18 @@ print(mk_skbuild_docs())
611611
This is an experimental feature gated by :confval:`experimental`
612612
```
613613

614+
```{eval-rst}
615+
.. confval:: wheel.repair.imports-file
616+
:type: ``Path``
617+
618+
The generated file containing any necessary top-level imports.
619+
620+
This files should be imported as early as possible in all top-level modules and packages.
621+
622+
On Windows wheels, this file contains all ``os.add_dll_directory`` needed in the current wheel.
623+
On other OS, this is an empty file.
624+
```
625+
614626
```{eval-rst}
615627
.. confval:: wheel.repair.in-wheel
616628
:type: ``bool``
@@ -619,4 +631,14 @@ print(mk_skbuild_docs())
619631
Patch the dynamic links to libraries installed in the current wheel.
620632
```
621633

634+
```{eval-rst}
635+
.. confval:: wheel.repair.patch-imports
636+
:type: ``bool``
637+
:default: true
638+
639+
Automatically patch every top-level packages/modules to import the dlls on Windows wheels.
640+
641+
Alternatively, set this to ``false`` and use :confval:`wheel.repair.imports-file` instead.
642+
```
643+
622644
<!-- [[[end]]] -->

src/scikit_build_core/repair_wheel/windows.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,20 @@ def repair_wheel(self) -> None:
280280
"Patching dll directories: {dll_dirs}",
281281
dll_dirs=self.dll_dirs,
282282
)
283-
# TODO: Not handling namespace packages with this
284-
for path in platlib.iterdir():
285-
assert isinstance(path, Path)
286-
if path.is_dir():
287-
pkg_file = path / "__init__.py"
288-
if not pkg_file.exists():
289-
logger.debug(
290-
"Ignoring non-python package: {pkg_file}",
291-
pkg_file=pkg_file,
292-
)
293-
continue
294-
self.patch_python_file(pkg_file)
295-
elif path.suffix == ".py":
296-
self.patch_python_file(path)
283+
if self.settings.wheel.repair.imports_file:
284+
imports_file = platlib / self.settings.wheel.repair.imports_file
285+
self.patch_python_file(imports_file)
286+
else:
287+
for path in platlib.iterdir():
288+
assert isinstance(path, Path)
289+
if path.is_dir():
290+
pkg_file = path / "__init__.py"
291+
if not pkg_file.exists():
292+
logger.debug(
293+
"Ignoring non-python package: {pkg_file}",
294+
pkg_file=pkg_file,
295+
)
296+
continue
297+
self.patch_python_file(pkg_file)
298+
elif path.suffix == ".py":
299+
self.patch_python_file(path)

src/scikit_build_core/resources/scikit-build.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@
265265
"type": "string"
266266
},
267267
"description": "A list of external library files that will be bundled in the wheel."
268+
},
269+
"patch-imports": {
270+
"type": "boolean",
271+
"default": true,
272+
"description": "Automatically patch every top-level packages/modules to import the dlls on Windows wheels."
273+
},
274+
"imports-file": {
275+
"type": "string",
276+
"description": "The generated file containing any necessary top-level imports."
268277
}
269278
},
270279
"description": "Wheel repair options"

src/scikit_build_core/settings/skbuild_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,23 @@ class WheelRepair:
256256
build. The bundled libraries are installed under ``site-packages/${name}.libs``
257257
"""
258258

259+
patch_imports: bool = True
260+
"""
261+
Automatically patch every top-level packages/modules to import the dlls on Windows wheels.
262+
263+
Alternatively, set this to ``false`` and use :confval:`wheel.repair.imports-file` instead.
264+
"""
265+
266+
imports_file: Optional[Path] = None
267+
"""
268+
The generated file containing any necessary top-level imports.
269+
270+
This files should be imported as early as possible in all top-level modules and packages.
271+
272+
On Windows wheels, this file contains all ``os.add_dll_directory`` needed in the current wheel.
273+
On other OS, this is an empty file.
274+
"""
275+
259276

260277
@dataclasses.dataclass
261278
class WheelSettings:

0 commit comments

Comments
 (0)