Skip to content

Commit 21f4bb8

Browse files
fixes exeternal prefix cleaning (#61)
1 parent 4111e77 commit 21f4bb8

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bazel_dep(name = "buildifier_prebuilt", version = "7.3.1")
6666
bazel_dep(name = "aspect_rules_lint", version = "1.4.2")
6767

6868
# PlantUML for docs
69-
bazel_dep(name = "rules_java", version = "8.6.3")
69+
bazel_dep(name = "rules_java", version = "8.11.0")
7070

7171
http_jar = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
7272

src/extensions/score_metamodel/BUILD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ score_py_pytest(
3333
size = "small",
3434
srcs = glob(["tests/*.py"]),
3535
# All requirements already in the library so no need to have it double
36-
data = ["//src:test_rst_files"] + glob(["**/*.rst"]),
36+
data = ["//src:test_rst_files"] + glob(
37+
["tests/**/*.rst"],
38+
),
3739
deps = [":score_metamodel"],
3840
)

src/extensions/score_metamodel/checks/check_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def validate_fields(
5353
:param field_type: A string indicating the field type ('option' or 'link').
5454
"""
5555

56-
def remove_prefix(values: list[str], prefixes: list[str]) -> list[str]:
56+
def remove_prefix(word: str, prefixes: list[str]) -> str:
5757
# Memory and allocation wise better to use a generator here.
5858
# Removes any prefix allowed by configuration, if prefix is there.
59-
return [word.removeprefix(p) for word in values for p in prefixes]
59+
return [word.removeprefix(prefix) for prefix in prefixes][0]
6060

6161
for field, pattern in fields.items():
6262
raw_value: str | list[str] | None = need.get(field, None)
@@ -77,10 +77,10 @@ def remove_prefix(values: list[str], prefixes: list[str]) -> list[str]:
7777
values = [str(raw_value)]
7878

7979
# The filter ensures that the function is only called when needed.
80-
if field_type == "link" and allowed_prefixes:
81-
values = remove_prefix(values, allowed_prefixes)
8280

8381
for value in values:
82+
if field_type == "link" and allowed_prefixes:
83+
value = remove_prefix(value, allowed_prefixes)
8484
try:
8585
if not re.match(pattern, value):
8686
log.warning_for_option(

src/extensions/score_metamodel/metamodel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ needs_types:
227227
safety: "^(QM|ASIL_B|ASIL_D)$"
228228
status: "^(valid|invalid)$"
229229
mandatory_links:
230-
satisfies: "^stkh_req__.*$"
230+
satisfies: "^.*_req__.*$"
231231
optional_options:
232232
codelink: "^.*$"
233233
testlink: "^.*$"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
..
2+
# *******************************************************************************
3+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
4+
#
5+
# See the NOTICE file(s) distributed with this work for additional
6+
# information regarding copyright ownership.
7+
#
8+
# This program and the accompanying materials are made available under the
9+
# terms of the Apache License Version 2.0 which is available at
10+
# https://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# SPDX-License-Identifier: Apache-2.0
13+
# *******************************************************************************
14+
15+
#CHECK: check_options
16+
17+
.. Cleaning of 'external prefix' before checking regex confirmity
18+
#EXPECT-NOT tool_req__test_abcd.satisfies (PROCESS_doc_getstrt__req__process): does not follow pattern `^doc_.+$`.
19+
20+
.. tool_req:: This is a test
21+
:id: tool_req__test_abcd
22+
:satisfies: PROCESS_doc_getstrt__req__process
23+
24+
This should not give a warning
25+
26+
27+
.. Also make sure it works wit lists of links
28+
29+
#EXPECT-NOT: tool_req__test_aaaa.satisfies (PROCESS_doc_getstrt__req__process): does not follow pattern `^doc_.+$`.
30+
#EXPECT-NOT: tool_req__test_aaaa.satisfies (PROCESS_gd_guidl__req__engineering): does not follow pattern `^gd_.+$`.
31+
32+
.. tool_req:: This is a test
33+
:id: tool_req__test_aaaa
34+
:satisfies: PROCESS_doc_getstrt__req__process;PROCESS_gd_guidl__req__engineering
35+
36+
This should give a warning

src/extensions/score_metamodel/tests/rst/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@
2020
"sphinx_needs",
2121
"score_metamodel",
2222
]
23+
24+
needs_external_needs = [
25+
{
26+
"base_url": "https://eclipse-score.github.io/process_description/main/",
27+
"json_url": "https://eclipse-score.github.io/process_description/main/needs.json",
28+
"id_prefix": "process_",
29+
}
30+
]

0 commit comments

Comments
 (0)