windows_dll_manager.py
Go to the documentation of this file.
1 import os
2 import sys
3 import contextlib
4 
5 
7  pinocchio_paths = os.getenv("PINOCCHIO_WINDOWS_DLL_PATH")
8  if pinocchio_paths is None:
9  # Standard site-packages to bin path
10  RELATIVE_DLL_PATH = "..\\..\\..\\bin"
11  return [os.path.join(os.path.dirname(__file__), RELATIVE_DLL_PATH)]
12  else:
13  return pinocchio_paths.split(os.pathsep)
14 
15 
16 class PathManager(contextlib.AbstractContextManager):
17  """Restore PATH state after importing Python module"""
18 
19  def add_dll_directory(self, dll_dir: str):
20  os.environ["PATH"] += os.pathsep + dll_dir
21 
22  def __enter__(self):
23  self.old_path = os.environ["PATH"]
24  return self
25 
26  def __exit__(self, *exc_details):
27  os.environ["PATH"] = self.old_path
28 
29 
30 class DllDirectoryManager(contextlib.AbstractContextManager):
31  """Restore DllDirectory state after importing Python module"""
32 
33  def add_dll_directory(self, dll_dir: str):
34  # add_dll_directory can fail on relative path and non
35  # existing path.
36  # Since we don't know all the fail criterion we just ignore
37  # thrown exception
38  try:
39  self.dll_dirs.append(os.add_dll_directory(dll_dir))
40  except OSError:
41  pass
42 
43  def __enter__(self):
44  self.dll_dirs = []
45  return self
46 
47  def __exit__(self, *exc_details):
48  for d in self.dll_dirs:
49  d.close()
50 
51 
53  if sys.version_info >= (3, 8):
54  return DllDirectoryManager()
55  else:
56  return PathManager()
pinocchio.windows_dll_manager.DllDirectoryManager.dll_dirs
dll_dirs
Definition: windows_dll_manager.py:44
pinocchio.windows_dll_manager.DllDirectoryManager.__exit__
def __exit__(self, *exc_details)
Definition: windows_dll_manager.py:47
pinocchio.windows_dll_manager.build_directory_manager
def build_directory_manager()
Definition: windows_dll_manager.py:52
pinocchio.windows_dll_manager.PathManager.old_path
old_path
Definition: windows_dll_manager.py:23
pinocchio.windows_dll_manager.PathManager.__enter__
def __enter__(self)
Definition: windows_dll_manager.py:22
pinocchio.windows_dll_manager.get_dll_paths
def get_dll_paths()
Definition: windows_dll_manager.py:6
pinocchio.windows_dll_manager.PathManager.__exit__
def __exit__(self, *exc_details)
Definition: windows_dll_manager.py:26
pinocchio.windows_dll_manager.DllDirectoryManager.__enter__
def __enter__(self)
Definition: windows_dll_manager.py:43
pinocchio.windows_dll_manager.DllDirectoryManager.add_dll_directory
def add_dll_directory(self, str dll_dir)
Definition: windows_dll_manager.py:33
pinocchio.windows_dll_manager.PathManager
Definition: windows_dll_manager.py:16
boost::fusion::append
result_of::push_front< V const, T >::type append(T const &t, V const &v)
Append the element T at the front of boost fusion vector V.
Definition: fusion.hpp:32
pinocchio.windows_dll_manager.PathManager.add_dll_directory
def add_dll_directory(self, str dll_dir)
Definition: windows_dll_manager.py:19
pinocchio.windows_dll_manager.DllDirectoryManager
Definition: windows_dll_manager.py:30


pinocchio
Author(s):
autogenerated on Sat Jun 1 2024 02:40:39