Skip to content

Commit 1347d11

Browse files
committed
Removed OMCSession
1 parent 6d85271 commit 1347d11

5 files changed

Lines changed: 20 additions & 55 deletions

File tree

OMPython/__init__.py

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
11
# -*- coding: utf-8 -*-
22
"""
33
OMPython is a Python interface to OpenModelica.
4-
To get started, create an OMCSession/OMCSessionZMQ object:
5-
from OMPython import OMCSession/OMCSessionZMQ
6-
omc = OMCSession()/OMCSessionZMQ()
7-
omc.sendExpression(command)
8-
9-
Note: Conversion from OMPython 1.0 to OMPython 2.0 is very simple
10-
1.0:
11-
import OMPython
12-
OMPython.execute(command)
13-
2.0:
14-
from OMPython import OMCSession
15-
OMPython = OMCSession()
16-
OMPython.execute(command)
17-
18-
OMPython 3.0 includes a new class OMCSessionZMQ uses PyZMQ to communicate
19-
with OpenModelica. A new argument `useCorba=False` is added to ModelicaSystem
20-
class which means it will use OMCSessionZMQ by default. If you want to use
21-
OMCSession then create ModelicaSystem object like this,
22-
obj = ModelicaSystem(useCorba=True)
23-
24-
The difference between execute and sendExpression is the type of the
25-
returned expression. sendExpression maps Modelica types to Python types,
26-
while execute tries to map also output that is not valid Modelica.
27-
That format is harder to use.
4+
To get started, create an OMCSessionZMQ object:
5+
from OMPython import OMCSessionZMQ
6+
omc = OMCSessionZMQ()
7+
omc.sendExpression("command")
288
"""
299

3010
from __future__ import absolute_import
@@ -553,7 +533,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
553533
str(builtin).lower(), str(showProtected).lower()))
554534
return value
555535

556-
class OMCSession(OMCSessionHelper, OMCSessionBase):
536+
class OMCSessionZMQ(OMCSessionHelper, OMCSessionBase):
557537

558538
def __init__(self, readonly=False, timeout = 10.00,
559539
docker = None, dockerContainer = None, dockerExtraArgs = None, dockerOpenModelicaPath = "omc",
@@ -662,16 +642,7 @@ def sendExpression(self, command, parsed=True):
662642
else:
663643
return result
664644
else:
665-
raise Exception("Process Exited, No connection with OMC. Create a new instance of OMCSession")
666-
667-
class OMCSessionZMQ(OMCSession):
668-
def __init__(self, *args, **kwargs):
669-
warnings.warn(
670-
"OMCSessionZMQ is deprecated and will be remove in the next release. Please use OMCSession instead.",
671-
DeprecationWarning,
672-
stacklevel=2
673-
)
674-
super(OMCSessionZMQ, self).__init__(*args, **kwargs)
645+
raise Exception("Process Exited, No connection with OMC. Create a new instance of OMCSessionZMQ")
675646

676647
class ModelicaSystemError(Exception):
677648
pass
@@ -689,13 +660,8 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
689660
Note: If the model file is not in the current working directory, then the path where file is located must be included together with file name. Besides, if the Modelica model contains several different models within the same package, then in order to build the specific model, in second argument, user must put the package name with dot(.) followed by specific model name.
690661
ex: myModel = ModelicaSystem("ModelicaModel.mo", "modelName")
691662
"""
692-
if session is not None:
693-
self.getconn = session
694-
else:
695-
self.getconn = OMCSession(omhome=omhome)
696-
697663
if fileName is None and modelName is None and not lmodel: # all None
698-
self.getconn = OMCSession(omhome=omhome)
664+
raise Exception("Cannot create ModelicaSystem object without any arguments")
699665
return
700666

701667
self.tree = None
@@ -717,7 +683,10 @@ def __init__(self, fileName=None, modelName=None, lmodel=None, commandLineOption
717683

718684
self._verbose = verbose
719685

720-
self.getconn = OMCSession(omhome=omhome)
686+
if session is not None:
687+
self.getconn = session
688+
else:
689+
self.getconn = OMCSessionZMQ(omhome=omhome)
721690

722691
## needed for properly deleting the session
723692
self._omc_log_file = self.getconn._omc_log_file

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ help(OMPython)
4040
```
4141

4242
```python
43-
from OMPython import OMCSession
44-
omc = OMCSession()
43+
from OMPython import OMCSessionZMQ
44+
omc = OMCSessionZMQ()
4545
omc.sendExpression("getVersion()")
4646
```
4747

@@ -50,12 +50,8 @@ online.
5050

5151
## Bug Reports
5252

53-
- See OMPython bugs on the [OpenModelica
54-
trac](https://trac.openmodelica.org/OpenModelica/query?component=OMPython)
55-
or submit a [new
56-
ticket](https://trac.openmodelica.org/OpenModelica/newticket).
57-
- [Pull requests](https://github.com/OpenModelica/OMPython/pulls) are
58-
welcome.
53+
- Submit bugs through the [OpenModelica GitHub issues](https://github.com/OpenModelica/OMPython/issues/new).
54+
- [Pull requests](https://github.com/OpenModelica/OMPython/pulls) are welcome ❤️.
5955

6056
## Contact
6157

tests/test_ArrayDimension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Test_ArrayDimension:
1111

1212
def test_ArrayDimension(self):
13-
omc = OMPython.OMCSession()
13+
omc = OMPython.OMCSessionZMQ()
1414

1515
## create a temp dir for each session
1616
tempdir = tempfile.mkdtemp()

tests/test_FMIRegression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Test_FMIRegression:
1111

1212
def buildModelFMU(self, modelName):
13-
omc = OMPython.OMCSession()
13+
omc = OMPython.OMCSessionZMQ()
1414

1515
## create a temp dir for each session
1616
tempdir = tempfile.mkdtemp()

tests/test_docker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
class DockerTester(unittest.TestCase):
77
@pytest.mark.skip(reason="This test would fail")
88
def testDocker(self):
9-
om = OMPython.OMCSession(docker="openmodelica/openmodelica:v1.16.1-minimal")
9+
om = OMPython.OMCSessionZMQ(docker="openmodelica/openmodelica:v1.16.1-minimal")
1010
assert(om.sendExpression("getVersion()") == "OpenModelica 1.16.1")
11-
omInner = OMPython.OMCSession(dockerContainer=om._dockerCid)
11+
omInner = OMPython.OMCSessionZMQ(dockerContainer=om._dockerCid)
1212
assert(omInner.sendExpression("getVersion()") == "OpenModelica 1.16.1")
13-
om2 = OMPython.OMCSession(docker="openmodelica/openmodelica:v1.16.1-minimal", port=11111)
13+
om2 = OMPython.OMCSessionZMQ(docker="openmodelica/openmodelica:v1.16.1-minimal", port=11111)
1414
assert(om2.sendExpression("getVersion()") == "OpenModelica 1.16.1")
1515
del(om2)
1616
del(omInner)

0 commit comments

Comments
 (0)