Skip to content

Commit 21a531b

Browse files
committed
[OMCPath] remove compatibility code for Python < 3.12
1 parent 07eb621 commit 21a531b

File tree

2 files changed

+4
-57
lines changed

2 files changed

+4
-57
lines changed

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

273273

274-
class OMCPathReal(pathlib.PurePosixPath):
274+
class OMCPath(pathlib.PurePosixPath):
275275
"""
276276
Implementation of a basic Path object which uses OMC as backend. The connection to OMC is provided via a
277277
OMCSessionZMQ session object.
@@ -416,46 +416,6 @@ def size(self) -> int:
416416
raise OMCSessionException(f"Error reading file size for path {self.as_posix()}!")
417417

418418

419-
if sys.version_info < (3, 12):
420-
421-
class OMCPathCompatibility(pathlib.Path):
422-
"""
423-
Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
424-
ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
425-
OMCPathCompatibility is based on the standard pathlib.Path implementation.
426-
"""
427-
428-
# modified copy of pathlib.Path.__new__() definition
429-
def __new__(cls, *args, **kwargs):
430-
logger.warning("Python < 3.12 - using a version of class OMCPath "
431-
"based on pathlib.Path for local usage only.")
432-
433-
if cls is OMCPathCompatibility:
434-
cls = OMCPathCompatibilityWindows if os.name == 'nt' else OMCPathCompatibilityPosix
435-
self = cls._from_parts(args)
436-
if not self._flavour.is_supported:
437-
raise NotImplementedError("cannot instantiate %r on your system"
438-
% (cls.__name__,))
439-
return self
440-
441-
def size(self) -> int:
442-
"""
443-
Needed compatibility function to have the same interface as OMCPathReal
444-
"""
445-
return self.stat().st_size
446-
447-
class OMCPathCompatibilityPosix(pathlib.PosixPath, OMCPathCompatibility):
448-
pass
449-
450-
class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
451-
pass
452-
453-
OMCPath = OMCPathCompatibility
454-
455-
else:
456-
OMCPath = OMCPathReal
457-
458-
459419
class OMCSessionZMQ:
460420

461421
def __init__(
@@ -514,16 +474,7 @@ def omcpath(self, *path) -> OMCPath:
514474
"""
515475
Create an OMCPath object based on the given path segments and the current OMC session.
516476
"""
517-
518-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
519-
if sys.version_info < (3, 12):
520-
if isinstance(self.omc_process, OMCProcessLocal):
521-
# noinspection PyArgumentList
522-
return OMCPath(*path)
523-
else:
524-
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCProcessLocal is used!")
525-
else:
526-
return OMCPath(*path, session=self)
477+
return OMCPath(*path, session=self)
527478

528479
def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
529480
"""
@@ -533,11 +484,7 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
533484
names = [str(uuid.uuid4()) for _ in range(100)]
534485

535486
if tempdir_base is None:
536-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
537-
if sys.version_info < (3, 12):
538-
tempdir_str = tempfile.gettempdir()
539-
else:
540-
tempdir_str = self.sendExpression("getTempDirectoryPath()")
487+
tempdir_str = self.sendExpression("getTempDirectoryPath()")
541488
tempdir_base = self.omcpath(tempdir_str)
542489

543490
tempdir: Optional[OMCPath] = None

0 commit comments

Comments
 (0)