Skip to content

Commit

Permalink
Add _linked_libpython_windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Oct 24, 2018
1 parent 47f4a06 commit cd2e408
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 21 additions & 3 deletions julia/find_libpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ def linked_libpython():
"""
Find the linked libpython using dladdr (in *nix).
Calling this in Windows always return `None` at the moment.
Returns
-------
path : str or None
A path to linked libpython. Return `None` if statically linked.
"""
if is_windows:
return None
return _linked_libpython_windows()
return _linked_libpython_unix()


Expand Down Expand Up @@ -71,6 +69,26 @@ def _linked_libpython_unix():
return path


def _linked_libpython_windows():
"""
Based on: https://stackoverflow.com/a/16659821
"""
from ctypes.wintypes import HANDLE, LPWSTR, DWORD

GetModuleFileName = ctypes.windll.kernel32.GetModuleFileNameW
GetModuleFileName.argtypes = [HANDLE, LPWSTR, DWORD]
GetModuleFileName.restype = DWORD

MAX_PATH = 260
try:
buf = ctypes.create_unicode_buffer(MAX_PATH)
GetModuleFileName(ctypes.pythonapi._handle, buf, MAX_PATH)
return buf.value
except (ValueError, OSError):
return None



def library_name(name, suffix=SHLIB_SUFFIX, is_windows=is_windows):
"""
Convert a file basename `name` to a library name (no "lib" and ".so" etc.)
Expand Down
8 changes: 1 addition & 7 deletions test/test_find_libpython.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import platform

import pytest

from julia.find_libpython import finding_libpython, linked_libpython
from julia.core import determine_if_statically_linked

Expand All @@ -18,8 +14,6 @@ def test_finding_libpython_yield_type():
# let's just check returned type of finding_libpython.


@pytest.mark.xfail(platform.system() == "Windows",
reason="linked_libpython is not implemented for Windows")
def test_linked_libpython():
if determine_if_statically_linked():
if not determine_if_statically_linked():
assert linked_libpython() is not None

0 comments on commit cd2e408

Please sign in to comment.