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

Function run_pyspector

tests/unit/test_group_a_rules.py:25–47  ·  view source on GitHub ↗
(code: str, filename: str = "app.py")

Source from the content-addressed store, hash-verified

23
24
25def run_pyspector(code: str, filename: str = "app.py") -> list[dict]:
26 from pyspector._rust_core import run_scan
27 from pyspector.config import get_default_rules
28 import ast as _ast, json as _json
29 from pyspector.cli import AstEncoder
30
31 wrapped = _wrap(code)
32 rules_toml = get_default_rules()
33
34 with tempfile.TemporaryDirectory() as tmpdir:
35 path = os.path.join(tmpdir, filename)
36 Path(path).write_text(wrapped)
37 with warnings.catch_warnings():
38 warnings.filterwarnings("ignore")
39 try:
40 tree = _ast.parse(wrapped)
41 ast_json = _json.dumps(tree, cls=AstEncoder)
42 except Exception:
43 ast_json = "{}"
44 files = [{"file_path": filename, "content": wrapped, "ast_json": ast_json}]
45 results = run_scan(tmpdir, rules_toml, {"exclude": []}, files)
46
47 return [{"rule_id": r.rule_id, "line_number": r.line_number} for r in results]
48
49
50def fires(code, rule_id, **kw):

Callers 1

firesFunction · 0.70

Calls 2

get_default_rulesFunction · 0.90
_wrapFunction · 0.70

Tested by

no test coverage detected