Support @include directives in QSS templates - #14101
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## implement-basis-for-new-styling #14101 +/- ##
================================================================
Coverage 91.93% 91.93%
================================================================
Files 483 483
Lines 33505 33525 +20
================================================================
+ Hits 30802 30822 +20
Misses 2703 2703
Flags with carried forward coverage won't be shown. Click here to find out more.
|
369c272 to
0cbf763
Compare
0cbf763 to
c3b669d
Compare
c3b669d to
ec20c7f
Compare
ec20c7f to
8abd255
Compare
There was a problem hiding this comment.
Pull request overview
Adds support for @include "…" directives in QSS template processing so GUI styling can be split across multiple .qss.in files while still using design-token substitution.
Changes:
- Introduce
resolve_includes()to expand@include "file.qss.in"directives (including nested includes) and detect circular references. - Update
process_qss()to resolve includes before token substitution. - Move/extend unit tests to cover include resolution behavior and keep resource-reading tests centralized.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/ert/gui/theme_manager/qss_processing.py |
Adds include-resolution pre-pass and integrates it into QSS processing. |
tests/ert/unit_tests/gui/theme_manager/test_qss_processing.py |
Adds unit tests for include resolution (multiple, nested, circular, missing). |
tests/ert/unit_tests/gui/theme_manager/test_theme_utils.py |
Relocates and keeps tests for read_qss_stylesheet_file() behavior. |
| _TOKEN_PATTERN = re.compile(r"\{\{([a-z0-9\-]+)\}\}") | ||
| _INCLUDE_PATTERN = re.compile(r'^@include\s+"(.+?)"', re.MULTILINE) | ||
|
|
||
| _BASE_TEMPLATE = "base" |
8abd255 to
75e7ef8
Compare
75e7ef8 to
0b4c9f6
Compare
0b4c9f6 to
32a599e
Compare
|
Screenshots differ from baselines. A baseline update PR has been prepared: equinor/ert-testdata#80 |
Allow a .qss.in template to pull in another with @include "nav.qss.in", so styling can be split per GUI area instead of living in one file. Includes are resolved before token substitution, so included files use {{token}} placeholders exactly like the base template. Includes may nest; circular references raise QssProcessingError instead of recursing until the stack is exhausted.
read_qss_stylesheet_file only names a resource and delegates to read_theming_resource, so its tests belong with the other resource loader tests rather than among the template processing ones.
32a599e to
da0b629
Compare
|
Screenshot tests now pass. The baseline update PR equinor/ert-testdata#80 has been closed. |
| for match in _INCLUDE_LIKE_PATTERN.finditer(template): | ||
| line = match.group(0) | ||
| if not _INCLUDE_PATTERN.fullmatch(line): | ||
| raise QssProcessingError( | ||
| f"Malformed @include directive: {line.strip()}. " | ||
| 'Expected the form: @include "name.qss.in"' | ||
| ) |
There was a problem hiding this comment.
Do we need to separate the two pattern checks? What happens if we just use _INCLUDE_PATTERN from the start?
There was a problem hiding this comment.
What are the pros/cons of having multiple .qss.in? Do we have enough components to that we need the added complexity of having between-qss communication?
Issue
Resolves #14103
Approach
Stacked on #14100 so that needs to be reviewed first.
base.qss.inholds styling for the whole GUI, which won't scale. Adds@include "nav.qss.in"so stylesheets can be split per GUI area. Includes are resolved before token substitution, so included files use{{token}}like the base template.Includes may nest; circular references raise
QssProcessingErrorinstead of recursing until the stack is exhausted.No visual change,
base.qss.inuses no includes yet, so the rendered stylesheet is unchanged.git rebase -i main --exec 'just rapid-tests')When applicable
merge screenshot-PR in ert-testdata before merging this PR.