Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: ['3.10', '3.12', '3.13']
python-version: ['3.12', '3.13']
os: ['ubuntu-latest', 'windows-latest']
omc-version: ['stable', 'nightly']

Expand Down
59 changes: 3 additions & 56 deletions OMPython/OMCSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
return self._ask(question='getClassNames', opt=opt)


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


if sys.version_info < (3, 12):

class OMCPathCompatibility(pathlib.Path):
"""
Compatibility class for OMCPath in Python < 3.12. This allows to run all code which uses OMCPath (mainly
ModelicaSystem) on these Python versions. There is one remaining limitation: only OMCProcessLocal will work as
OMCPathCompatibility is based on the standard pathlib.Path implementation.
"""

# modified copy of pathlib.Path.__new__() definition
def __new__(cls, *args, **kwargs):
logger.warning("Python < 3.12 - using a version of class OMCPath "
"based on pathlib.Path for local usage only.")

if cls is OMCPathCompatibility:
cls = OMCPathCompatibilityWindows if os.name == 'nt' else OMCPathCompatibilityPosix
self = cls._from_parts(args)
if not self._flavour.is_supported:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
return self

def size(self) -> int:
"""
Needed compatibility function to have the same interface as OMCPathReal
"""
return self.stat().st_size

class OMCPathCompatibilityPosix(pathlib.PosixPath, OMCPathCompatibility):
pass

class OMCPathCompatibilityWindows(pathlib.WindowsPath, OMCPathCompatibility):
pass

OMCPath = OMCPathCompatibility

else:
OMCPath = OMCPathReal


class OMCSessionZMQ:

def __init__(
Expand Down Expand Up @@ -514,16 +474,7 @@ def omcpath(self, *path) -> OMCPath:
"""
Create an OMCPath object based on the given path segments and the current OMC session.
"""

# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
if sys.version_info < (3, 12):
if isinstance(self.omc_process, OMCProcessLocal):
# noinspection PyArgumentList
return OMCPath(*path)
else:
raise OMCSessionException("OMCPath is supported for Python < 3.12 only if OMCProcessLocal is used!")
else:
return OMCPath(*path, session=self)
return OMCPath(*path, session=self)

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

if tempdir_base is None:
# fallback solution for Python < 3.12; a modified pathlib.Path object is used as OMCPath replacement
if sys.version_info < (3, 12):
tempdir_str = tempfile.gettempdir()
else:
tempdir_str = self.sendExpression("getTempDirectoryPath()")
tempdir_str = self.sendExpression("getTempDirectoryPath()")
tempdir_base = self.omcpath(tempdir_str)

tempdir: Optional[OMCPath] = None
Expand Down