(code: str, filename: str = "app.py")
| 19 | |
| 20 | |
| 21 | def 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 | |
| 46 | def fires(code, rule_id, **kw): |
no test coverage detected