Skip to content

Commit 5c1d3e4

Browse files
committed
[OMCPath] remove compatibility code for Python < 3.12
1 parent a620870 commit 5c1d3e4

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 (PurePosix)Path object which uses OMC as backend. The connection to OMC is provided via a
281281
OMCSessionZMQ session object.
@@ -441,46 +441,6 @@ def stat(self):
441441
"use size() to get the file size.")
442442

443443

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

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

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

616563
tempdir: Optional[OMCPath] = None

0 commit comments

Comments
 (0)