Skip to content

Commit ebdb40f

Browse files
WIP: seems to work in ref & local
1 parent 7dece30 commit ebdb40f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

scripts_bazel/generate_sourcelinks_cli.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,18 @@ def main():
8989
for file_path in args.files:
9090
if "known_good.json" not in str(file_path) and not metadata_set:
9191
metadata["module_name"] = parse_module_name_from_path(file_path)
92-
print("================")
93-
print(metadata)
94-
print("===============")
95-
print("METADATA SET")
92+
# print("================")
93+
# print(metadata)
94+
# print("===============")
95+
# print("METADATA SET")
9696
metadata_set = True
9797
abs_file_path = file_path.resolve()
9898
assert abs_file_path.exists(), abs_file_path
99+
# print("THIS Is ABS FILEPATH: ", file_path)
100+
# print("THIS IS ABS FILEPATH NAME: ", abs_file_path.name)
101+
# print("THIS Is ABS FILEPATH PARENT: ", abs_file_path.parent)
99102
references = _extract_references_from_file(
100-
abs_file_path.parent, Path(abs_file_path.name)
103+
abs_file_path.parent, Path(abs_file_path.name), file_path
101104
)
102105
all_need_references.extend(references)
103106
store_source_code_links_with_metadata_json(

src/extensions/score_source_code_linker/generate_source_code_links_json.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import os
2121
from pathlib import Path
22+
from sphinx_needs.logging import get_logger
23+
LOGGER = get_logger(__name__)
2224

2325
from src.extensions.score_source_code_linker.needlinks import (
2426
NeedLink,
@@ -43,21 +45,21 @@ def _extract_references_from_line(line: str):
4345
yield tag, req.strip()
4446

4547

46-
def _extract_references_from_file(root: Path, file_path: Path) -> list[NeedLink]:
48+
def _extract_references_from_file(root: Path, file_path_name: Path, file_path: Path) -> list[NeedLink]:
4749
"""Scan a single file for template strings and return findings."""
4850
assert root.is_absolute(), "Root path must be absolute"
49-
assert not file_path.is_absolute(), "File path must be relative to the root"
51+
assert not file_path_name.is_absolute(), "File path must be relative to the root"
5052
# assert file_path.is_relative_to(root), (
5153
# f"File path ({file_path}) must be relative to the root ({root})"
5254
# )
53-
assert (root / file_path).exists(), (
54-
f"File {file_path} does not exist in root {root}."
55+
assert (root / file_path_name).exists(), (
56+
f"File {file_path_name} does not exist in root {root}."
5557
)
5658

5759
findings: list[NeedLink] = []
5860

5961
try:
60-
with open(root / file_path, encoding="utf-8", errors="ignore") as f:
62+
with open(root / file_path_name, encoding="utf-8", errors="ignore") as f:
6163
for line_num, line in enumerate(f, 1):
6264
for tag, req in _extract_references_from_line(line):
6365
findings.append(
@@ -69,8 +71,9 @@ def _extract_references_from_file(root: Path, file_path: Path) -> list[NeedLink]
6971
full_line=line.strip(),
7072
)
7173
)
72-
except (UnicodeDecodeError, PermissionError, OSError):
74+
except (UnicodeDecodeError, PermissionError, OSError) as e:
7375
# Skip files that can't be read as text
76+
LOGGER.debug(f"Error reading file to parse for linked needs: \n{e}")
7477
pass
7578

7679
return findings
@@ -121,8 +124,8 @@ def find_all_need_references(search_path: Path) -> list[NeedLink]:
121124
all_need_references.extend(references)
122125

123126
elapsed_time = os.times().elapsed - start_time
124-
print(
125-
f"DEBUG: Found {len(all_need_references)} need references "
127+
LOGGER.debug(
128+
f"Found {len(all_need_references)} need references "
126129
f"in {elapsed_time:.2f} seconds"
127130
)
128131

0 commit comments

Comments
 (0)