Skip to content

Commit 7fb3e7a

Browse files
committed
rename classes: *Process* => *Session*
1 parent beddea1 commit 7fb3e7a

8 files changed

Lines changed: 43 additions & 43 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
OMCSessionException,
5353
OMCSessionRunData,
5454
OMCSessionZMQ,
55-
OMCProcess,
56-
OMCProcessLocal,
55+
OMCSession,
56+
OMCSessionLocal,
5757
OMCPath,
5858
)
5959

@@ -336,7 +336,7 @@ def __init__(
336336
command_line_options: Optional[list[str]] = None,
337337
work_directory: Optional[str | os.PathLike] = None,
338338
omhome: Optional[str] = None,
339-
omc_process: Optional[OMCProcess] = None,
339+
omc_process: Optional[OMCSession] = None,
340340
) -> None:
341341
"""Create a ModelicaSystem instance. To define the model use model() or convertFmu2Mo().
342342
@@ -464,13 +464,13 @@ def model(
464464
if model_file is not None:
465465
file_path = pathlib.Path(model_file)
466466
# special handling for OMCProcessLocal - consider a relative path
467-
if isinstance(self._session.omc_process, OMCProcessLocal) and not file_path.is_absolute():
467+
if isinstance(self._session.omc_process, OMCSessionLocal) and not file_path.is_absolute():
468468
file_path = pathlib.Path.cwd() / file_path
469469
if not file_path.is_file():
470470
raise IOError(f"Model file {file_path} does not exist!")
471471

472472
self._file_name = self.getWorkDirectory() / file_path.name
473-
if (isinstance(self._session.omc_process, OMCProcessLocal)
473+
if (isinstance(self._session.omc_process, OMCSessionLocal)
474474
and file_path.as_posix() == self._file_name.as_posix()):
475475
pass
476476
elif self._file_name.is_file():
@@ -1207,7 +1207,7 @@ def plot(
12071207
plot is created by OMC which needs access to the local display. This is not the case for docker and WSL.
12081208
"""
12091209

1210-
if not isinstance(self._session.omc_process, OMCProcessLocal):
1210+
if not isinstance(self._session.omc_process, OMCSessionLocal):
12111211
raise ModelicaSystemError("Plot is using the OMC plot functionality; "
12121212
"thus, it is only working if OMC is running locally!")
12131213

