Skip to content

Commit c73c25f

Browse files
rgommersdnicolodi
andauthored
WIP: apply suggestions from code review
Co-authored-by: Daniele Nicolodi <[email protected]>
1 parent e577eac commit c73c25f

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

docs/how-to-guides/shared-libraries.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ the lack of RPATH support:
9292

9393
If an internal shared library is not only used as part of a Python package, but
9494
for example also as a regular shared library in a C/C++ project or as a
95-
standalone library, then the method shown above won't work. The library is`
95+
standalone library, then the method shown above won't work. The library is
9696
then marked for installation into the system default ``libdir`` location.
9797
Actually installing into ``libdir`` isn't possible with wheels, hence
9898
``meson-python`` will instead do the following *on platforms other than
@@ -125,7 +125,7 @@ RPATH entry - and Meson will not automatically manage RPATH entries for you.
125125
Hence you'll need to add the needed RPATH yourself, for example by adding
126126
``-Wl,rpath=/path/to/dir/sharedlib/is/in`` to ``LDFLAGS`` before starting
127127
the build. In case you run into this problem after a wheel is built and
128-
installed, adding that same path to ``LD_LIBRARY_PATH`` is a quick way of
128+
installed, adding that same path to the ``LD_LIBRARY_PATH`` environment variable is a quick way of
129129
checking if that is indeed the problem.
130130

131131
On Windows, the solution is similar - the shared library can either be

tests/packages/sharedlib-in-package/mypkg/__init__.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,28 @@
99
# start-literalinclude
1010
def _enable_sharedlib_loading():
1111
"""
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.
2727
2828
.. note::
2929
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.
3534
"""
3635
basedir = os.path.dirname(__file__)
3736
subdir = os.path.join(basedir, 'sub')

0 commit comments

Comments
 (0)