Skip to content

Commit

Permalink
Merge pull request #761 from OptimumCode/annotation-script-rfc-support
Browse files Browse the repository at this point in the history
Correct annotation python script to correctly work with rfc and iso links
  • Loading branch information
Julian authored Feb 7, 2025
2 parents e524505 + 9563ce7 commit 9c5d99b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
33 changes: 29 additions & 4 deletions bin/annotate-specification-links
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def line_number_of(path: Path, case: dict[str, Any]) -> int:
1,
)

def extract_kind_and_spec(key: str) -> (str, str):
"""
Extracts specification number and kind from the defined key
"""
can_have_spec = ["rfc", "iso"]
if not any(key.startswith(el) for el in can_have_spec):
return key, ""
number = re.search(r"\d+", key)
spec = "" if number is None else number.group(0)
kind = key.removesuffix(spec)
return kind, spec


def main():
# Clear annotations which may have been emitted by a previous run.
Expand All @@ -82,20 +94,33 @@ def main():
line=error.lineno,
col=error.pos + 1,
title=str(error),
message=f"cannot load {path}"
)
sys.stdout.write(error)
continue

for test_case in contents:
specifications = test_case.get("specification")
if specifications is not None:
for each in specifications:
quote = each.pop("quote", "")
(kind, section), = each.items()
(key, section), = each.items()

number = re.search(r"\d+", kind)
spec = "" if number is None else number.group(0)
(kind, spec) = extract_kind_and_spec(key)

url_template = version_urls[kind]
if url_template is None:
error = annotation(
level="error",
path=path,
line=line_number_of(path, test_case),
title=f"unsupported template '{kind}'",
message=f"cannot find a URL template for '{kind}'"
)
sys.stdout.write(error)
continue

url = version_urls[kind].expand(
url = url_template.expand(
spec=spec,
section=section,
)
Expand Down
2 changes: 1 addition & 1 deletion bin/specification_urls.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"external": {
"ecma262": "https://262.ecma-international.org/{section}",
"perl5": "https://perldoc.perl.org/perlre#{section}",
"rfc": "https://www.rfc-editor.org/rfc/{spec}.txt#{section}",
"rfc": "https://www.rfc-editor.org/rfc/rfc{spec}.txt#{section}",
"iso": "https://www.iso.org/obp/ui"
}
}

0 comments on commit 9c5d99b

Please # to comment.