-
Notifications
You must be signed in to change notification settings - Fork 22
WIP: Source Links Fix #440
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
7dece30
ebdb40f
7f9f8bb
403b9e9
bb73a0f
703cc71
59f7602
7155441
2355aa3
bb475e8
996a51e
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 |
|---|---|---|
|
|
@@ -25,8 +25,10 @@ | |
| from src.extensions.score_source_code_linker.generate_source_code_links_json import ( | ||
| _extract_references_from_file, # pyright: ignore[reportPrivateUsage] TODO: move it out of the extension and into this script | ||
| ) | ||
| from src.extensions.score_source_code_linker.helpers import parse_module_name_from_path | ||
| from src.extensions.score_source_code_linker.needlinks import ( | ||
| store_source_code_links_json, | ||
| MetaData, | ||
| store_source_code_links_with_metadata_json, | ||
| ) | ||
|
|
||
| logging.basicConfig(level=logging.INFO, format="%(message)s") | ||
|
|
@@ -37,13 +39,13 @@ def main(): | |
| parser = argparse.ArgumentParser( | ||
| description="Generate source code links JSON from source files" | ||
| ) | ||
| parser.add_argument( | ||
| _ = parser.add_argument( | ||
| "--output", | ||
| required=True, | ||
| type=Path, | ||
| help="Output JSON file path", | ||
| ) | ||
| parser.add_argument( | ||
| _ = parser.add_argument( | ||
| "files", | ||
| nargs="*", | ||
| type=Path, | ||
|
|
@@ -53,15 +55,25 @@ def main(): | |
| args = parser.parse_args() | ||
|
|
||
| all_need_references = [] | ||
| metadata: MetaData = { | ||
| "module_name": "", | ||
| "hash": "", | ||
| "url": "", | ||
| } | ||
| metadata_set = False | ||
| for file_path in args.files: | ||
| if "known_good.json" not in str(file_path) and not metadata_set: | ||
| metadata["module_name"] = parse_module_name_from_path(file_path) | ||
| metadata_set = True | ||
| abs_file_path = file_path.resolve() | ||
| assert abs_file_path.exists(), abs_file_path | ||
| references = _extract_references_from_file( | ||
| abs_file_path.parent, Path(abs_file_path.name) | ||
| abs_file_path.parent, Path(abs_file_path.name), file_path | ||
| ) | ||
MaximilianSoerenPollak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| all_need_references.extend(references) | ||
|
|
||
| store_source_code_links_json(args.output, all_need_references) | ||
| store_source_code_links_with_metadata_json( | ||
| file=args.output, metadata=metadata, needlist=all_need_references | ||
| ) | ||
|
Comment on lines
+74
to
+76
|
||
| logger.info( | ||
| f"Found {len(all_need_references)} need references in {len(args.files)} files" | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,36 +21,71 @@ | |||||
| import sys | ||||||
| from pathlib import Path | ||||||
|
|
||||||
| from src.extensions.score_source_code_linker.helpers import parse_info_from_known_good | ||||||
|
|
||||||
| logging.basicConfig(level=logging.INFO, format="%(message)s") | ||||||
| logger = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| """ | ||||||
| if bazel-out/k8-fastbuild/bin/external/ in file_path => module is external | ||||||
| otherwise it's local | ||||||
| if local => module_name & hash == empty | ||||||
| if external => parse thing for module_name => look up known_good json for hash & url | ||||||
| """ | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| def add_needid_to_metaneed_mapping(mapping: dict[str, dict[str, str]], metadata: dict[str, str], needid: str): | ||||||
| mapping | ||||||
| pass | ||||||
|
|
||||||
| def main(): | ||||||
| parser = argparse.ArgumentParser( | ||||||
| description="Merge multiple sourcelinks JSON files into one" | ||||||
| ) | ||||||
| parser.add_argument( | ||||||
| _ = parser.add_argument( | ||||||
| "--output", | ||||||
| required=True, | ||||||
| type=Path, | ||||||
| help="Output merged JSON file path", | ||||||
| ) | ||||||
| parser.add_argument( | ||||||
| _ = parser.add_argument( | ||||||
| "--known_good", | ||||||
| required=True, | ||||||
| help="Optional path to a 'known good' JSON file (provided by Bazel).", | ||||||
|
||||||
| help="Optional path to a 'known good' JSON file (provided by Bazel).", | |
| help="Path to a 'known good' JSON file (provided by Bazel).", |
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.
merge_sourcelinks.pynow defines--known_goodasrequired=True, butdocs.bzlonly passes--known_goodwhenknown_good != None. With the defaultknown_good=None, the genrule will invoke the script without--known_goodand fail argument parsing. Either makeknown_goodmandatory indocs()/_merge_sourcelinks, or make--known_goodoptional again and handle the missing case in the script.