-
Notifications
You must be signed in to change notification settings - Fork 20
Source links as Bazel target #358
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
base: main
Are you sure you want to change the base?
Changes from all commits
d1dfc0c
8d9c7b2
e426bcd
e2bfbf7
529deb8
4b19f68
ae2d4d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 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 | ||
| # ******************************************************************************* | ||
|
|
||
| load("@aspect_rules_py//py:defs.bzl", "py_binary") | ||
| load("@pip_process//:requirements.bzl", "all_requirements") | ||
|
|
||
| py_binary( | ||
| name = "generate_sourcelinks", | ||
| srcs = ["generate_sourcelinks_cli.py"], | ||
| main = "generate_sourcelinks_cli.py", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//src/extensions/score_source_code_linker", | ||
| ] + all_requirements, | ||
| ) | ||
|
|
||
| py_binary( | ||
| name = "merge_sourcelinks", | ||
| srcs = ["merge_sourcelinks.py"], | ||
| main = "merge_sourcelinks.py", | ||
| visibility = ["//visibility:public"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 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 | ||
| # ******************************************************************************* | ||
|
|
||
| """ | ||
| CLI tool to generate source code links JSON from source files. | ||
| This is used by the Bazel sourcelinks_json rule to create a JSON file | ||
| with all source code links for documentation needs. | ||
| """ | ||
|
|
||
| import argparse | ||
| import logging | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from src.extensions.score_source_code_linker.generate_source_code_links_json import ( | ||
|
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. Might need to either make this function public or make a public counterpart.
Contributor
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. I'm not sure yet. Eventually, we should be able to extract it from the Sphinx extension, because the extension shall only consume the json files. |
||
| _extract_references_from_file, | ||
| ) | ||
| from src.extensions.score_source_code_linker.needlinks import ( | ||
| store_source_code_links_json, | ||
| ) | ||
|
|
||
| logging.basicConfig(level=logging.INFO, format="%(message)s") | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser( | ||
| description="Generate source code links JSON from source files" | ||
| ) | ||
| parser.add_argument( | ||
| "--output", | ||
| required=True, | ||
| type=Path, | ||
| help="Output JSON file path", | ||
| ) | ||
| parser.add_argument( | ||
| "files", | ||
| nargs="*", | ||
| type=Path, | ||
| help="Source files to scan for traceability tags", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| all_need_references = [] | ||
| for file_path in args.files: | ||
| abs_file_path = file_path.resolve() | ||
| if abs_file_path.exists(): | ||
| references = _extract_references_from_file( | ||
| abs_file_path.parent, Path(abs_file_path.name) | ||
| ) | ||
| all_need_references.extend(references) | ||
|
Comment on lines
+56
to
+62
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. I think due to '_extract_ref...' it will skip the 'bazel-' stuff and other things anyway?
Contributor
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. The idea is that all source files are explicitly included via Bazel (see all the new filegroup targets). No need for filtering in Python. |
||
|
|
||
| store_source_code_links_json(args.output, all_need_references) | ||
| logger.info( | ||
| f"Found {len(all_need_references)} need references in {len(args.files)} files" | ||
| ) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
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.
How would we best test this?