Skip to content

Commit

Permalink
Add __get_library_path function
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacarniato committed Aug 24, 2023
1 parent 3725873 commit ce7946b
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions ugrid/ugrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,29 @@ def __init__(self, file_path, method):
OSError: This gets raised in case UGrid is used within an unsupported OS.
"""

# Determine OS
lib_path = self.__get_library_path()
self.lib = CDLL(str(lib_path))
self.__open(file_path, method)

def __enter__(self):
return self

def __get_library_path(self):
"""Gets the library path
Raises:
OSError: This gets raised in case UGrid is used within an unsupported OS.
"""
system = platform.system()
lib_path = Path(__file__).parent
if system == "Windows":
lib_path = os.path.join(lib_path, "UGridApi.dll")
elif system == "Linux":
lib_path = os.path.join(lib_path, "UGridApi.so")
elif system == "Darwin":
lib_path = os.path.join(lib_path, "UGridApi.dylib")
else:
if not system:
system = "Unknown OS"
raise OSError(f"Unsupported operating system: {system}")

self.lib = CDLL(str(lib_path))
self.__open(file_path, method)

def __enter__(self):
return self
return lib_path

def __exit__(self, type, value, traceback):
self.__execute_function(self.lib.ug_file_close, self._file_id)
Expand Down

0 comments on commit ce7946b

Please sign in to comment.