prism-code-workspace 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
python_app/launch.py ADDED
@@ -0,0 +1,6 @@
1
+ """PyInstaller-friendly launcher for the Prism Python application."""
2
+
3
+ from python_app.desktop import main
4
+
5
+ if __name__ == "__main__":
6
+ raise SystemExit(main())
@@ -0,0 +1,14 @@
1
+ """Launch the native Python-only Prism application."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ if __package__ in {None, ""}:
9
+ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
10
+
11
+ from python_app.native_app import main
12
+
13
+ if __name__ == "__main__":
14
+ raise SystemExit(main())
@@ -0,0 +1,79 @@
1
+ """Code complexity and beginner readability advisor for Prism."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from typing import Any
7
+
8
+
9
+ def evaluate_code_health(analysis: dict[str, Any], trace: dict[str, Any] | None = None) -> dict[str, Any]:
10
+ """Compute cyclomatic complexity, readability grade, and beginner tips."""
11
+ metrics = analysis.get("metrics") or {}
12
+ loops = int(metrics.get("loops", 0))
13
+ conditions = int(metrics.get("conditions", 0))
14
+ functions = int(metrics.get("functions", 0))
15
+ max_depth = int(metrics.get("maxDepth", 0))
16
+ code_lines = int(metrics.get("codeLines", 0))
17
+
18
+ # McCabe-style simplified cyclomatic complexity: 1 + decision/loop branches
19
+ complexity = 1 + loops + conditions
20
+
21
+ if complexity <= 3 and max_depth <= 3:
22
+ grade = "A"
23
+ label = "Clean & Flat"
24
+ summary = "Low branching complexity. Easy for beginners to trace step by step."
25
+ elif complexity <= 6 and max_depth <= 4:
26
+ grade = "B"
27
+ label = "Moderate"
28
+ summary = "Moderate control flow. Consider splitting complex blocks into helper functions."
29
+ else:
30
+ grade = "C"
31
+ label = "Deep / Complex"
32
+ summary = "High branching or deep nesting. Refactoring into smaller functions is recommended."
33
+
34
+ tips: list[str] = []
35
+ if max_depth >= 4:
36
+ tips.append(f"Nesting depth reaches {max_depth} levels; consider early returns to flatten logic.")
37
+ if loops >= 2 and functions == 0 and code_lines >= 12:
38
+ tips.append("Multiple loops appear at top level; wrapping reusable logic in a function improves clarity.")
39
+ if conditions >= 3:
40
+ tips.append("Several conditional branches detected; verify edge cases in Live Trace.")
41
+ if trace and trace.get("warnings"):
42
+ tips.append("Trace terminated early due to safe execution bounds; inspect structural views for full coverage.")
43
+ if not tips:
44
+ tips.append("Structure is concise and well-proportioned for step-by-step learning.")
45
+
46
+ return {
47
+ "cyclomaticComplexity": complexity,
48
+ "maxNestingDepth": max_depth,
49
+ "grade": grade,
50
+ "label": label,
51
+ "summary": summary,
52
+ "tips": tips,
53
+ }
54
+
55
+
56
+ def format_health_markdown(health: dict[str, Any]) -> str:
57
+ """Render code health report as a Markdown section."""
58
+ lines = [
59
+ "## Code Health & Complexity",
60
+ f"- **Rating**: Grade {health['grade']} ({health['label']})",
61
+ f"- **Cyclomatic Complexity**: {health['cyclomaticComplexity']}",
62
+ f"- **Max Nesting Depth**: {health['maxNestingDepth']}",
63
+ f"- **Assessment**: {health['summary']}",
64
+ "",
65
+ "### Structural Tips",
66
+ ]
67
+ lines.extend(f"- {tip}" for tip in health.get("tips", []))
68
+ return "\n".join(lines)
69
+
70
+
71
+ def export_health_json(analysis: dict[str, Any], trace: dict[str, Any] | None = None) -> str:
72
+ """Serialize analysis metrics and health score into formatted JSON."""
73
+ health = evaluate_code_health(analysis, trace)
74
+ payload = {
75
+ "language": analysis.get("languageId", "unknown"),
76
+ "metrics": analysis.get("metrics", {}),
77
+ "health": health,
78
+ }
79
+ return json.dumps(payload, indent=2, ensure_ascii=False)