1919
2020import os
2121from pathlib import Path
22+ from sphinx_needs .logging import get_logger
23+ LOGGER = get_logger (__name__ )
2224
2325from 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