@@ -218,33 +218,32 @@ def _expand_helper(self, search_paths: typing.List[str], recurse: bool) -> typin
218
218
search_paths .append (keyword .filename )
219
219
keywords .append (keyword )
220
220
continue
221
- success = False
221
+ expand_include_file = None
222
222
for search_path in search_paths :
223
223
include_file = os .path .join (search_path , keyword .filename )
224
- if not os .path .isfile (include_file ):
225
- continue
226
- xform = None
227
- if keyword .subkeyword == "TRANSFORM" :
228
- xform = keyword
229
- context = ImportContext (xform , self , include_file )
230
- try :
231
- include_deck = self ._prepare_deck_for_expand (keyword )
232
- include_deck ._import_file (include_file , "utf-8" , context )
233
- except UnicodeDecodeError as e :
234
- encoding = self ._detect_encoding (include_file )
235
- include_deck = self ._prepare_deck_for_expand (keyword )
236
- include_deck ._import_file (include_file , encoding , context )
237
- success = True
238
- break
239
- if success :
240
- if recurse :
241
- # TODO: merge the parameters if the "LOCAL" option is not used!
242
- expanded = include_deck ._expand_helper (search_paths , True )
243
- keywords .extend (expanded )
244
- else :
245
- keywords .extend (include_deck .all_keywords )
246
- else :
224
+ if os .path .isfile (include_file ):
225
+ expand_include_file = include_file
226
+ break
227
+ if expand_include_file is None :
247
228
keywords .append (keyword )
229
+ continue
230
+ xform = None
231
+ if keyword .subkeyword == "TRANSFORM" :
232
+ xform = keyword
233
+ context = ImportContext (xform , self , expand_include_file )
234
+ try :
235
+ include_deck = self ._prepare_deck_for_expand (keyword )
236
+ include_deck ._import_file (expand_include_file , "utf-8" , context )
237
+ except UnicodeDecodeError as e :
238
+ encoding = self ._detect_encoding (expand_include_file )
239
+ include_deck = self ._prepare_deck_for_expand (keyword )
240
+ include_deck ._import_file (expand_include_file , encoding , context )
241
+ if recurse :
242
+ # TODO: merge the parameters if the "LOCAL" option is not used!
243
+ expanded = include_deck ._expand_helper (search_paths , True )
244
+ keywords .extend (expanded )
245
+ else :
246
+ keywords .extend (include_deck .all_keywords )
248
247
for keyword in keywords :
249
248
if isinstance (keyword , KeywordBase ):
250
249
keyword .deck = None
@@ -505,7 +504,10 @@ def _import_file(self, path: str, encoding: str, context: ImportContext):
505
504
from ansys .dyna .core .lib .deck_loader import load_deck_from_buffer
506
505
507
506
with open (path , encoding = encoding ) as f :
508
- return load_deck_from_buffer (self , f , context , self ._import_handlers )
507
+ loader_result = load_deck_from_buffer (self , f , context , self ._import_handlers )
508
+ for keyword in self .keywords :
509
+ keyword .included_from = path
510
+ return loader_result
509
511
510
512
def import_file (
511
513
self , path : str , encoding : str = "utf-8"
0 commit comments