Skip to content

Commit 229505f

Browse files
committed
??? WiP / TODO: rename all other *session* elements; cleanup tests
1 parent 62a3bd8 commit 229505f

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

OMPython/OMCSession.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ class OMCProcessCmd:
9898
Implementation of Open Modelica Compiler API functions. Depreciated!
9999
"""
100100

101-
def __init__(self, session: OMCProcess, readonly: bool = False):
102-
if not isinstance(session, OMCProcess):
101+
def __init__(self, omc_process: OMCProcess, readonly: bool = False):
102+
if not isinstance(omc_process, OMCProcess):
103103
raise OMCProcessException("Invalid session definition!")
104-
self._session = session
104+
self._omc_process = omc_process
105105
self._readonly = readonly
106106
self._omc_cache: dict[tuple[str, bool], Any] = {}
107107

@@ -122,7 +122,7 @@ def _ask(self, question: str, opt: Optional[list[str]] = None, parsed: bool = Tr
122122
return self._omc_cache[p]
123123

124124
try:
125-
res = self._session.sendExpression(expression, parsed=parsed)
125+
res = self._omc_process.sendExpression(expression, parsed=parsed)
126126
except OMCProcessException as ex:
127127
raise OMCProcessException(f"OMC _ask() failed: {expression} (parsed={parsed})") from ex
128128

@@ -292,29 +292,29 @@ class OMCPath(pathlib.PurePosixPath):
292292
errors as well as usage on a Windows system due to slightly different definitions (PureWindowsPath).
293293
"""
294294

295-
def __init__(self, *path, session: OMCProcess):
295+
def __init__(self, *path, omc_process: OMCProcess):
296296
super().__init__(*path)
297-
self._session = session
297+
self._omc_process = omc_process
298298

299299
def with_segments(self, *pathsegments):
300300
"""
301301
Create a new OMCPath object with the given path segments.
302302
303303
The original definition of Path is overridden to ensure session is set.
304304
"""
305-
return type(self)(*pathsegments, session=self._session)
305+
return type(self)(*pathsegments, omc_process=self._omc_process)
306306

307307
def is_file(self, *, follow_symlinks=True) -> bool:
308308
"""
309309
Check if the path is a regular file.
310310
"""
311-
return self._session.sendExpression(f'regularFileExists("{self.as_posix()}")')
311+
return self._omc_process.sendExpression(f'regularFileExists("{self.as_posix()}")')
312312

313313
def is_dir(self, *, follow_symlinks=True) -> bool:
314314
"""
315315
Check if the path is a directory.
316316
"""
317-
return self._session.sendExpression(f'directoryExists("{self.as_posix()}")')
317+
return self._omc_process.sendExpression(f'directoryExists("{self.as_posix()}")')
318318

319319
def is_absolute(self):
320320
"""
@@ -332,7 +332,7 @@ def read_text(self, encoding=None, errors=None, newline=None) -> str:
332332
The additional arguments `encoding`, `errors` and `newline` are only defined for compatibility with Path()
333333
definition.
334334
"""
335-
return self._session.sendExpression(f'readFile("{self.as_posix()}")')
335+
return self._omc_process.sendExpression(f'readFile("{self.as_posix()}")')
336336

337337
def write_text(self, data: str, encoding=None, errors=None, newline=None):
338338
"""
@@ -358,20 +358,20 @@ def mkdir(self, mode=0o777, parents=False, exist_ok=False):
358358
if self.is_dir() and not exist_ok:
359359
raise FileExistsError(f"Directory {self.as_posix()} already exists!")
360360

361-
return self._session.sendExpression(f'mkdir("{self.as_posix()}")')
361+
return self._omc_process.sendExpression(f'mkdir("{self.as_posix()}")')
362362

363363
def cwd(self):
364364
"""
365365
Returns the current working directory as an OMCPath object.
366366
"""
367-
cwd_str = self._session.sendExpression('cd()')
368-
return OMCPath(cwd_str, session=self._session)
367+
cwd_str = self._omc_process.sendExpression('cd()')
368+
return OMCPath(cwd_str, omc_process=self._omc_process)
369369

370370
def unlink(self, missing_ok: bool = False) -> None:
371371
"""
372372
Unlink (delete) the file or directory represented by this path.
373373
"""
374-
res = self._session.sendExpression(f'deleteFile("{self.as_posix()}")')
374+
res = self._omc_process.sendExpression(f'deleteFile("{self.as_posix()}")')
375375
if not res and not missing_ok:
376376
raise FileNotFoundError(f"Cannot delete file {self.as_posix()} - it does not exists!")
377377

@@ -406,12 +406,12 @@ def _omc_resolve(self, pathstr: str) -> str:
406406
'cd(omcpath_cwd)')
407407

408408
try:
409-
result = self._session.sendExpression(command=expression, parsed=False)
409+
result = self._omc_process.sendExpression(command=expression, parsed=False)
410410
result_parts = result.split('\n')
411411
pathstr_resolved = result_parts[1]
412412
pathstr_resolved = pathstr_resolved[1:-1] # remove quotes
413413

414-
omcpath_resolved = self._session.omcpath(pathstr_resolved)
414+
omcpath_resolved = self._omc_process.omcpath(pathstr_resolved)
415415
except OMCProcessException as ex:
416416
raise OMCProcessException(f"OMCPath resolve failed for {pathstr}!") from ex
417417

@@ -440,7 +440,7 @@ def size(self) -> int:
440440
if not self.is_file():
441441
raise OMCProcessException(f"Path {self.as_posix()} is not a file!")
442442

443-
res = self._session.sendExpression(f'stat("{self.as_posix()}")')
443+
res = self._omc_process.sendExpression(f'stat("{self.as_posix()}")')
444444
if res[0]:
445445
return int(res[1])
446446

@@ -652,7 +652,7 @@ def omcpath(self, *path) -> OMCPath:
652652
"""
653653
Create an OMCPath object based on the given path segments and the current OMC session.
654654
"""
655-
return OMCPath(*path, session=self)
655+
return OMCPath(*path, omc_process=self)
656656

657657
def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
658658
"""

tests/test_OMSessionCmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def test_isPackage():
55
omczmq = OMPython.OMCProcessLocal()
6-
omccmd = OMPython.OMCProcessCmd(session=omczmq)
6+
omccmd = OMPython.OMCProcessCmd(omc_process=omczmq)
77
assert not omccmd.isPackage('Modelica')
88

99

@@ -13,7 +13,7 @@ def test_isPackage2():
1313
model_name="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
1414
libraries=["Modelica"],
1515
)
16-
omccmd = OMPython.OMCProcessCmd(session=mod.get_omc_process())
16+
omccmd = OMPython.OMCProcessCmd(omc_process=mod.get_omc_process())
1717
assert omccmd.isPackage('Modelica')
1818

1919

0 commit comments

Comments
 (0)