@@ -1967,7 +1967,7 @@ def __init__(
19671967
variable_filter: Optional[str] = None,
19681968
work_directory: Optional[str | os.PathLike] = None,
19691969
omhome: Optional[str] = None,
1970-
omc_process: Optional[OMCProcess] = None,
1970+
omc_process: Optional[OMCSession] = None,
19711971
# simulation specific input
19721972
# TODO: add more settings (simulation options, input options, ...)
19731973
simargs: Optional[dict[str, Optional[str | dict[str, str] | numbers.Number]]] = None,

OMPython/OMCSession.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ class OMCPathReal(pathlib.PurePosixPath):
293293
errors as well as usage on a Windows system due to slightly different definitions (PureWindowsPath).
294294
"""
295295

296-
def __init__(self, *path, session: OMCProcess) -> None:
296+
def __init__(self, *path, session: OMCSession) -> None:
297297
super().__init__(*path)
298298
self._session = session
299299

@@ -322,7 +322,7 @@ def is_absolute(self):
322322
Check if the path is an absolute path considering the possibility that we are running locally on Windows. This
323323
case needs special handling as the definition of is_absolute() differs.
324324
"""
325-
if isinstance(self._session, OMCProcessLocal) and platform.system() == 'Windows':
325+
if isinstance(self._session, OMCSessionLocal) and platform.system() == 'Windows':
326326
return pathlib.PureWindowsPath(self.as_posix()).is_absolute()
327327
return super().is_absolute()
328328

@@ -546,7 +546,7 @@ def __init__(
546546
self,
547547
timeout: float = 10.00,
548548
omhome: Optional[str] = None,
549-
omc_process: Optional[OMCProcess] = None,
549+
omc_process: Optional[OMCSession] = None,
550550
) -> None:
551551
"""
552552
Initialisation for OMCSessionZMQ
@@ -557,8 +557,8 @@ def __init__(
557557
stacklevel=2)
558558

559559
if omc_process is None:
560-
omc_process = OMCProcessLocal(omhome=omhome, timeout=timeout)
561-
elif not isinstance(omc_process, OMCProcess):
560+
omc_process = OMCSessionLocal(omhome=omhome, timeout=timeout)
561+
elif not isinstance(omc_process, OMCSession):
562562
raise OMCSessionException("Invalid definition of the OMC process!")
563563
self.omc_process = omc_process
564564

@@ -570,7 +570,7 @@ def escape_str(value: str) -> str:
570570
"""
571571
Escape a string such that it can be used as string within OMC expressions, i.e. escape all double quotes.
572572
"""
573-
return OMCProcess.escape_str(value=value)
573+
return OMCSession.escape_str(value=value)
574574

575575
def omcpath(self, *path) -> OMCPath:
576576
"""
@@ -599,7 +599,7 @@ def run_model_executable(cmd_run_data: OMCSessionRunData) -> int:
599599
Run the command defined in cmd_run_data. This class is defined as static method such that there is no need to
600600
keep instances of over classes around.
601601
"""
602-
return OMCProcess.run_model_executable(cmd_run_data=cmd_run_data)
602+
return OMCSession.run_model_executable(cmd_run_data=cmd_run_data)
603603

604604
def execute(self, command: str):
605605
return self.omc_process.execute(command=command)
@@ -641,7 +641,7 @@ def __call__(cls, *args, **kwargs):
641641
return obj
642642

643643

644-
class OMCProcessMeta(abc.ABCMeta, PostInitCaller):
644+
class OMCSessionMeta(abc.ABCMeta, PostInitCaller):
645645
"""
646646
Helper class to get a combined metaclass of ABCMeta and PostInitCaller.
647647
@@ -650,7 +650,7 @@ class OMCProcessMeta(abc.ABCMeta, PostInitCaller):
650650
"""
651651

652652

653-
class OMCProcess(metaclass=OMCProcessMeta):
653+
class OMCSession(metaclass=OMCSessionMeta):
654654
"""
655655
Base class for an OMC session. This class contains common functionality for all OMC sessions.
656656
@@ -771,7 +771,7 @@ def omcpath(self, *path) -> OMCPath:
771771

772772
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
773773
if sys.version_info < (3, 12):
774-
if isinstance(self, OMCProcessLocal):
774+
if isinstance(self, OMCSessionLocal):
775775
# noinspection PyArgumentList
776776
return OMCPath(*path)
777777
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCProcessLocal is used!")
@@ -1040,7 +1040,7 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
10401040
raise NotImplementedError("This method must be implemented in subclasses!")
10411041

10421042

1043-
class OMCProcessPort(OMCProcess):
1043+
class OMCSessionPort(OMCSession):
10441044
"""
10451045
OMCProcess implementation which uses a port to connect to an already running OMC server.
10461046
"""
@@ -1059,7 +1059,7 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
10591059
raise OMCSessionException("OMCProcessPort does not support omc_run_data_update()!")
10601060

10611061

1062-
class OMCProcessLocal(OMCProcess):
1062+
class OMCSessionLocal(OMCSession):
10631063
"""
10641064
OMCProcess implementation which runs the OMC server locally on the machine (Linux / Windows).
10651065
"""
@@ -1185,7 +1185,7 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
11851185
return omc_run_data_copy
11861186

11871187

1188-
class OMCProcessDockerHelper(OMCProcess):
1188+
class OMCSessionDockerHelper(OMCSession):
11891189
"""
11901190
Base class for OMCProcess implementations which run the OMC server in a Docker container.
11911191
"""
@@ -1322,7 +1322,7 @@ def omc_run_data_update(self, omc_run_data: OMCSessionRunData) -> OMCSessionRunD
13221322
return omc_run_data_copy
13231323

13241324

1325-
class OMCProcessDocker(OMCProcessDockerHelper):
1325+
class OMCSessionDocker(OMCSessionDockerHelper):
13261326
"""
13271327
OMC process running in a Docker container.
13281328
"""
@@ -1465,7 +1465,7 @@ def _docker_omc_start(self) -> Tuple[subprocess.Popen, DockerPopen, str]:
14651465
return omc_process, docker_process, docker_cid
14661466

14671467

1468-
class OMCProcessDockerContainer(OMCProcessDockerHelper):
1468+
class OMCSessionDockerContainer(OMCSessionDockerHelper):
14691469
"""
14701470
OMC process running in a Docker container (by container ID).
14711471
"""
@@ -1558,7 +1558,7 @@ def _docker_omc_start(self) -> Tuple[subprocess.Popen, DockerPopen]:
15581558
return omc_process, docker_process
15591559

15601560

1561-
class OMCProcessWSL(OMCProcess):
1561+
class OMCSessionWSL(OMCSession):
15621562
"""
15631563
OMC process running in Windows Subsystem for Linux (WSL).
15641564
"""

OMPython/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
OMCSessionException,
4949
OMCSessionRunData,
5050
OMCSessionZMQ,
51-
OMCProcessPort,
52-
OMCProcessLocal,
53-
OMCProcessDocker,
54-
OMCProcessDockerContainer,
55-
OMCProcessWSL,
51+
OMCSessionPort,
52+
OMCSessionLocal,
53+
OMCSessionDocker,
54+
OMCSessionDockerContainer,
55+
OMCSessionWSL,
5656
)
5757

