Skip to content

Commit ef68951

Browse files
committed
Merge branch 'remove_deprecated-OMCPath' into v5.0.0-syntron
2 parents eb2bf7e + 21a531b commit ef68951

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
@@ -275,7 +275,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
275275
return self._ask(question='getClassNames', opt=opt)
276276

277277

278-
class OMCPathReal(pathlib.PurePosixPath):
278+
class OMCPath(pathlib.PurePosixPath):
279279
"""
280280
Implementation of a basic Path object which uses OMC as backend. The connection to OMC is provided via a
281281
OMCSessionZMQ session object.
@@ -420,46 +420,6 @@ def size(self) -> int:
420420
raise OMCSessionException(f"Error reading file size for path {self.as_posix()}!")
421421

422422

423-
if sys.version_info < (3, 12):
424-
425-
class OMCPathCompatibility(pathlib.Path):
426-
"""
427-
Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
428-
ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
429-
OMCPathCompatibility is based on the standard pathlib.Path implementation.
430-
"""
431-
432-
# modified copy of pathlib.Path.__new__() definition
433-
def __new__(cls, *args, **kwargs):
434-
logger.warning("Python < 3.12 - using a version of class OMCPath "
435-
"based on pathlib.Path for local usage only.")
436-
437-
if cls is OMCPathCompatibility:
438-
cls = OMCPathCompatibilityWindows if os.name == 'nt' else OMCPathCompatibilityPosix
439-
self = cls._from_parts(args)
440-
if not self._flavour.is_supported:
441-
raise NotImplementedError("cannot instantiate %r on your system"
442-
% (cls.__name__,))
443-
return self
444-
445-
def size(self) -> int:
446-
"""
447-
Needed compatibility function to have the same interface as OMCPathReal
448-
"""
449-
return self.stat().st_size
450-
451-
class OMCPathCompatibilityPosix(pathlib.PosixPath, OMCPathCompatibility):
452-
pass
453-
454-
class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
455-
pass
456-
457-
OMCPath = OMCPathCompatibility
458-
459-
else:
460-
OMCPath = OMCPathReal
461-
462-
463423
@dataclasses.dataclass
464424
class OMCSessionRunData:
465425
"""
@@ -559,16 +519,7 @@ def omcpath(self, *path) -> OMCPath:
559519
"""
560520
Create an OMCPath object based on the given path segments and the current OMC session.
561521
"""
562-
563-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
564-
if sys.version_info < (3, 12):
565-
if isinstance(self.omc_process, OMCProcessLocal):
566-
# noinspection PyArgumentList
567-
return OMCPath(*path)
568-
else:
569-
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCProcessLocal is used!")
570-
else:
571-
return OMCPath(*path, session=self)
522+
return OMCPath(*path, session=self)
572523

573524
def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
574525
"""
@@ -578,11 +529,7 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
578529
names = [str(uuid.uuid4()) for _ in range(100)]
579530

580531
if tempdir_base is None:
581-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
582-
if sys.version_info < (3, 12):
583-
tempdir_str = tempfile.gettempdir()
584-
else:
585-
tempdir_str = self.sendExpression("getTempDirectoryPath()")
532+
tempdir_str = self.sendExpression("getTempDirectoryPath()")
586533
tempdir_base = self.omcpath(tempdir_str)
587534

588535
tempdir: Optional[OMCPath] = None

0 commit comments

Comments
 (0)