|
9 | 9 | # start-literalinclude |
10 | 10 | def _enable_sharedlib_loading(): |
11 | 11 | """ |
12 | | - Ensure the shared libraries in this dir and the ``sub`` subdir can be |
13 | | - loaded on Windows. |
14 | | -
|
15 | | - One shared library is installed alongside this ``__init__.py`` file. |
16 | | - Windows can load it because it searches for DLLs in the directory where a |
17 | | - ``.pyd`` (Python extension module) is located in. Cygwin does not though. |
18 | | - For a shared library in another directory inside the package, Windows also |
19 | | - needs a hint. |
20 | | -
|
21 | | - This function is Windows-specific due to lack of RPATH support on Windows. |
22 | | - It cannot find shared libraries installed within wheels unless we either |
23 | | - amend the DLL search path or pre-load the DLL. |
24 | | -
|
25 | | - Note that ``delvewheel`` inserts a similar snippet into the main |
26 | | - ``__init__.py`` of a package when it vendors external shared libraries. |
| 12 | + Ensure the shared libraries in this package loaded on Windows. |
| 13 | + |
| 14 | + Windows lacks a concept equivalent to RPATH: Python extension modules cannot |
| 15 | + find DLLs installed outside the DLL search path. This function ensured that the |
| 16 | + location of the shared libraries distributed with this Python wheel is in the DLL |
| 17 | + search path of the process. |
| 18 | + |
| 19 | + The Windows DLL search path includes the object depending on it is located: |
| 20 | + the DLL search path needs to be augmented only when the Python extension |
| 21 | + modules and the DLLs they require are installed in separate directories. |
| 22 | + Cygwin does not have the same default library search path: all locations where |
| 23 | + the shared libraries are installed need to be added to the search path. |
| 24 | +
|
| 25 | + This function is very similar to the snippet inserted into the main ``__init__.py`` |
| 26 | + of a package by ``delvewheel`` when it vendors external shared libraries. |
27 | 27 |
|
28 | 28 | .. note:: |
29 | 29 |
|
30 | | - `os.add_dll_directory` is only available for Python >=3.8, and with |
31 | | - the Conda ``python`` packages only works as advertised for >=3.10. |
32 | | - If you require support for older versions, pre-loading the DLL |
33 | | - with `ctypes.WinDLL` may be preferred (the SciPy code base has an |
34 | | - example of this). |
| 30 | + `os.add_dll_directory` is only available for Python 3.8 and later, and in |
| 31 | + the Conda ``python`` packages it works as advertised only for version |
| 32 | + 3.10 and later. For older Python versions, pre-loading the DLLs with |
| 33 | + `ctypes.WinDLL` may be preferred. |
35 | 34 | """ |
36 | 35 | basedir = os.path.dirname(__file__) |
37 | 36 | subdir = os.path.join(basedir, 'sub') |
|
0 commit comments