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

Function run_pyspector

tests/unit/test_missing_rules.py:21–43  ·  view source on GitHub ↗
(code: str, filename: str = "app.py")

Source from the content-addressed store, hash-verified

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