File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,13 @@ def linked_libpython():
3333 """
3434 Find the linked libpython using dladdr (in *nix).
3535
36- Calling this in Windows always return `None` at the moment.
37-
3836 Returns
3937 -------
4038 path : str or None
4139 A path to linked libpython. Return `None` if statically linked.
4240 """
4341 if is_windows :
44- return None
42+ return _linked_libpython_windows ()
4543 return _linked_libpython_unix ()
4644
4745
@@ -71,6 +69,26 @@ def _linked_libpython_unix():
7169 return path
7270
7371
72+ def _linked_libpython_windows ():
73+ """
74+ Based on: https://stackoverflow.com/a/16659821
75+ """
76+ from ctypes .wintypes import HANDLE , LPWSTR , DWORD
77+
78+ GetModuleFileName = ctypes .windll .kernel32 .GetModuleFileNameW
79+ GetModuleFileName .argtypes = [HANDLE , LPWSTR , DWORD ]
80+ GetModuleFileName .restype = DWORD
81+
82+ MAX_PATH = 260
83+ try :
84+ buf = ctypes .create_unicode_buffer (MAX_PATH )
85+ GetModuleFileName (ctypes .pythonapi ._handle , buf , MAX_PATH )
86+ return buf .value
87+ except (ValueError , OSError ):
88+ return None
89+
90+
91+
7492def library_name (name , suffix = SHLIB_SUFFIX , is_windows = is_windows ):
7593 """
7694 Convert a file basename `name` to a library name (no "lib" and ".so" etc.)
Original file line number Diff line number Diff line change 1- import platform
2-
3- import pytest
4-
51from julia .find_libpython import finding_libpython , linked_libpython
62from julia .core import determine_if_statically_linked
73
@@ -18,8 +14,6 @@ def test_finding_libpython_yield_type():
1814# let's just check returned type of finding_libpython.
1915
2016
21- @pytest .mark .xfail (platform .system () == "Windows" ,
22- reason = "linked_libpython is not implemented for Windows" )
2317def test_linked_libpython ():
24- if determine_if_statically_linked ():
18+ if not determine_if_statically_linked ():
2519 assert linked_libpython () is not None
You can’t perform that action at this time.
0 commit comments