Skip to content

Commit

Permalink
Fix handling of file names when loading sibling modules
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianSipos committed Jan 3, 2025
1 parent 324711d commit adcc8a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/ace/adm_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ def get_modules_and_revisions(self, _ctx):
for adm_mod in found.all():
rev = adm_mod.revisions[0].name if adm_mod.revisions else None
result.append((adm_mod.name, rev, ('yang', adm_mod.source_id)))

for file_entry in self._file_entries:
if '@' in file_entry.name:
name, rev = file_entry.name.split('@', 2)
name, ext = os.path.splitext(file_entry.name)
if ext != '.yang':
continue

if '@' in name:
name, rev = name.split('@', 2)
else:
name = file_entry.name
rev = None
result.append((name, rev, ('yang', file_entry.path)))

LOGGER.debug('available modules %s', result)
return result

def get_module_from_handle(self, handle):
Expand All @@ -71,7 +77,7 @@ def get_module_from_handle(self, handle):
file_text = found.file_text
return (found.abs_file_path, 'yang', file_text)
elif isinstance(handle[1], str):
with os.open(handle[1], 'r') as infile:
with open(handle[1], 'r') as infile:
file_text = infile.read()
return (handle, 'yang', file_text)

Expand Down Expand Up @@ -356,8 +362,8 @@ def _read_file(self, dec:adm_yang.Decoder, file_path:str,
)
return mod

LOGGER.debug('Loading ADM from %s', file_path)
try:
LOGGER.debug('Loading ADM from %s', file_path)
with open(file_path, 'r') as adm_file:
adm_new = dec.decode(adm_file)
except Exception as err:
Expand Down
2 changes: 1 addition & 1 deletion src/ace/adm_yang.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def resolve(val):
elif issubclass(cls, (Const, Var)):
value_stmt = search_one_exp(stmt, (AMM_MOD, 'init-value'))
if not value_stmt:
LOGGER.warning('const is missing init-value substatement')
LOGGER.warning('object "%s" is missing init-value substatement', stmt.arg)
else:
obj.init_value = value_stmt.arg
# actually check the content
Expand Down

0 comments on commit adcc8a6

Please sign in to comment.