MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / run_similarity

Function run_similarity

scripts/inspect-unity.py:159–188  ·  view source on GitHub ↗

Run similarity-csharp and return (report path, group count, total lines).

(output_dir: Path, threshold: float)

Source from the content-addressed store, hash-verified

157
158
159def run_similarity(output_dir: Path, threshold: float) -> tuple[Path, int, int]:
160 """Run similarity-csharp and return (report path, group count, total lines)."""
161 report_path = output_dir / "similarity.txt"
162 assets_dir = TEST_PROJECT / "Assets"
163
164 cmd = [
165 "similarity-csharp",
166 "-p",
167 str(assets_dir),
168 "--min-lines",
169 "5",
170 "--threshold",
171 str(threshold),
172 "-o",
173 str(report_path),
174 ]
175 print(f"Running: {' '.join(cmd)}")
176 result = subprocess.run(cmd, capture_output=True, text=True)
177 if result.returncode != 0:
178 print(f"similarity-csharp failed (exit {result.returncode}):")
179 if result.stderr:
180 print(result.stderr)
181 return report_path, 0, 0
182
183 if not report_path.exists():
184 print("similarity-csharp produced no output")
185 return report_path, 0, 0
186
187 groups, total_lines = parse_similarity_report(report_path)
188 return report_path, groups, total_lines
189
190
191def parse_similarity_report(report_path: Path) -> tuple[int, int]:

Callers 1

mainFunction · 0.85

Calls 2

parse_similarity_reportFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected