Skip to content

Commit 73d3c09

Browse files
Fixed source_code_linker finding external needs
Added simple loop search logic to try all available prefixes per id.
1 parent 727e4c6 commit 73d3c09

5 files changed

Lines changed: 53 additions & 15 deletions

File tree

BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
load("@score_cr_checker//:cr_checker.bzl", "copyright_checker")
1515

16+
package(default_visibility = ["//visibility:public"])
17+
1618
copyright_checker(
1719
name = "copyright",
1820
srcs = [

docs/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ docs(
2727
"suffix": "latest", # latest main branch documentation build
2828
"external_needs_info": [
2929
{
30-
"base_url": "https://eclipse-score.github.io/score/main/",
30+
"base_url": "https://eclipse-score.github.io/score/main",
3131
"json_url": "https://eclipse-score.github.io/score/main/needs.json",
3232
"version": "0.1",
3333
"id_prefix": "score_",

src/BUILD

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,33 @@ pkg_tar(
101101
srcs = [":html_files"],
102102
)
103103

104+
py_library(
105+
name = "docs_as_code_py_modules",
106+
srcs = [
107+
"@score_docs_as_code//src:plantuml_for_python",
108+
"@score_docs_as_code//src/extensions:score_plantuml",
109+
"@score_docs_as_code//src/extensions/score_draw_uml_funcs",
110+
"@score_docs_as_code//src/extensions/score_header_service",
111+
"@score_docs_as_code//src/extensions/score_layout",
112+
"@score_docs_as_code//src/extensions/score_metamodel",
113+
"@score_docs_as_code//src/extensions/score_source_code_linker",
114+
"@score_docs_as_code//src/find_runfiles",
115+
],
116+
visibility = ["//visibility:public"],
117+
)
118+
104119
filegroup(
105120
name = "score_extension_files",
106121
srcs = glob(
107-
["*/**"],
122+
[
123+
"**",
124+
],
108125
exclude = [
109126
"**/test/**",
110127
"**/tests/**",
111128
"**/__pycache__/**",
112129
],
113-
),
130+
) + [":docs_as_code_py_modules"],
114131
visibility = ["//visibility:public"],
115132
)
116133

src/extensions/score_metamodel/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ py_library(
1818
name = "score_metamodel",
1919
srcs = glob(
2020
["**/*.py"],
21-
),
21+
) + ["metamodel.yaml"],
2222
data = glob(["*.yaml"]), # Needed to remove 'resolving of symlink' in score_metamodel.__init__
2323
imports = [
2424
".",

src/extensions/score_source_code_linker/__init__.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from sphinx.application import Sphinx
1818
from sphinx.environment import BuildEnvironment
19-
from sphinx_needs.data import SphinxNeedsData
19+
from sphinx_needs.data import NeedsMutable, SphinxNeedsData, NeedsInfoType
2020
from sphinx_needs.logging import get_logger
2121

2222
from src.extensions.score_source_code_linker.parse_source_files import GITHUB_BASE_URL
@@ -59,6 +59,21 @@ def setup(app: Sphinx) -> dict[str, str | bool]:
5959
}
6060

6161

62+
def find_need(
63+
all_needs: NeedsMutable, id: str, prefixes: list[str]
64+
) -> NeedsInfoType | None:
65+
if id in all_needs:
66+
return all_needs[id]
67+
68+
# Try all possible prefixes
69+
for prefix in prefixes:
70+
prefixed_id = f"{prefix}{id}"
71+
if prefixed_id in all_needs:
72+
return all_needs[prefixed_id]
73+
74+
return None
75+
76+
6277
# re-qid: gd_req__req__attr_impl
6378
def add_source_link(app: Sphinx, env: BuildEnvironment) -> None:
6479
"""
@@ -77,28 +92,25 @@ def add_source_link(app: Sphinx, env: BuildEnvironment) -> None:
7792
p5 = Path(__file__).parents[5]
7893

7994
if str(p5).endswith("src"):
80-
LOGGER.info("DEBUG: WE ARE IN THE IF")
95+
LOGGER.debug("DEBUG: WE ARE IN THE IF")
8196
path = str(p5.parent / Path(app.confdir).name / "score_source_code_parser.json")
8297
else:
83-
LOGGER.info("DEBUG: WE ARE IN THE ELSE")
98+
LOGGER.debug("DEBUG: WE ARE IN THE ELSE")
8499
path = str(p5 / "score_source_code_parser.json")
85100

86101
if app.config.score_source_code_linker_file_overwrite:
87102
path = app.config.score_source_code_linker_file_overwrite
88103

104+
# For some reason the prefix 'sphinx_needs internally' is CAPSLOCKED.
105+
# So we have to make sure we uppercase the prefixes
106+
prefixes = [x["id_prefix"].upper() for x in app.config.needs_external_needs]
89107
try:
90108
with open(path) as f:
91109
gh_json = json.load(f)
92110
for id, link in gh_json.items():
93111
id = id.strip()
94-
try:
95-
# NOTE: Removing & adding the need is important to make sure
96-
# the needs gets 're-evaluated'.
97-
need = needs_copy[id] # NeedsInfoType
98-
Needs_Data.remove_need(need["id"])
99-
need["source_code_link"] = ",".join(link)
100-
Needs_Data.add_need(need)
101-
except KeyError:
112+
need = find_need(needs_copy, id, prefixes)
113+
if need is None:
102114
# NOTE: manipulating link to remove git-hash,
103115
# making the output file location more readable
104116
files = [x.replace(GITHUB_BASE_URL, "").split("/", 1)[-1] for x in link]
@@ -107,6 +119,13 @@ def add_source_link(app: Sphinx, env: BuildEnvironment) -> None:
107119
+ f"Found in file(s): {files}",
108120
type="score_source_code_linker",
109121
)
122+
continue
123+
124+
# NOTE: Removing & adding the need is important to make sure
125+
# the needs gets 're-evaluated'.
126+
Needs_Data.remove_need(need["id"])
127+
need["source_code_link"] = ",".join(link)
128+
Needs_Data.add_need(need)
110129
except Exception as e:
111130
LOGGER.warning(
112131
f"An unexpected error occurred while adding source_code_links to needs."

0 commit comments

Comments
 (0)