Skip to content

Commit 2f07130

Browse files
committed
Merge branch 'G003-compatibility' into merge_BCDEF_squash+merge
2 parents da5b791 + 363d322 commit 2f07130

6 files changed

Lines changed: 256 additions & 60 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 151 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@
2828
ModelicaDoEOMC,
2929
)
3030

31+
from OMPython.compatibility_v400 import (
32+
depreciated_class,
33+
)
34+
3135
# define logger using the current module name as ID
3236
logger = logging.getLogger(__name__)
3337

3438

39+
@depreciated_class(msg="Please use class ModelicaSystemOMC instead!")
3540
class ModelicaSystem(ModelicaSystemOMC):
3641
"""
3742
Compatibility class.
@@ -67,58 +72,167 @@ def __init__(
6772
def setCommandLineOptions(self, commandLineOptions: str):
6873
super().set_command_line_options(command_line_option=commandLineOptions)
6974

70-
def setContinuous( # type: ignore[override]
75+
def _set_compatibility_helper(
76+
self,
77+
pkey: str,
78+
args: Any,
79+
kwargs: dict[str, Any],
80+
) -> Any:
81+
param = None
82+
if len(args) == 1:
83+
param = args[0]
84+
if param is None and pkey in kwargs:
85+
param = kwargs[pkey]
86+
87+
return param
88+
89+
def setContinuous(
7190
self,
72-
cvals: str | list[str] | dict[str, Any],
91+
*args: Any,
92+
**kwargs: dict[str, Any],
7393
) -> bool:
74-
if isinstance(cvals, dict):
75-
return super().setContinuous(**cvals)
76-
raise ModelicaSystemError("Only dict input supported for setContinuous()")
94+
"""
95+
Compatibility wrapper for setContinuous() from OMPython v4.0.0
96+
97+
Original definition:
7798
78-
def setParameters( # type: ignore[override]
99+
```
100+
def setContinuous(
101+
self,
102+
cvals: str | list[str] | dict[str, Any],
103+
) -> bool:
104+
```
105+
"""
106+
param = self._set_compatibility_helper(pkey='cvals', args=args, kwargs=kwargs)
107+
if param is None:
108+
raise ModelicaSystemError("Invalid input for setContinuous() (v4.0.0 compatibility mode).")
109+
110+
return super().setContinuous(param)
111+
112+
def setParameters(
79113
self,
80-
pvals: str | list[str] | dict[str, Any],
114+
*args: Any,
115+
**kwargs: dict[str, Any],
81116
) -> bool:
82-
if isinstance(pvals, dict):
83-
return super().setParameters(**pvals)
84-
raise ModelicaSystemError("Only dict input supported for setParameters()")
117+
"""
118+
Compatibility wrapper for setParameters() from OMPython v4.0.0
119+
120+
Original definition:
85121
86-
def setOptimizationOptions( # type: ignore[override]
122+
```
123+
def setParameters(
124+
self,
125+
pvals: str | list[str] | dict[str, Any],
126+
) -> bool:
127+
```
128+
"""
129+
param = self._set_compatibility_helper(pkey='pvals', args=args, kwargs=kwargs)
130+
if param is None:
131+
raise ModelicaSystemError("Invalid input for setParameters() (v4.0.0 compatibility mode).")
132+
133+
return super().setParameters(param)
134+
135+
def setOptimizationOptions(
87136
self,
88-
optimizationOptions: str | list[str] | dict[str, Any],
137+
*args: Any,
138+
**kwargs: dict[str, Any],
89139
) -> bool:
90-
if isinstance(optimizationOptions, dict):
91-
return super().setOptimizationOptions(**optimizationOptions)
92-
raise ModelicaSystemError("Only dict input supported for setOptimizationOptions()")
140+
"""
141+
Compatibility wrapper for setOptimizationOptions() from OMPython v4.0.0
142+
143+
Original definition:
93144
94-
def setInputs( # type: ignore[override]
145+
```
146+
def setOptimizationOptions(
147+
self,
148+
optimizationOptions: str | list[str] | dict[str, Any],
149+
) -> bool:
150+
```
151+
"""
152+
param = self._set_compatibility_helper(pkey='optimizationOptions', args=args, kwargs=kwargs)
153+
if param is None:
154+
raise ModelicaSystemError("Invalid input for setOptimizationOptions() (v4.0.0 compatibility mode).")
155+
156+
return super().setOptimizationOptions(param)
157+
158+
def setInputs(
95159
self,
96-
name: str | list[str] | dict[str, Any],
160+
*args: Any,
161+
**kwargs: dict[str, Any],
97162
) -> bool:
98-
if isinstance(name, dict):
99-
return super().setInputs(**name)
100-
raise ModelicaSystemError("Only dict input supported for setInputs()")
163+
"""
164+
Compatibility wrapper for setInputs() from OMPython v4.0.0
165+
166+
Original definition:
101167
102-
def setSimulationOptions( # type: ignore[override]
168+
```
169+
def setInputs(
170+
self,
171+
name: str | list[str] | dict[str, Any],
172+
) -> bool:
173+
```
174+
"""
175+
param = self._set_compatibility_helper(pkey='name', args=args, kwargs=kwargs)
176+
if param is None:
177+
raise ModelicaSystemError("Invalid input for setInputs() (v4.0.0 compatibility mode).")
178+
179+
return super().setInputs(param)
180+
181+
def setSimulationOptions(
103182
self,
104-
simOptions: str | list[str] | dict[str, Any],
183+
*args: Any,
184+
**kwargs: dict[str, Any],
105185
) -> bool:
106-
if isinstance(simOptions, dict):
107-
return super().setSimulationOptions(**simOptions)
108-
raise ModelicaSystemError("Only dict input supported for setSimulationOptions()")
186+
"""
187+
Compatibility wrapper for setSimulationOptions() from OMPython v4.0.0
188+
189+
Original definition:
109190
110-
def setLinearizationOptions( # type: ignore[override]
191+
```
192+
def setSimulationOptions(
193+
self,
194+
simOptions: str | list[str] | dict[str, Any],
195+
) -> bool:
196+
```
197+
"""
198+
param = self._set_compatibility_helper(pkey='simOptions', args=args, kwargs=kwargs)
199+
if param is None:
200+
raise ModelicaSystemError("Invalid input for setSimulationOptions() (v4.0.0 compatibility mode).")
201+
202+
return super().setSimulationOptions(param)
203+
204+
def setLinearizationOptions(
111205
self,
112-
linearizationOptions: str | list[str] | dict[str, Any],
206+
*args: Any,
207+
**kwargs: dict[str, Any],
113208
) -> bool:
114-
if isinstance(linearizationOptions, dict):
115-
return super().setLinearizationOptions(**linearizationOptions)
116-
raise ModelicaSystemError("Only dict input supported for setLinearizationOptions()")
209+
"""
210+
Compatibility wrapper for setLinearizationOptions() from OMPython v4.0.0
211+
212+
Original definition:
213+
214+
```
215+
def setLinearizationOptions(
216+
self,
217+
linearizationOptions: str | list[str] | dict[str, Any],
218+
) -> bool:
219+
```
220+
"""
221+
param = self._set_compatibility_helper(pkey='linearizationOptions', args=args, kwargs=kwargs)
222+
if param is None:
223+
raise ModelicaSystemError("Invalid input for setLinearizationOptions() (v4.0.0 compatibility mode).")
224+
225+
return super().setLinearizationOptions(param)
117226

118227
def getContinuous(
119228
self,
120229
names: Optional[str | list[str]] = None,
121230
):
231+
"""
232+
Compatibility wrapper for getContinuous() from OMPython v4.0.0
233+
234+
If no model simulation was run (self._simulated == False), the return value should be converted to str.
235+
"""
122236
retval = super().getContinuous(names=names)
123237
if self._simulated:
124238
return retval
@@ -146,6 +260,11 @@ def getOutputs(
146260
self,
147261
names: Optional[str | list[str]] = None,
148262
):
263+
"""
264+
Compatibility wrapper for getOutputs() from OMPython v4.0.0
265+
266+
If no model simulation was run (self._simulated == False), the return value should be converted to str.
267+
"""
149268
retval = super().getOutputs(names=names)
150269
if self._simulated:
151270
return retval
@@ -170,12 +289,14 @@ def getOutputs(
170289
raise ModelicaSystemError("Invalid data!")
171290

172291

292+
@depreciated_class(msg="Please use class ModelicaDoEOMC instead!")
173293
class ModelicaSystemDoE(ModelicaDoEOMC):
174294
"""
175295
Compatibility class.
176296
"""
177297

178298

299+
@depreciated_class(msg="Please use class ModelExecutionCmd instead!")
179300
class ModelicaSystemCmd(ModelExecutionCmd):
180301
"""
181302
Compatibility class; in the new version it is renamed as ModelExecutionCmd.

OMPython/OMCSession.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import logging
99
from typing import Any, Optional
10-
import warnings
1110

1211
import pyparsing
1312

@@ -17,7 +16,6 @@
1716
OMSessionException,
1817
)
1918
from OMPython.om_session_omc import (
20-
DockerPopen,
2119
OMCSessionABC,
2220
OMCSessionDocker,
2321
OMCSessionDockerContainer,
@@ -26,30 +24,28 @@
2624
OMCSessionWSL,
2725
)
2826

27+
from OMPython.compatibility_v400 import (
28+
depreciated_class,
29+
)
2930

3031
# define logger using the current module name as ID
3132
logger = logging.getLogger(__name__)
3233

3334

35+
@depreciated_class(msg="Please use class OMSessionException instead!")
3436
class OMCSessionException(OMSessionException):
3537
"""
3638
Just a compatibility layer ...
3739
"""
3840

3941

42+
@depreciated_class(msg="Please use OMCSession*.sendExpression(...) instead!")
4043
class OMCSessionCmd:
4144
"""
4245
Implementation of Open Modelica Compiler API functions. Depreciated!
4346
"""
4447

4548
def __init__(self, session: OMSessionABC, readonly: bool = False):
46-
warnings.warn(
47-
message="The class OMCSessionCMD is depreciated and will be removed in future versions; "
48-
"please use OMCSession*.sendExpression(...) instead!",
49-
category=DeprecationWarning,
50-
stacklevel=2,
51-
)
52-
5349
if not isinstance(session, OMSessionABC):
5450
raise OMSessionException("Invalid OMC process definition!")
5551
self._session = session
@@ -228,6 +224,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
228224
return self._ask(question='getClassNames', opt=opt)
229225

230226

227+
@depreciated_class(msg="Please use OMCSession* classes instead!")
231228
class OMCSessionZMQ(OMSessionABC):
232229
"""
233230
This class is a compatibility layer for the new schema using OMCSession* classes.
@@ -242,11 +239,6 @@ def __init__(
242239
"""
243240
Initialisation for OMCSessionZMQ
244241
"""
245-
warnings.warn(message="The class OMCSessionZMQ is depreciated and will be removed in future versions; "
246-
"please use OMCProcess* classes instead!",
247-
category=DeprecationWarning,
248-
stacklevel=2)
249-
250242
if omc_process is None:
251243
omc_process = OMCSessionLocal(omhome=omhome, timeout=timeout)
252244
elif not isinstance(omc_process, OMCSessionABC):
@@ -303,9 +295,36 @@ def set_workdir(self, workdir: OMPathABC) -> None:
303295
return self.omc_process.set_workdir(workdir=workdir)
304296

305297

306-
DummyPopen = DockerPopen
307-
OMCProcessLocal = OMCSessionLocal
308-
OMCProcessPort = OMCSessionPort
309-
OMCProcessDocker = OMCSessionDocker
310-
OMCProcessDockerContainer = OMCSessionDockerContainer
311-
OMCProcessWSL = OMCSessionWSL
298+
@depreciated_class(msg="Please use class OMCSessionLocal instead!")
299+
class OMCProcessLocal(OMCSessionLocal):
300+
"""
301+
Just a wrapper class; OMCProcessLocal => OMCSessionLocal
302+
"""
303+
304+
305+
@depreciated_class(msg="Please use class OMCSessionPort instead!")
306+
class OMCProcessPort(OMCSessionPort):
307+
"""
308+
Just a wrapper class; OMCProcessPort => OMCSessionPort
309+
"""
310+
311+
312+
@depreciated_class(msg="Please use class OMCSessionDocker instead!")
313+
class OMCProcessDocker(OMCSessionDocker):
314+
"""
315+
Just a wrapper class; OMCProcessDocker => OMCSessionDocker
316+
"""
317+
318+
319+
@depreciated_class(msg="Please use class OMCSessionDockerContainer instead!")
320+
class OMCProcessDockerContainer(OMCSessionDockerContainer):
321+
"""
322+
Just a wrapper class; OMCProcessDockerContainer => OMCSessionDockerContainer
323+
"""
324+
325+
326+
@depreciated_class(msg="Please use class OMCSessionWSL instead!")
327+
class OMCProcessWSL(OMCSessionWSL):
328+
"""
329+
Just a wrapper class; OMCProcessWSL => OMCSessionWSL
330+
"""

OMPython/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
'ModelicaDoEOMC',
9090
'ModelicaDoERunner',
9191
'ModelicaSystemABC',
92-
'ModelicaSystemDoE',
9392
'ModelicaSystemError',
9493
'ModelicaSystemOMC',
9594
'ModelicaSystemRunner',
@@ -112,8 +111,8 @@
112111

113112
'ModelicaSystemCmd',
114113
'ModelicaSystem',
114+
'ModelicaSystemDoE',
115115

116-
'OMCSessionABC',
117116
'OMCSessionCmd',
118117

119118
'OMCSessionException',

0 commit comments

Comments
 (0)