windows_dll_manager.py
Go to the documentation of this file.
1 import contextlib
2 import os
3 
4 
6  eigenpy_paths = os.getenv("EIGENPY_WINDOWS_DLL_PATH")
7  if eigenpy_paths is None:
8  # From https://peps.python.org/pep-0250/#implementation
9  # lib/python-version/site-packages/package
10  RELATIVE_DLL_PATH1 = "..\\..\\..\\..\\bin"
11  # lib/site-packages/package
12  RELATIVE_DLL_PATH2 = "..\\..\\..\\bin"
13  # For unit test
14  RELATIVE_DLL_PATH3 = "..\\..\\bin"
15  return [
16  os.path.join(os.path.dirname(__file__), RELATIVE_DLL_PATH1),
17  os.path.join(os.path.dirname(__file__), RELATIVE_DLL_PATH2),
18  os.path.join(os.path.dirname(__file__), RELATIVE_DLL_PATH3),
19  ]
20  else:
21  return eigenpy_paths.split(os.pathsep)
22 
23 
24 class DllDirectoryManager(contextlib.AbstractContextManager):
25  """Restore DllDirectory state after importing Python module"""
26 
27  def add_dll_directory(self, dll_dir: str):
28  # add_dll_directory can fail on relative path and non
29  # existing path.
30  # Since we don't know all the fail criterion we just ignore
31  # thrown exception
32  try:
33  self.dll_dirs.append(os.add_dll_directory(dll_dir))
34  except OSError:
35  pass
36 
37  def __enter__(self):
38  self.dll_dirs = []
39  return self
40 
41  def __exit__(self, *exc_details):
42  for d in self.dll_dirs:
43  d.close()
44 
45 
47  return DllDirectoryManager()
eigenpy.windows_dll_manager.DllDirectoryManager
Definition: windows_dll_manager.py:24
eigenpy.windows_dll_manager.DllDirectoryManager.__enter__
def __enter__(self)
Definition: windows_dll_manager.py:37
eigenpy.windows_dll_manager.build_directory_manager
def build_directory_manager()
Definition: windows_dll_manager.py:46
eigenpy.windows_dll_manager.DllDirectoryManager.add_dll_directory
def add_dll_directory(self, str dll_dir)
Definition: windows_dll_manager.py:27
eigenpy.windows_dll_manager.DllDirectoryManager.dll_dirs
dll_dirs
Definition: windows_dll_manager.py:38
eigenpy.windows_dll_manager.get_dll_paths
def get_dll_paths()
Definition: windows_dll_manager.py:5
eigenpy.windows_dll_manager.DllDirectoryManager.__exit__
def __exit__(self, *exc_details)
Definition: windows_dll_manager.py:41


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45