Skip to content

Commit 75ded21

Browse files
committed
[OMCPath] remove compatibility code for Python < 3.12
1 parent b1aba64 commit 75ded21

File tree

2 files changed

+3
-57
lines changed

2 files changed

+3
-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: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
284284
return self._ask(question='getClassNames', opt=opt)
285285

286286

287-
class OMCPathReal(pathlib.PurePosixPath):
287+
class OMCPath(pathlib.PurePosixPath):
288288
"""
289289
Implementation of a basic (PurePosix)Path object which uses OMC as backend. The connection to OMC is provided via an
290290
instances of OMCSession* classes.
@@ -450,49 +450,6 @@ def stat(self):
450450
"use size() to get the file size.")
451451

452452

453-
if sys.version_info < (3, 12):
454-
455-
class OMCPathCompatibility(pathlib.Path):
456-
"""
457-
Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
458-
ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
459-
OMCPathCompatibility is based on the standard pathlib.Path implementation.
460-
"""
461-
462-
# modified copy of pathlib.Path.__new__() definition
463-
def __new__(cls, *args, **kwargs):
464-
logger.warning("Python < 3.12 - using a version of class OMCPath "
465-
"based on pathlib.Path for local usage only.")
466-
467-
if cls is OMCPathCompatibility:
468-
cls = OMCPathCompatibilityWindows if os.name == 'nt' else OMCPathCompatibilityPosix
469-
self = cls._from_parts(args)
470-
if not self._flavour.is_supported:
471-
raise NotImplementedError(f"cannot instantiate {cls.__name__} on your system")
472-
return self
473-
474-
def size(self) -> int:
475-
"""
476-
Needed compatibility function to have the same interface as OMCPathReal
477-
"""
478-
return self.stat().st_size
479-
480-
class OMCPathCompatibilityPosix(pathlib.PosixPath, OMCPathCompatibility):
481-
"""
482-
Compatibility class for OMCPath on Posix systems (Python < 3.12)
483-
"""
484-
485-
class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
486-
"""
487-
Compatibility class for OMCPath on Windows systems (Python < 3.12)
488-
"""
489-
490-
OMCPath = OMCPathCompatibility
491-
492-
else:
493-
OMCPath = OMCPathReal
494-
495-
496453
@dataclasses.dataclass
497454
class OMCSessionRunData:
498455
"""
@@ -805,13 +762,6 @@ def omcpath(self, *path) -> OMCPath:
805762
"""
806763
Create an OMCPath object based on the given path segments and the current OMCSession* class.
807764
"""
808-
809-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
810-
if sys.version_info < (3, 12):
811-
if isinstance(self, OMCSessionLocal):
812-
# noinspection PyArgumentList
813-
return OMCPath(*path)
814-
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCSessionLocal is used!")
815765
return OMCPath(*path, session=self)
816766

817767
def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
@@ -822,11 +772,7 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
822772
names = [str(uuid.uuid4()) for _ in range(100)]
823773

824774
if tempdir_base is None:
825-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
826-
if sys.version_info < (3, 12):
827-
tempdir_str = tempfile.gettempdir()
828-
else:
829-
tempdir_str = self.sendExpression("getTempDirectoryPath()")
775+
tempdir_str = self.sendExpression("getTempDirectoryPath()")
830776
tempdir_base = self.omcpath(tempdir_str)
831777

832778
tempdir: Optional[OMCPath] = None

0 commit comments

Comments
 (0)