Skip to content

Commit 70cafe0

Browse files
committed
[compatibility] add class wrapper to provide the depreciation message
1 parent 2c34957 commit 70cafe0

3 files changed

Lines changed: 85 additions & 20 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 7 additions & 0 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.
@@ -170,12 +175,14 @@ def getOutputs(
170175
raise ModelExecutionException("Invalid data!")
171176

172177

178+
@depreciated_class(msg="Please use class ModelicaDoEOMC instead!")
173179
class ModelicaSystemDoE(ModelicaDoEOMC):
174180
"""
175181
Compatibility class.
176182
"""
177183

178184

185+
@depreciated_class(msg="Please use class ModelExecutionCmd instead!")
179186
class ModelicaSystemCmd(ModelExecutionCmd):
180187
"""
181188
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):
@@ -301,9 +293,36 @@ def set_workdir(self, workdir: OMPathABC) -> None:
301293
return self.omc_process.set_workdir(workdir=workdir)
302294

303295

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

OMPython/compatibility_v400.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Helper functions for compatibility with OMPython v4.0.0
4+
"""
5+
import warnings
6+
from typing import Optional
7+
8+
9+
def depreciated_class(msg: Optional[str] = None):
10+
"""
11+
Decorator for depreciated / compatibility classes.
12+
"""
13+
14+
def depreciated(cls):
15+
"""
16+
Helper functions to do the decoration part.
17+
"""
18+
19+
class Wrapper(cls):
20+
"""
21+
Wrapper to define the depreciation message.
22+
"""
23+
24+
def __init__(self, *args, **kwargs):
25+
message = f"The class {cls.__name__} is depreciated and will be removed in future versions!"
26+
if msg is not None:
27+
message += f" {msg}"
28+
29+
warnings.warn(
30+
message=message,
31+
category=DeprecationWarning,
32+
stacklevel=3,
33+
)
34+
35+
super().__init__(*args, **kwargs)
36+
37+
return Wrapper
38+
39+
return depreciated

0 commit comments

Comments
 (0)