Description
scripts/convertWellSchema.py removes every comment from the deck it converts. The loss is silent: the script reports XSD validation passed and the output is valid, so nothing signals that anything was lost.
GEOS decks use comments to record why a value was chosen — a solver tolerance, a rate derivation, the identity of a saturation table. None of that is recoverable from the output.
Root cause
The script reads the deck with xml.etree.ElementTree, which discards comments by default. Three call sites are affected:
update_constraint_element() — line 100
removeUseMass() — line 301
add_we() — line 323
All three call tree = ET.parse(xml_file).
A second, separate loss affects the prolog. xml.etree keeps no node before the root element, so a header comment before <Problem> is dropped even after the parser is fixed.
Steps to reproduce
- Take any deck with
<WellControls> and at least one comment.
- Run
python3 scripts/convertWellSchema.py -s deck.xml -t out.xml --xsd src/coreComponents/schema/schema.xsd.
- Compare
grep -c '<!--' deck.xml with grep -c '<!--' out.xml.
Observed on two decks: 3 comments to 0, and 5 comments to 0.
Suggested fix
- Pass a comment-preserving parser at the three call sites:
ET.XMLParser(target=ET.TreeBuilder(insert_comments=True)).
- Read the prolog comments with
lxml before the conversion writes anything, then put them back afterwards. The read must come first, because --replace is the default and the source and the target are then the same file.
A PR follows.
Environment
GEOS develop at 24a8410, Python 3.11, lxml 6.1.2.
Description
scripts/convertWellSchema.pyremoves every comment from the deck it converts. The loss is silent: the script reportsXSD validation passedand the output is valid, so nothing signals that anything was lost.GEOS decks use comments to record why a value was chosen — a solver tolerance, a rate derivation, the identity of a saturation table. None of that is recoverable from the output.
Root cause
The script reads the deck with
xml.etree.ElementTree, which discards comments by default. Three call sites are affected:update_constraint_element()— line 100removeUseMass()— line 301add_we()— line 323All three call
tree = ET.parse(xml_file).A second, separate loss affects the prolog.
xml.etreekeeps no node before the root element, so a header comment before<Problem>is dropped even after the parser is fixed.Steps to reproduce
<WellControls>and at least one comment.python3 scripts/convertWellSchema.py -s deck.xml -t out.xml --xsd src/coreComponents/schema/schema.xsd.grep -c '<!--' deck.xmlwithgrep -c '<!--' out.xml.Observed on two decks: 3 comments to 0, and 5 comments to 0.
Suggested fix
ET.XMLParser(target=ET.TreeBuilder(insert_comments=True)).lxmlbefore the conversion writes anything, then put them back afterwards. The read must come first, because--replaceis the default and the source and the target are then the same file.A PR follows.
Environment
GEOS
developat 24a8410, Python 3.11, lxml 6.1.2.