@@ -59,6 +59,7 @@ def wait(self, timeout):
5959 pass
6060
6161
62+ # TODO: rename to OMSessionException
6263class OMCSessionException (Exception ):
6364 """
6465 Exception which is raised by any OMC* class.
@@ -71,6 +72,13 @@ class OMCSessionCmd:
7172 """
7273
7374 def __init__ (self , session : OMSessionABC , readonly : bool = False ):
75+ warnings .warn (
76+ message = "The class OMCSessionCMD is depreciated and will be removed in future versions; "
77+ "please use OMCSession*.sendExpression(...) instead!" ,
78+ category = DeprecationWarning ,
79+ stacklevel = 2 ,
80+ )
81+
7482 if not isinstance (session , OMSessionABC ):
7583 raise OMCSessionException ("Invalid OMC process definition!" )
7684 self ._session = session
@@ -253,7 +261,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
253261# conditions. This is also the reason for OMPathABC, a simple base class to be used in ModelicaSystem* classes.
254262# Reason: before Python 3.12, pathlib.PurePosixPath can not be derived from; therefore, OMPathABC is not possible
255263if sys .version_info < (3 , 12 ):
256- class OMPathCompatibility (pathlib .Path ):
264+ class _OMPathCompatibility (pathlib .Path ):
257265 """
258266 Compatibility class for OMPathABC in Python < 3.12. This allows to run all code which uses OMPathABC (mainly
259267 ModelicaSystem) on these Python versions. There are remaining limitation as only local execution is possible.
@@ -264,8 +272,8 @@ def __new__(cls, *args, **kwargs):
264272 logger .warning ("Python < 3.12 - using a version of class OMCPath "
265273 "based on pathlib.Path for local usage only." )
266274
267- if cls is OMPathCompatibility :
268- cls = OMPathCompatibilityWindows if os .name == 'nt' else OMPathCompatibilityPosix
275+ if cls is _OMPathCompatibility :
276+ cls = _OMPathCompatibilityWindows if os .name == 'nt' else _OMPathCompatibilityPosix
269277 self = cls ._from_parts (args )
270278 if not self ._flavour .is_supported :
271279 raise NotImplementedError (f"cannot instantiate { cls .__name__ } on your system" )
@@ -277,22 +285,20 @@ def size(self) -> int:
277285 """
278286 return self .stat ().st_size
279287
280- class OMPathCompatibilityPosix (pathlib .PosixPath , OMPathCompatibility ):
288+ class _OMPathCompatibilityPosix (pathlib .PosixPath , _OMPathCompatibility ):
281289 """
282290 Compatibility class for OMCPath on Posix systems (Python < 3.12)
283291 """
284292
285- class OMPathCompatibilityWindows (pathlib .WindowsPath , OMPathCompatibility ):
293+ class _OMPathCompatibilityWindows (pathlib .WindowsPath , _OMPathCompatibility ):
286294 """
287295 Compatibility class for OMCPath on Windows systems (Python < 3.12)
288296 """
289297
290- OMPathABC = OMPathCompatibility
291- OMCPath = OMPathCompatibility
292- OMPathRunnerABC = OMPathCompatibility
293- OMPathRunnerLocal = OMPathCompatibility
294- OMPathRunnerBash = OMPathCompatibility
295-
298+ OMPathABC = _OMPathCompatibility
299+ OMPathRunnerABC = _OMPathCompatibility
300+ OMPathRunnerLocal = _OMPathCompatibility
301+ OMPathRunnerBash = _OMPathCompatibility
296302else :
297303 class OMPathABC (pathlib .PurePosixPath , metaclass = abc .ABCMeta ):
298304 """
@@ -427,7 +433,7 @@ def is_absolute(self) -> bool:
427433 """
428434 Check if the path is an absolute path. Special handling to differentiate Windows and Posix definitions.
429435 """
430- if isinstance ( self ._session , OMCSessionLocal ) and platform . system () == 'Windows' :
436+ if self ._session . model_execution_windows and self . _session . model_execution_local :
431437 return pathlib .PureWindowsPath (self .as_posix ()).is_absolute ()
432438 return pathlib .PurePosixPath (self .as_posix ()).is_absolute ()
433439
@@ -618,7 +624,7 @@ def resolve(self, strict: bool = False) -> OMPathABC:
618624
619625 def size (self ) -> int :
620626 """
621- Get the size of the file in bytes - implementation baseon on pathlib.Path.
627+ Get the size of the file in bytes - implementation based on pathlib.Path.
622628 """
623629 if not self .is_file ():
624630 raise OMCSessionException (f"Path { self .as_posix ()} is not a file!" )
@@ -776,7 +782,7 @@ def resolve(self, strict: bool = False) -> OMPathABC:
776782
777783 def size (self ) -> int :
778784 """
779- Get the size of the file in bytes - implementation baseon on pathlib.Path.
785+ Get the size of the file in bytes - implementation based on pathlib.Path.
780786 """
781787 if not self .is_file ():
782788 raise OMCSessionException (f"Path { self .as_posix ()} is not a file!" )
@@ -790,7 +796,7 @@ def size(self) -> int:
790796 try :
791797 return int (stdout )
792798 except ValueError as exc :
793- raise OSError (f"Invalid return value for filesize ({ self .as_posix ()} ): { stdout } " ) from exc
799+ raise OSError (f"Invalid return value for file size ({ self .as_posix ()} ): { stdout } " ) from exc
794800 else :
795801 raise OSError (f"Cannot get size for file { self .as_posix ()} " )
796802
@@ -1225,26 +1231,6 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMPathABC] = None) -> OMPathABC
12251231
12261232 return self ._tempdir (tempdir_base = tempdir_base )
12271233
1228- @staticmethod
1229- def _tempdir (tempdir_base : OMPathABC ) -> OMPathABC :
1230- names = [str (uuid .uuid4 ()) for _ in range (100 )]
1231-
1232- tempdir : Optional [OMPathABC ] = None
1233- for name in names :
1234- # create a unique temporary directory name
1235- tempdir = tempdir_base / name
1236-
1237- if tempdir .exists ():
1238- continue
1239-
1240- tempdir .mkdir (parents = True , exist_ok = False )
1241- break
1242-
1243- if tempdir is None or not tempdir .is_dir ():
1244- raise OMCSessionException ("Cannot create a temporary directory!" )
1245-
1246- return tempdir
1247-
12481234 def execute (self , command : str ):
12491235 warnings .warn (
12501236 message = "This function is depreciated and will be removed in future versions; "
@@ -1259,7 +1245,7 @@ def sendExpression(self, expr: str, parsed: bool = True) -> Any:
12591245 """
12601246 Send an expression to the OMC server and return the result.
12611247
1262- The complete error handling of the OMC result is done within this method using '" getMessagesStringInternal()'.
1248+ The complete error handling of the OMC result is done within this method using 'getMessagesStringInternal()'.
12631249 Caller should only check for OMCSessionException.
12641250 """
12651251
@@ -1544,6 +1530,8 @@ def __init__(
15441530 raise OMCSessionException ("Invalid definition of the OMC process!" )
15451531 self .omc_process = omc_process
15461532
1533+ super ().__init__ (timeout = timeout )
1534+
15471535 def __del__ (self ):
15481536 if hasattr (self , 'omc_process' ):
15491537 del self .omc_process
@@ -2086,16 +2074,16 @@ def _omc_port_get(self) -> str:
20862074 return port
20872075
20882076
2089- class OMSessionRunner (OMSessionABC ):
2077+ class OMSessionRunnerABC (OMSessionABC , metaclass = abc . ABCMeta ):
20902078 """
20912079 Implementation based on OMSessionABC without any use of an OMC server.
20922080 """
20932081
20942082 def __init__ (
20952083 self ,
2084+ ompath_runner : Type [OMPathRunnerABC ],
20962085 timeout : float = 10.0 ,
20972086 version : str = "1.27.0" ,
2098- ompath_runner : Type [OMPathRunnerABC ] = OMPathRunnerLocal ,
20992087 cmd_prefix : Optional [list [str ]] = None ,
21002088 model_execution_local : bool = True ,
21012089 ) -> None :
@@ -2110,8 +2098,27 @@ def __init__(
21102098 if cmd_prefix is not None :
21112099 self ._cmd_prefix = cmd_prefix
21122100
2113- # TODO: some checking?!
2114- # if ompath_runner == Type[OMPathRunnerBash]:
2101+
2102+ class OMSessionRunner (OMSessionRunnerABC ):
2103+ """
2104+ Implementation based on OMSessionABC without any use of an OMC server.
2105+ """
2106+
2107+ def __init__ (
2108+ self ,
2109+ ompath_runner : Type [OMPathRunnerABC ] = OMPathRunnerLocal ,
2110+ timeout : float = 10.0 ,
2111+ version : str = "1.27.0" ,
2112+ cmd_prefix : Optional [list [str ]] = None ,
2113+ model_execution_local : bool = True ,
2114+ ) -> None :
2115+ super ().__init__ (
2116+ ompath_runner = ompath_runner ,
2117+ timeout = timeout ,
2118+ version = version ,
2119+ cmd_prefix = cmd_prefix ,
2120+ model_execution_local = model_execution_local ,
2121+ )
21152122
21162123 def __post_init__ (self ) -> None :
21172124 """
0 commit comments