Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow config_file to be a path-like object #128

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions xmipy/xmiwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
create_string_buffer,
)
from enum import Enum, IntEnum, unique
from os import PathLike
from pathlib import Path
from typing import Any, Callable, Tuple, Union

Expand Down Expand Up @@ -43,9 +44,9 @@ class XmiWrapper(Xmi):

def __init__(
self,
lib_path: Union[str, Path],
lib_dependency: Union[str, Path, None] = None,
working_directory: Union[str, Path, None] = None,
lib_path: Union[str, PathLike[Any]],
lib_dependency: Union[str, PathLike[Any], None] = None,
working_directory: Union[str, PathLike[Any], None] = None,
timing: bool = False,
logger_level: Union[str, int] = 0,
):
Expand Down Expand Up @@ -88,13 +89,13 @@ def __init__(

Parameters
----------
lib_path : Union[str, Path]
lib_path : Union[str, PathLike]
Path to the shared library

lib_dependency : Union[str, Path, None], optional
lib_dependency : Union[str, PathLike, None], optional
Path to the dependencies of the shared library, by default None

working_directory : Union[str, Path, None], optional
working_directory : Union[str, PathLike, None], optional
The working directory the shared library expects when being called,
by default None

Expand Down Expand Up @@ -137,7 +138,7 @@ def __del__(self) -> None:
self.finalize()

@staticmethod
def _add_lib_dependency(lib_dependency: Union[str, Path]) -> None:
def _add_lib_dependency(lib_dependency: Union[str, PathLike[Any]]) -> None:
lib_dependency = str(Path(lib_dependency).absolute())
if platform.system() == "Windows":
os.environ["PATH"] = lib_dependency + os.pathsep + os.environ["PATH"]
Expand Down Expand Up @@ -171,10 +172,10 @@ def set_int(self, name: str, value: int) -> None:
c_var = c_int.in_dll(self.lib, name)
c_var.value = value

def initialize(self, config_file: str = "") -> None:
def initialize(self, config_file: Union[str, PathLike[Any]] = "") -> None:
if self._state == State.UNINITIALIZED:
with cd(self.working_directory):
self._execute_function(self.lib.initialize, config_file.encode())
self._execute_function(self.lib.initialize, os.fsencode(config_file))
self._state = State.INITIALIZED
else:
raise InputError("The library is already initialized")
Expand Down
Loading