Skip to content

Commit d4d230b

Browse files
committed
Merge branch 'remove_deprecated-OMCPath' into v5.0.0-syntron
2 parents 2918597 + 75ded21 commit d4d230b

2 files changed

Lines changed: 3 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: 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
"""
@@ -729,13 +686,6 @@ def omcpath(self, *path) -> OMCPath:
729686
"""
730687
Create an OMCPath object based on the given path segments and the current OMCSession* class.
731688
"""
732-
733-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
734-
if sys.version_info < (3, 12):
735-
if isinstance(self, OMCSessionLocal):
736-
# noinspection PyArgumentList
737-
return OMCPath(*path)
738-
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCSessionLocal is used!")
739689
return OMCPath(*path, session=self)
740690

741691
def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
@@ -746,11 +696,7 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMCPath] = None) -> OMCPath:
746696
names = [str(uuid.uuid4()) for _ in range(100)]
747697

748698
if tempdir_base is None:
749-
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
750-
if sys.version_info < (3, 12):
751-
tempdir_str = tempfile.gettempdir()
752-
else:
753-
tempdir_str = self.sendExpression("getTempDirectoryPath()")
699+
tempdir_str = self.sendExpression("getTempDirectoryPath()")
754700
tempdir_base = self.omcpath(tempdir_str)
755701

756702
tempdir: Optional[OMCPath] = None

0 commit comments

Comments
 (0)