Skip to content

Add mxspec.py specification script#2997

Merged
jstone-lucasfilm merged 3 commits into
AcademySoftwareFoundation:mainfrom
jstone-lucasfilm:dev_mxspec_script
Jul 11, 2026
Merged

Add mxspec.py specification script#2997
jstone-lucasfilm merged 3 commits into
AcademySoftwareFoundation:mainfrom
jstone-lucasfilm:dev_mxspec_script

Conversation

@jstone-lucasfilm

Copy link
Copy Markdown
Member

This changelist adds an mxspec.py script for processing MaterialX specification documents, replacing the comparenodedefs.py script with a more general tool that supports three subcommands:

  • compare: Compare node definitions between a specification document and a data library document, reporting differences in node sets, typed signatures, and default values.
  • normalize: Normalize table formatting and default value notation, aligning columns and converting defaults to canonical placeholders such as __zero__ and __one__.
  • expand: Expand polymorphic tables into concrete per-signature tables, with an optional --nodedefs flag that adds nodedef name subheaders from the standard libraries.

GitHub CI additionally compares the NPR Nodes specification against its data library on each commit, extending the trackable alignment history already maintained for the Standard and PBR Nodes.

This work was developed as a collaboration between the AOUSD Materials Working Group and the ASWF.

This changelist adds an `mxspec.py` script for processing MaterialX specification documents, replacing the `comparenodedefs.py` script with a more general tool that supports three subcommands:

- `compare`: Compare node definitions between a specification document and a data library document, reporting differences in node sets, typed signatures, and default values.
- `normalize`: Normalize table formatting and default value notation, aligning columns and converting defaults to canonical placeholders such as `__zero__` and `__one__`.
- `expand`: Expand polymorphic tables into concrete per-signature tables, with an optional `--nodedefs` flag that adds nodedef name subheaders from the standard libraries.

GitHub CI additionally compares the NPR Nodes specification against its data library on each commit, extending the trackable alignment history already maintained for the Standard and PBR Nodes.

This work was developed as a collaboration between the AOUSD Materials Working Group and the ASWF.

@ashwinbhat ashwinbhat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I was wondering if we should add some notes about markdown layout requirements since we are parsing table cells.

Following up on review notes from Ashwin Bhat, this changelist adds reporting of specification parsing warnings, such as column count mismatches, when running the `normalize` and `expand` subcommands of `mxspec.py`, matching the diagnostics already reported by `compare`.
@jstone-lucasfilm

Copy link
Copy Markdown
Member Author

This is a great point, @ashwinbhat, and I've now added clearer reporting of parser warnings across all of the commands, so that any mismatches in conventions are surfaced to the user.

We could add explicit documentation of our Markdown conventions as well, but my concern would be that we're then creating two distinct homes for these conventions (the specification documents and our supporting Python scripts), which would then need to be kept in sync over time.

@kwokcb kwokcb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.
Some minor comments in matching.


A general observation:

  • I'm curious if instead of markdown formatted tables it would be easier to use
    html instead.
  • Then it's much easier to parse (especially if you tag the tables with metadata), though a bit more trouble to write.

Comment thread python/Scripts/mxspec.py
signatures = {}
specDefaults = {}
for nodeName, tables in nodeSections.items():
sigs = signatures.setdefault(nodeName, set())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but I think you'd want to get defaults based on the per table item's defaults ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and fixed!

Comment thread python/Scripts/mxspec.py

extraInLib = tuple(sorted(libInputs - specInputs))
extraInSpec = tuple(sorted(specInputs - libInputs))
return libSig, extraInLib, extraInSpec

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this just return the first one vs comparing all matches ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the exact match pass above handles most cases, and this fallback pass uses fuzzy matching and returns the first one. So far, I don't believe we have any real-world cases where there's more than one fuzzy match, so this works well, but indeed we could revisit this if such a case appears in the future.

Following up on review feedback from Bernard Kwok, this changelist keys specification defaults by node and signature, mirroring the structure of data library defaults, so that each expanded signature is compared against the defaults from its own specification table.
@jstone-lucasfilm

Copy link
Copy Markdown
Member Author

A general observation:

  • I'm curious if instead of markdown formatted tables it would be easier to use
    html instead.
  • Then it's much easier to parse (especially if you tag the tables with metadata), though a bit more trouble to write.

Agreed that HTML would be easier to parse, though I'd lean towards Markdown here since the specifications are hand-authored and reviewed in pull requests, where Markdown tables remain readable in raw text and diffs.

The normalize subcommand is meant to address the parsing side of this tradeoff by keeping tables in a canonical form, and if we need table metadata down the road, HTML comments within the Markdown could carry it without changing the rendered document.

@jstone-lucasfilm jstone-lucasfilm merged commit 38368ee into AcademySoftwareFoundation:main Jul 11, 2026
36 checks passed
@jstone-lucasfilm jstone-lucasfilm deleted the dev_mxspec_script branch July 11, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants