File tree 2 files changed +22
-10
lines changed
2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -33,15 +33,13 @@ def linked_libpython():
33
33
"""
34
34
Find the linked libpython using dladdr (in *nix).
35
35
36
- Calling this in Windows always return `None` at the moment.
37
-
38
36
Returns
39
37
-------
40
38
path : str or None
41
39
A path to linked libpython. Return `None` if statically linked.
42
40
"""
43
41
if is_windows :
44
- return None
42
+ return _linked_libpython_windows ()
45
43
return _linked_libpython_unix ()
46
44
47
45
@@ -71,6 +69,26 @@ def _linked_libpython_unix():
71
69
return path
72
70
73
71
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
+
74
92
def library_name (name , suffix = SHLIB_SUFFIX , is_windows = is_windows ):
75
93
"""
76
94
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
-
5
1
from julia .find_libpython import finding_libpython , linked_libpython
6
2
from julia .core import determine_if_statically_linked
7
3
@@ -18,8 +14,6 @@ def test_finding_libpython_yield_type():
18
14
# let's just check returned type of finding_libpython.
19
15
20
16
21
- @pytest .mark .xfail (platform .system () == "Windows" ,
22
- reason = "linked_libpython is not implemented for Windows" )
23
17
def test_linked_libpython ():
24
- if determine_if_statically_linked ():
18
+ if not determine_if_statically_linked ():
25
19
assert linked_libpython () is not None
You can’t perform that action at this time.
0 commit comments