-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PlantUML can be used to draw images, especially uml-like images. Signed-off-by: Alexander Lanin <[email protected]>
- Loading branch information
1 parent
edb023b
commit 49d8db4
Showing
15 changed files
with
375 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1 +1,6 @@ | ||
build --java_language_version=17 | ||
build --tool_java_language_version=17 | ||
build --java_runtime_version=remotejdk_17 | ||
build --tool_java_runtime_version=remotejdk_17 | ||
|
||
test --test_output=errors |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# ******************************************************************************* | ||
# Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# ******************************************************************************* | ||
"""intentionally empty""" |
This file contains 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ******************************************************************************* | ||
# Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# ******************************************************************************* | ||
|
||
""" | ||
This extension sets up PlantUML within the SCORE Bazel environment. | ||
The complexity arises, as the plantuml binary is only available through Bazel. | ||
However going through `bazel run //docs:plantuml` for every PlantUML diagram | ||
is simply too slow. | ||
This extension determines the path to the plantuml binary and sets it up in the | ||
Sphinx configuration. | ||
In addition it sets common PlantUML options, like output to svg_obj. | ||
""" | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
from sphinx.application import Sphinx | ||
from sphinx.util import logging | ||
|
||
try: | ||
from python.runfiles import Runfiles | ||
except ImportError: | ||
sys.exit( | ||
"ERROR: This script must be run from within the virtual environment " | ||
"which can be generated by `bazel run //docs:ide_support`. " | ||
"It can also be run indirectly via bazel, e.g. " | ||
"`bazel run //docs:incremental`." | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def get_plantuml_path() -> Path: | ||
"""Determine the path to the plantuml binary.""" | ||
|
||
runfiles_dir = get_runfiles_dir() | ||
|
||
plantuml = runfiles_dir / ".." / "plantuml" | ||
# Note: this MUST NOT be resolved as we need the "something.runfiles/../" | ||
# piece as part of the path! This way the bazel plantuml script will find | ||
# the runfiles. | ||
|
||
if not plantuml.exists(): | ||
sys.exit( | ||
f"Could not find plantuml binary at {plantuml}. " | ||
"Have a look at README.md for instructions on how to build docs." | ||
) | ||
|
||
return plantuml | ||
|
||
|
||
def get_runfiles_dir() -> Path: | ||
if r := Runfiles.Create(): | ||
# Runfiles are only available when running in Bazel. | ||
# bazel build and bazel run are both supported. | ||
# i.e. `bazel build //docs:docs` and `bazel run //docs:incremental`. | ||
logger.debug("Using runfiles to determine plantuml path.") | ||
|
||
runfiles_dir = Path(r.EnvVars()["RUNFILES_DIR"]) | ||
if not runfiles_dir.exists(): | ||
sys.exit( | ||
f"Could not find runfiles at {runfiles_dir}. Have a look at " | ||
"README.md for instructions on how to build docs." | ||
) | ||
|
||
else: | ||
# The only way to land here is when running from within the virtual | ||
# environment created by the `docs:ide_support` rule in the BUILD file. | ||
# i.e. esbonio or manual sphinx-build execution within the virtual | ||
# environment. | ||
# We'll still use the plantuml binary from the bazel build. | ||
# But we need to find it first. | ||
logger.debug("Running outside bazel.") | ||
|
||
git_root = Path(__file__).resolve().parents[3] | ||
assert ( | ||
git_root / ".git" | ||
).exists(), f"Could not find git root. Assumed path: {git_root}" | ||
|
||
runfiles_dir = git_root / "bazel-bin" / "docs" / "ide_support.runfiles" | ||
if not runfiles_dir.exists(): | ||
sys.exit( | ||
f"Could not find ide_support.runfiles at {runfiles_dir}. " | ||
"Have a look at README.md for instructions on how to build docs." | ||
) | ||
|
||
return runfiles_dir | ||
|
||
|
||
def setup(app: Sphinx): | ||
app.config.plantuml = str(get_plantuml_path()) | ||
app.config.plantuml_output_format = "svg_obj" | ||
|
||
logger.debug(f"PlantUML binary found at {app.config.plantuml}") | ||
|
||
# The extension is not even active at runtime. | ||
return {"parallel_read_safe": True, "parallel_write_safe": True} |
This file contains 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 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 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.