MCPcopy Create free account
hub / github.com/ParzivalHack/PySpector / run_pyspector_ai

Function run_pyspector_ai

tests/unit/test_ai_rules.py:81–104  ·  view source on GitHub ↗
(code: str, filename: str = "model_loader.py")

Source from the content-addressed store, hash-verified

79
80
81def run_pyspector_ai(code: str, filename: str = "model_loader.py") -> list[dict]:
82 try:
83 from pyspector._rust_core import run_scan
84 from pyspector.cli import AstEncoder
85 from pyspector.config import get_default_rules
86 except (ImportError, SystemExit) as exc:
87 pytest.skip(f"PySpector Rust core is not available: {exc}")
88
89 wrapped = _wrap(code)
90 rules_toml = get_default_rules(ai_scan=True)
91
92 with tempfile.TemporaryDirectory() as tmpdir:
93 path = os.path.join(tmpdir, filename)
94 Path(path).write_text(wrapped)
95 with warnings.catch_warnings():
96 warnings.filterwarnings("ignore")
97 try:
98 ast_json = json.dumps(ast.parse(wrapped), cls=AstEncoder)
99 except Exception:
100 ast_json = "{}"
101 files = [{"file_path": filename, "content": wrapped, "ast_json": ast_json}]
102 results = run_scan(tmpdir, rules_toml, {"exclude": []}, files)
103
104 return [{"rule_id": result.rule_id, "line_number": result.line_number} for result in results]
105
106
107def fires(code: str, rule_id: str) -> bool:

Callers 1

firesFunction · 0.85

Calls 2

get_default_rulesFunction · 0.90
_wrapFunction · 0.70

Tested by

no test coverage detected