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