From 8ea3773aed2a2c6d6c4a32b690cae5396319e01e Mon Sep 17 00:00:00 2001 From: Sumanth Ratna Date: Tue, 30 Jun 2020 22:14:39 -0400 Subject: [PATCH 1/3] Close Issue41179 https://bugs.python.org/issue41179 --- Lib/ctypes/util.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index 01176bf9696577..bb30cf40f14c11 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -1,4 +1,5 @@ import os +import platform import shutil import subprocess import sys @@ -70,15 +71,22 @@ def find_library(name): elif os.name == "posix" and sys.platform == "darwin": from ctypes.macholib.dyld import dyld_find as _dyld_find def find_library(name): - possible = ['lib%s.dylib' % name, - '%s.dylib' % name, - '%s.framework/%s' % (name, name)] - for name in possible: - try: - return _dyld_find(name) - except ValueError: - continue - return None + macos_version = platform.mac_ver()[0] + if macos_version == '10.16' or macos_version == '11.0': + # see https://bugs.python.org/issue41179 + # macOS Big Sur no longer copies dynamic libraries + # TODO (@sumanthratna): maybe look in /System/Library/Frameworks/ + pass + else: + possible = ['lib%s.dylib' % name, + '%s.dylib' % name, + '%s.framework/%s' % (name, name)] + for name in possible: + try: + return _dyld_find(name) + except ValueError: + continue + return None elif sys.platform.startswith("aix"): # AIX has two styles of storing shared libraries From 0a2ee77547c0e25f081cfb6507a1ab8fecbd683a Mon Sep 17 00:00:00 2001 From: Sumanth Ratna Date: Tue, 30 Jun 2020 22:28:11 -0400 Subject: [PATCH 2/3] Only import platform if OS is macOS --- Lib/ctypes/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index bb30cf40f14c11..a5d133d9d4d120 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -1,5 +1,4 @@ import os -import platform import shutil import subprocess import sys @@ -71,7 +70,8 @@ def find_library(name): elif os.name == "posix" and sys.platform == "darwin": from ctypes.macholib.dyld import dyld_find as _dyld_find def find_library(name): - macos_version = platform.mac_ver()[0] + from platform import mac_ver + macos_version = mac_ver()[0] if macos_version == '10.16' or macos_version == '11.0': # see https://bugs.python.org/issue41179 # macOS Big Sur no longer copies dynamic libraries From 24960b89cad59f1837bbddc8bf6584463d557be5 Mon Sep 17 00:00:00 2001 From: Sumanth Ratna Date: Tue, 30 Jun 2020 22:34:46 -0400 Subject: [PATCH 3/3] Update TODO --- Lib/ctypes/util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py index a5d133d9d4d120..ca90f97600e640 100644 --- a/Lib/ctypes/util.py +++ b/Lib/ctypes/util.py @@ -75,7 +75,9 @@ def find_library(name): if macos_version == '10.16' or macos_version == '11.0': # see https://bugs.python.org/issue41179 # macOS Big Sur no longer copies dynamic libraries - # TODO (@sumanthratna): maybe look in /System/Library/Frameworks/ + # TODO (@sumanthratna): we shouldn't change this logic + # https://github.com/python/cpython/blob/0a2ee77547c0e25f081cfb6507a1ab8fecbd683a/Lib/ctypes/macholib/dyld.py#L15-L29 + # this probably requires a change to ctypes.macholib.dyld.dyld_find pass else: possible = ['lib%s.dylib' % name,