MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / _find_in_file

Method _find_in_file

scripts/verify-version-sync.py:211–247  ·  view source on GitHub ↗

Find version references in a specific file.

(self, file_path: str, pattern: str, is_master: bool = False, first_only: bool = False)

Source from the content-addressed store, hash-verified

209 return refs
210
211 def _find_in_file(self, file_path: str, pattern: str, is_master: bool = False, first_only: bool = False) -> List[VersionReference]:
212 """Find version references in a specific file."""
213 full_path = self.root_path / file_path
214 if not full_path.exists():
215 return []
216
217 refs = []
218 try:
219 with open(full_path, "r", encoding="utf-8") as f:
220 content = f.read()
221
222 # Use multiline matching for complex patterns
223 matches = re.finditer(pattern, content, re.MULTILINE | re.DOTALL)
224 for match in matches:
225 # Extract version from the first capturing group
226 if match.groups():
227 version = match.group(1)
228 else:
229 version = match.group(0)
230
231 # Calculate line number
232 line_num = content[: match.start()].count("\n") + 1
233
234 refs.append(VersionReference(file_path=file_path, version=version, pattern=pattern, line_number=line_num, is_master=is_master))
235
236 # If first_only is True, break after first match
237 if first_only:
238 break
239
240 # For most files, only take the first match
241 if file_path != "CHANGELOG.md":
242 break
243
244 except Exception as e:
245 print(f"⚠️ Error reading {file_path}: {e}")
246
247 return refs
248
249 def generate_comprehensive_report(self) -> VersionReport:
250 """Generate a comprehensive version synchronization report."""

Callers 1

find_all_versionsMethod · 0.95

Calls 2

VersionReferenceClass · 0.85
countMethod · 0.80

Tested by

no test coverage detected