Minor refactoring and cleanup.
@@ -123,12 +123,12 @@ class LibraryLoader:
if _is_pyglet_doc_run:
return LibraryMock()
- if 'framework' in kwargs and self.platform == 'darwin':
- return self.load_framework(kwargs['framework'])
-
if not names:
raise ImportError("No library name specified")
+ if 'framework' in kwargs and self.platform == 'darwin':
+ return self.load_framework(kwargs['framework'])
+
platform_names = kwargs.get(self.platform, [])
if isinstance(platform_names, str):
platform_names = [platform_names]
@@ -225,10 +225,10 @@ class MachOLibraryLoader(LibraryLoader):
search_path.append(os.path.join(os.environ['CONDA_PREFIX'], 'lib', libname))
# pyinstaller.py sets sys.frozen to True, and puts dylibs in
- # Contents/MacOS, which path pyinstaller puts in sys._MEIPASS
- if (hasattr(sys, 'frozen') and hasattr(sys, '_MEIPASS') and
- sys.frozen is True and pyglet.compat_platform == 'darwin'):
- search_path.append(os.path.join(sys._MEIPASS, libname))
+ # Contents/macOS, which path pyinstaller puts in sys._MEIPASS
+ if getattr(sys, 'frozen', False) and getattr(sys, '_MEIPASS', None):
+ meipass = getattr(sys, '_MEIPASS')
+ search_path.append(os.path.join(meipass, libname))
# conda support
if os.environ.get('CONDA_PREFIX', False):
@@ -316,7 +316,7 @@ class LinuxLibraryLoader(LibraryLoader):
try:
with open('/etc/ld.so.conf') as fid:
- directories.extend([dir.strip() for dir in fid])
+ directories.extend([directory.strip() for directory in fid])
except IOError:
pass
@@ -354,4 +354,5 @@ elif pyglet.compat_platform.startswith('linux'):
loader = LinuxLibraryLoader()
else:
loader = LibraryLoader()
+
load_library = loader.load_library