5858
# global names imported if import 'from OMPython import *' is used
@@ -67,9 +67,9 @@
6767
'OMCSessionException',
6868
'OMCSessionRunData',
6969
'OMCSessionZMQ',
70-
'OMCProcessPort',
71-
'OMCProcessLocal',
72-
'OMCProcessDocker',
73-
'OMCProcessDockerContainer',
74-
'OMCProcessWSL',
70+
'OMCSessionPort',
71+
'OMCSessionLocal',
72+
'OMCSessionDocker',
73+
'OMCSessionDockerContainer',
74+
'OMCSessionWSL',
7575
]

tests/test_ModelicaSystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
155155
@skip_on_windows
156156
@skip_python_older_312
157157
def test_getSolutions_docker(model_firstorder):
158-
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
158+
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
159159
omc = OMPython.OMCSessionZMQ(omc_process=omcp)
160160

161161
mod = OMPython.ModelicaSystem(

tests/test_ModelicaSystemDoE.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_ModelicaSystemDoE_local(tmp_path, model_doe, param_doe):
6969
@skip_on_windows
7070
@skip_python_older_312
7171
def test_ModelicaSystemDoE_docker(tmp_path, model_doe, param_doe):
72-
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
72+
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
7373
omc = OMPython.OMCSessionZMQ(omc_process=omcp)
7474
assert omc.sendExpression("getVersion()") == "OpenModelica 1.25.0"
7575

tests/test_OMCPath.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_OMCPath_OMCSessionZMQ():
2424

2525

2626
def test_OMCPath_OMCProcessLocal():
27-
omp = OMPython.OMCProcessLocal()
27+
omp = OMPython.OMCSessionLocal()
2828
om = OMPython.OMCSessionZMQ(omc_process=omp)
2929

3030
_run_OMCPath_checks(om)
@@ -35,7 +35,7 @@ def test_OMCPath_OMCProcessLocal():
3535
@skip_on_windows
3636
@skip_python_older_312
3737
def test_OMCPath_OMCProcessDocker():
38-
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
38+
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
3939
om = OMPython.OMCSessionZMQ(omc_process=omcp)
4040
assert om.sendExpression("getVersion()") == "OpenModelica 1.25.0"
4141

@@ -48,7 +48,7 @@ def test_OMCPath_OMCProcessDocker():
4848
@pytest.mark.skip(reason="Not able to run WSL on github")
4949
@skip_python_older_312
5050
def test_OMCPath_OMCProcessWSL():
51-
omcp = OMPython.OMCProcessWSL(
51+
omcp = OMPython.OMCSessionWSL(
5252
wsl_omc='omc',
5353
wsl_user='omc',
5454
timeout=30.0,

tests/test_ZMQ.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_execute(om):
4646

4747
def test_omcprocessport_execute(om):
4848
port = om.omc_process.get_port()
49-
omcp = OMPython.OMCProcessPort(omc_port=port)
49+
omcp = OMPython.OMCSessionPort(omc_port=port)
5050

5151
# run 1
5252
om1 = OMPython.OMCSessionZMQ(omc_process=omcp)
@@ -62,7 +62,7 @@ def test_omcprocessport_execute(om):
6262

6363
def test_omcprocessport_simulate(om, model_time_str):
6464
port = om.omc_process.get_port()
65-
omcp = OMPython.OMCProcessPort(omc_port=port)
65+
omcp = OMPython.OMCSessionPort(omc_port=port)
6666

6767
om = OMPython.OMCSessionZMQ(omc_process=omcp)
6868
assert om.sendExpression(f'loadString("{model_time_str}")') is True

tests/test_docker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
@skip_on_windows
1212
def test_docker():
13-
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
13+
omcp = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
1414
om = OMPython.OMCSessionZMQ(omc_process=omcp)
1515
assert om.sendExpression("getVersion()") == "OpenModelica 1.25.0"
1616

17-
omcpInner = OMPython.OMCProcessDockerContainer(dockerContainer=omcp.get_docker_container_id())
17+
omcpInner = OMPython.OMCSessionDockerContainer(dockerContainer=omcp.get_docker_container_id())
1818
omInner = OMPython.OMCSessionZMQ(omc_process=omcpInner)
1919
assert omInner.sendExpression("getVersion()") == "OpenModelica 1.25.0"
2020

21-
omcp2 = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal", port=11111)
21+
omcp2 = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal", port=11111)
2222
om2 = OMPython.OMCSessionZMQ(omc_process=omcp2)
2323
assert om2.sendExpression("getVersion()") == "OpenModelica 1.25.0"
2424

0 commit comments

Comments
 (0)