-
Notifications
You must be signed in to change notification settings - Fork 32
test: add golden outputs for docs.bzl scenarios #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlexanderLanin
merged 6 commits into
eclipse-score:main
from
etas-contrib:refactor/docs-bzl-golden-tests
Sep 8, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
59b498a
test: add golden outputs for docs.bzl scenarios
AlexanderLanin 61c6e88
simplify
AlexanderLanin fee5cae
fix css order
AlexanderLanin 01a4a33
fix: keep edit links valid for workspace mounts
AlexanderLanin 88286a3
Merge branch 'main' into refactor/docs-bzl-golden-tests
AlexanderLanin b561fd8
update html/css
AlexanderLanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,10 @@ | |
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
| import logging | ||
| import os | ||
| from pathlib import Path | ||
| from typing import Any | ||
| from typing import Any, cast | ||
| from urllib.parse import quote | ||
|
|
||
| import html_options | ||
| import sphinx_options | ||
|
|
@@ -22,11 +24,33 @@ | |
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # TEMP UNTIL UPSTREAM FIX - BEGIN | ||
| # Bug ref: https://github.com/useblocks/sphinx-needs/issues/1913 | ||
| # Sphinx-Needs discovers these files with ``Path.glob``. The filesystem | ||
| # does not define the order returned by that operation, while Sphinx preserves | ||
| # registration order for stylesheets with the same priority. Keep the CSS | ||
| # cascade stable across Bazel runfiles, local virtual environments, and CI. | ||
| _NEEDS_COMMON_CSS_ORDER = ( | ||
| "sphinx-needs/common_css/needstable.css", | ||
| "sphinx-needs/common_css/need_core.css", | ||
| "sphinx-needs/common_css/need_style.css", | ||
| "sphinx-needs/common_css/need_toggle.css", | ||
| "sphinx-needs/common_css/need_links.css", | ||
| ) | ||
| _NEEDS_COMMON_CSS_POSITION = { | ||
| filename: position for position, filename in enumerate(_NEEDS_COMMON_CSS_ORDER) | ||
| } | ||
| # TEMP UNTIL UPSTREAM FIX - END | ||
|
|
||
|
|
||
| def setup(app: Sphinx) -> dict[str, str | bool]: | ||
| logger.debug("score_layout setup called") | ||
|
|
||
| app.connect("config-inited", update_config) | ||
| # Run after the PyData theme creates its edit-URL callback so mounted pages | ||
| # can replace the callback with a workspace-aware one. | ||
| app.connect("html-page-context", configure_mounted_source_controls, priority=800) | ||
| app.connect("html-page-context", normalize_needs_css_order) | ||
| return { | ||
| "version": "0.1", | ||
| "parallel_read_safe": True, | ||
|
|
@@ -68,3 +92,120 @@ def update_config(app: Sphinx, _config: Any): | |
| app.add_css_file("css/score.css", priority=500) | ||
| app.add_css_file("css/score_needs.css", priority=500) | ||
| app.add_css_file("css/score_design.css", priority=500) | ||
|
|
||
|
|
||
| # TEMP UNTIL UPSTREAM FIX - BEGIN | ||
| # Bug ref: https://github.com/useblocks/sphinx-mounts/issues/47 | ||
| def configure_mounted_source_controls( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be in this PR?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need that to generate identical html every time, as currently |
||
| app: Sphinx, | ||
| pagename: str, | ||
| _templatename: str, | ||
| context: dict[str, Any], | ||
| _doctree: Any, | ||
| ) -> None: | ||
| """Configure safe source/edit controls for mounted documents. | ||
|
|
||
| ``sphinx-mounts`` stores the absolute filesystem path of a mounted source | ||
| in Sphinx. Sphinx currently derives ``page_source_suffix`` from that path, | ||
| which makes themes such as PyData build malformed source and edit URLs. | ||
| A real source file inside the current workspace can still be mapped to a | ||
| safe repository-relative URL. Generated and external sources have no such | ||
| guaranteed URL, so their controls remain hidden until the mount extension | ||
| exposes a logical source path and repository mapping. | ||
| """ | ||
| source_path = Path(app.env.doc2path(pagename, base=False)) | ||
| if not source_path.is_absolute(): | ||
| return | ||
|
|
||
| source_path = source_path.resolve() | ||
| workspace_directory = os.environ.get("BUILD_WORKSPACE_DIRECTORY") | ||
| if workspace_directory: | ||
| workspace_root = Path(workspace_directory).resolve() | ||
| if ( | ||
| source_path.is_relative_to(workspace_root) | ||
| and not {"bazel-bin", "bazel-out"}.intersection(source_path.parts) | ||
| and _configure_workspace_edit_url(context, source_path, workspace_root) | ||
| ): | ||
| return | ||
|
|
||
| context["page_source_suffix"] = "" | ||
| context["sourcename"] = "" | ||
| context["secondary_sidebar_items"] = [] | ||
|
|
||
|
|
||
| def _configure_workspace_edit_url( | ||
| context: dict[str, Any], source_path: Path, workspace_root: Path | ||
| ) -> bool: | ||
| """Install a GitHub edit callback for a source file in the workspace.""" | ||
| if context.get("edit_page_url_template") is not None: | ||
| return False | ||
|
|
||
| github_values = tuple( | ||
| context.get(name) for name in ("github_user", "github_repo", "github_version") | ||
| ) | ||
| if not all( | ||
| isinstance(value, str) and value not in {"", "dummy", "None"} | ||
| for value in github_values | ||
| ): | ||
| return False | ||
|
|
||
| github_user, github_repo, github_version = cast(tuple[str, str, str], github_values) | ||
| relative_path = quote(source_path.relative_to(workspace_root).as_posix(), safe="/") | ||
| github_url = str(context.get("github_url", "https://github.com")).rstrip("/") | ||
| edit_url = ( | ||
| f"{github_url}/{quote(github_user, safe='')}/{quote(github_repo, safe='')}" | ||
| f"/edit/{quote(github_version, safe='')}/{relative_path}" | ||
| ) | ||
|
|
||
| def get_edit_provider_and_url() -> tuple[str, str]: | ||
| """Return the edit URL for the mounted workspace source.""" | ||
| return "GitHub", edit_url | ||
|
|
||
| context["get_edit_provider_and_url"] = get_edit_provider_and_url | ||
| return True | ||
|
|
||
|
|
||
| # TEMP UNTIL UPSTREAM FIX - END | ||
|
|
||
|
|
||
| # TEMP UNTIL UPSTREAM FIX - BEGIN | ||
| # Bug ref: https://github.com/useblocks/sphinx-needs/issues/1913 | ||
| def normalize_needs_css_order( | ||
| _app: Sphinx, | ||
| _pagename: str, | ||
| _templatename: str, | ||
| context: dict[str, Any], | ||
| _doctree: Any, | ||
| ) -> None: | ||
| """Make Sphinx-Needs common stylesheets deterministic before rendering.""" | ||
| css_files = context.get("css_files") | ||
| if not isinstance(css_files, list): | ||
| return | ||
| css_files = cast(list[Any], css_files) | ||
|
|
||
| common_css = [ | ||
| (index, css_file) | ||
| for index, css_file in enumerate(css_files) | ||
| if _css_filename(css_file) in _NEEDS_COMMON_CSS_POSITION | ||
| ] | ||
| if len(common_css) < 2: | ||
| return | ||
|
|
||
| positions = [index for index, _ in common_css] | ||
| ordered_common_css = sorted( | ||
| (css_file for _, css_file in common_css), | ||
| key=lambda css_file: _NEEDS_COMMON_CSS_POSITION[_css_filename(css_file)], | ||
| ) | ||
| normalized_css_files = list(css_files) | ||
| for index, css_file in zip(positions, ordered_common_css, strict=True): | ||
| normalized_css_files[index] = css_file | ||
| context["css_files"] = normalized_css_files | ||
|
|
||
|
|
||
| def _css_filename(css_file: Any) -> str: | ||
| """Return a stylesheet's path in the form used by Sphinx-Needs.""" | ||
| filename = str(os.fspath(getattr(css_file, "filename", css_file))) | ||
| return Path(filename).as_posix().removeprefix("_static/") | ||
|
|
||
|
|
||
| # TEMP UNTIL UPSTREAM FIX - END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not quiet understand this marker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea was to run fast tests first and then the slow tests. however "fast" is not quite true. They are only fast because mostly they are cached. So I ended up with "cached" and "slow". Those are horrible categories, but so far I dont have a better approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But they are only cached on second run right?