@@ -140,15 +140,24 @@ def model(
140140 if not file_path .is_file ():
141141 raise IOError (f"Model file { file_path } does not exist!" )
142142
143- self ._file_name = self .getWorkDirectory () / file_path .name
144- if (isinstance (self ._session , OMCSessionLocal )
145- and file_path .as_posix () == self ._file_name .as_posix ()):
146- pass
147- elif self ._file_name .is_file ():
148- raise IOError (f"Simulation model file { self ._file_name } exist - not overwriting!" )
143+ if isinstance (self ._session , OMCSessionLocal ) and file_path .name == "package.mo" :
144+ # Structured/directory-based package: OMC requires the enclosing
145+ # directory's name to match the package name declared inside
146+ # package.mo, and the package may span sibling .mo files in that
147+ # same directory tree (e.g. Tests/StableBouncingBall.mo). Copying
148+ # just this one file into a randomly-named work directory breaks
149+ # both of those, so load it in place instead.
150+ self ._file_name = self ._session .omcpath (file_path )
149151 else :
150- content = file_path .read_text (encoding = 'utf-8' )
151- self ._file_name .write_text (content )
152+ self ._file_name = self .getWorkDirectory () / file_path .name
153+ if (isinstance (self ._session , OMCSessionLocal )
154+ and file_path .as_posix () == self ._file_name .as_posix ()):
155+ pass
156+ elif self ._file_name .is_file ():
157+ raise IOError (f"Simulation model file { self ._file_name } exist - not overwriting!" )
158+ else :
159+ content = file_path .read_text (encoding = 'utf-8' )
160+ self ._file_name .write_text (content )
152161
153162 if self ._file_name is not None :
154163 self ._loadFile (fileName = self ._file_name )
0 commit comments