Fix problems with tools#145
Conversation
f141318 to
edaf76a
Compare
…t to always resolve these problems manually
…ed with a bad merge confict resolution
- Greatly simplify logic for reading schema file and handling exceptions in that process - Remove unnecessary logic comments
…mments and strings
edaf76a to
4e89dac
Compare
mkavulich
left a comment
There was a problem hiding this comment.
Including some comments to make reviews easier
| return result | ||
|
|
||
| ############################################################################### | ||
| def find_schema_file(schema_root, schema_path=None): |
There was a problem hiding this comment.
Note: this tool is no longer needed since we no longer have the schema version in the filename (#142)
| ############################################################################### | ||
| """Read the XML file, <filename>, and return its tree and root""" | ||
| if os.path.isfile(filename) and os.access(filename, os.R_OK): | ||
| file_open = (lambda x: open(x, 'r')) |
There was a problem hiding this comment.
This logic was simplified as a suggestion from pylint
| #Function to extract standard names from element tree root | ||
| #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
|
||
| def get_dict_stdnames(xml_tree_root): |
There was a problem hiding this comment.
Renamed this function to get_standard_names_as_set to avoid confusion (it returns a set, not a dict)
|
|
||
| #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
|
|
||
| ############ |
There was a problem hiding this comment.
This logic isn't really changed all that much, just moved into function main_func(); choosing the "Hide whitespace" option will make this bit easier to review.
| @@ -0,0 +1,8 @@ | |||
| """Shared utilities for ESM Standard Names tools.""" | |||
There was a problem hiding this comment.
This allows us to import these functions directly from tools in the directory above; note the simplified logic in imports at the top of those scripts.
| #get list of all standard names | ||
| all_std_names = [] | ||
| for name in root.findall('./section/standard_name'): | ||
| for name in root.findall('.//standard_name'): |
There was a problem hiding this comment.
The change that started this whole rabbit hole: we need to check for ALL standard_name entries, not just the top-level ones
| else: | ||
| rm_elements = root.findall(f'.//standard_name[@{args.field}="{dup}"]')[1:] | ||
| print(f"{dup}, ({len(rm_elements)} duplicate(s))") | ||
| if args.overwrite: |
There was a problem hiding this comment.
I made a judgement call here that we always want to manually resolve duplicate entries. Doing it automatically seems prone to error (e.g. they were intended to be separate entries but had the same standard name due to a typo).
| def standard_name_to_description(prop_dict, context=None): | ||
| def standard_name_to_description(prop_dict): | ||
| ######################################################################## | ||
| """Translate a standard_name to its default description |
There was a problem hiding this comment.
These checks were remnants from code originally copied from the framework, and have no function here
| match = _REAL_SUBST_RE.match(description) | ||
| # end while | ||
| else: | ||
| description = '' |
There was a problem hiding this comment.
More logic leftover from ccpp-framework
| file_ok = validate_xml_file(stdname_file, schema_name, | ||
| None, schema_path=schema_root, | ||
| error_on_noxmllint=True) | ||
| except ValueError as valerr: |
There was a problem hiding this comment.
This is convoluted logic to catch an error raised by the validate_xml_file function....it's way simpler and better practice to just let the exception be raised and reference the resulting error trace.
Description
In the process of trying to add a new tool to check for redundant CF name elements (see #143), I found that our existing tools suffer from a number of issues:
This PR resolves those problems. Also, I took the opportunity to clean up the existing tools:
And finally, I added the check for duplicate cfname elements that was the start of this whole process.
Issues
Resolves #118, #144