Skip to content

Commit ffd5cc8

Browse files
committed
Merge branch 'remove_deprecated-OMCPath' into v5.0.0-syntron4
2 parents 459e28d + 329078b commit ffd5cc8

2 files changed

Lines changed: 4 additions & 57 deletions

File tree

.github/workflows/Test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
timeout-minutes: 30
1515
strategy:
1616
matrix:
17-
python-version: ['3.10', '3.12', '3.13']
17+
python-version: ['3.12', '3.13']
1818
os: ['ubuntu-latest', 'windows-latest']
1919
omc-version: ['stable', 'nightly']
2020

OMPython/OMCSession.py

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
274274
return self._ask(question='getClassNames', opt=opt)
275275

276276

277-
class OMCPathReal(pathlib.PurePosixPath):
277+
class OMCPath(pathlib.PurePosixPath):
278278
"""
279279
Implementation of a basic (PurePosix)Path object which uses OMC as backend. The connection to OMC is provided via a
280280
OMCSessionZMQ session object.
@@ -440,46 +440,6 @@ def stat(self):
440440
"use size() to get the file size.")
441441

442442

443-
if sys.version_info < (3, 12):
444-
445-
class OMCPathCompatibility(pathlib.Path):
446-
"""
447-
Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
448-
ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
449-
OMCPathCompatibility is based on the standard pathlib.Path implementation.
450-
"""
451-
452-
# modified copy of pathlib.Path.__new__() definition
453-
def __new__(cls, *args, **kwargs):
454-
logger.warning("Python < 3.12 - using a version of class OMCPath "
455-
"based on pathlib.Path for local usage only.")
456-
457-
if cls is OMCPathCompatibility:
458-
cls = OMCPathCompatibilityWindows if os.name == 'nt' else OMCPathCompatibilityPosix
459-
self = cls._from_parts(args)
460-
if not self._flavour.is_supported:
461-
raise NotImplementedError("cannot instantiate %r on your system"
462-
% (cls.__name__,))
463-
return self
464-
465-
def size(self) -> int:
466-
"""
467-
Needed compatibility function to have the same interface as OMCPathReal
468-
"""
469-
return self.stat().st_size
470-
471-
class OMCPathCompatibilityPosix(pathlib.PosixPath, OMCPathCompatibility):
472-
pass
473-
474-
class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
475-
pass
476-
477-
OMCPath = OMCPathCompatibility
478-
479-
else:
480-
OMCPath = OMCPathReal
481-
482-
483443
@dataclasses.dataclass
484444
class OMCSessionRunData:
485445
"""
@@ -586,16 +546,7 @@ def omcpath(self, *path) -> OMCPath:
586546
"""
587547
Create an OMCPath object based on the given path segments and the current OMC session.
588548
"""
589-
590-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
591-
if sys.version_info < (3, 12):
592-
if isinstance(self.omc_process, OMCProcessLocal):
593-
# noinspection PyArgumentList
594-
return OMCPath(*path)
595-
else:
596-
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCProcessLocal is used!")
597-
else:
598-
return OMCPath(*path, session=self)
549+
return OMCPath(*path, session=self)
599550

600551
def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
601552
"""
@@ -605,11 +556,7 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
605556
names = [str(uuid.uuid4()) for _ in range(100)]
606557

607558
if tempdir_base is None:
608-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
609-
if sys.version_info < (3, 12):
610-
tempdir_str = tempfile.gettempdir()
611-
else:
612-
tempdir_str = self.sendExpression("getTempDirectoryPath()")
559+
tempdir_str = self.sendExpression("getTempDirectoryPath()")
613560
tempdir_base = self.omcpath(tempdir_str)
614561

615562
tempdir: Optional[OMCPath] = None

0 commit comments

Comments
 (0)