Skip to content

Commit

Permalink
schema_editor: sort listdir output, copy schema before merging (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Dec 4, 2023
1 parent fc890e4 commit 6884f83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Bug Fixes
- Fix ``rebuild_fits_rec_dtype`` handling of unsigned integer columns
with shapes [#213]

- Sort keyword files used for schema_editor to make output non-arbitrary
copy schema before merging to avoid schema modification [#227]

Changes to API
--------------

Expand Down
7 changes: 4 additions & 3 deletions src/stdatamodels/jwst/datamodels/schema_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import argparse
from collections import OrderedDict
import copy
import datetime
import inspect
import os
Expand Down Expand Up @@ -228,7 +229,7 @@ def __init__(self, directory=""):
raise ValueError("Cannot locate keyword database directory")

self.schema = None
for filename in os.listdir(directory):
for filename in sorted(os.listdir(directory)):
if filename.startswith("top."):
keyword_db = os.path.abspath(os.path.join(directory, filename))
schema = aschema.load_schema(keyword_db, resolve_references=False)
Expand Down Expand Up @@ -381,7 +382,7 @@ def merge_enums(merged_subschema, dictionary):
set(dictionary["enum"]))

merged_subschema = OrderedDict()
for dictionary in schema:
for dictionary in copy.deepcopy(schema):
if merged_subschema:
merge_dictionaries(merged_subschema, dictionary)
else:
Expand Down Expand Up @@ -448,7 +449,7 @@ def __init__(self, exclude=None):
'schemas', '')
self.schema_files = []

for filename in os.listdir(self.base_url):
for filename in sorted(os.listdir(self.base_url)):
if filename.endswith(".yaml") and filename not in exclude:
self.schema_files.append(filename)

Expand Down

0 comments on commit 6884f83

Please sign in to comment.