Skip to content

Commit 7f2b31c

Browse files
committed
fix(IO): support file which doesn't contain an Include tag
1 parent f77168a commit 7f2b31c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

geos-trame/src/geos_trame/app/deck/tree.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@ def write_files( self ):
160160
files = self._split( pb )
161161

162162
for filepath, content in files.items():
163-
includeName: str = self.input_file.xml_parser.file_to_relative_path[ filepath ]
164163
model_loaded: BaseModel = self.decode_data( content )
165164
model_with_changes: BaseModel = self._apply_changed_properties( model_loaded )
166-
self._append_include_file( model_with_changes, includeName )
165+
166+
if self.input_file.xml_parser.contains_include_files():
167+
includeName: str = self.input_file.xml_parser.get_relative_path_of_file( filepath )
168+
self._append_include_file( model_with_changes, includeName )
167169

168170
model_as_xml: str = self.to_xml( model_with_changes )
169171

geos-trame/src/geos_trame/app/io/xml_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ def get_simulation_deck( self ) -> ElementTree.Element:
6161
return
6262
return self.simulation_deck
6363

64+
def contains_include_files( self ) -> bool:
65+
"""
66+
Return True if the parsed file contains included file or not.
67+
"""
68+
return len( self.file_to_relative_path ) > 0
69+
70+
def get_relative_path_of_file( self, filename: str ) -> str:
71+
"""
72+
Return the relative path of a given filename.
73+
"""
74+
return self.file_to_relative_path[ filename ]
75+
6476
def _read( self ) -> ElementTree.Element:
6577
"""Reads an xml file (and recursively its included files) into memory
6678

0 commit comments

Comments
 (0)