(code, filename="app.py")
| 11 | |
| 12 | |
| 13 | def run(code, filename="app.py"): |
| 14 | from pyspector._rust_core import run_scan |
| 15 | from pyspector.config import get_default_rules |
| 16 | import ast as _ast, json as _json |
| 17 | from pyspector.cli import AstEncoder |
| 18 | wrapped = _wrap(code) |
| 19 | rules = get_default_rules() |
| 20 | with tempfile.TemporaryDirectory() as d: |
| 21 | p = os.path.join(d, filename) |
| 22 | Path(p).write_text(wrapped) |
| 23 | with warnings.catch_warnings(): |
| 24 | warnings.filterwarnings("ignore") |
| 25 | try: aj = _json.dumps(_ast.parse(wrapped), cls=AstEncoder) |
| 26 | except: aj = "{}" |
| 27 | files = [{"file_path": filename, "content": wrapped, "ast_json": aj}] |
| 28 | return [{"rule_id": r.rule_id} for r in run_scan(d, rules, {"exclude": []}, files)] |
| 29 | |
| 30 | |
| 31 | def fires(code, rule_id): return [f for f in run(code) if f["rule_id"] == rule_id] |
no test coverage detected