codeabc 0.1.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.
Files changed (62) hide show
  1. backend/__init__.py +0 -0
  2. backend/app.py +95 -0
  3. backend/desktop_server.py +46 -0
  4. backend/models.py +629 -0
  5. backend/prompts/__init__.py +0 -0
  6. backend/prompts/annotate.py +44 -0
  7. backend/prompts/edit.py +62 -0
  8. backend/prompts/overview.py +57 -0
  9. backend/prompts/qa.py +45 -0
  10. backend/routers/__init__.py +0 -0
  11. backend/routers/analyze.py +271 -0
  12. backend/routers/project.py +872 -0
  13. backend/services/__init__.py +0 -0
  14. backend/services/action_plan.py +366 -0
  15. backend/services/activity.py +313 -0
  16. backend/services/apimap.py +391 -0
  17. backend/services/async_surface.py +123 -0
  18. backend/services/cache.py +183 -0
  19. backend/services/churn.py +244 -0
  20. backend/services/ci_checks.py +317 -0
  21. backend/services/codemap_export.py +136 -0
  22. backend/services/commands.py +276 -0
  23. backend/services/complexity.py +111 -0
  24. backend/services/config_files.py +190 -0
  25. backend/services/contributing.py +308 -0
  26. backend/services/coverage.py +283 -0
  27. backend/services/datamodels.py +190 -0
  28. backend/services/deep_nesting.py +110 -0
  29. backend/services/dependencies.py +270 -0
  30. backend/services/docs.py +255 -0
  31. backend/services/docstrings.py +163 -0
  32. backend/services/duplicate_code.py +165 -0
  33. backend/services/entrypoints.py +152 -0
  34. backend/services/envscan.py +167 -0
  35. backend/services/error_handling.py +239 -0
  36. backend/services/filenames.py +261 -0
  37. backend/services/github_clone.py +129 -0
  38. backend/services/glossary.py +96 -0
  39. backend/services/health_score.py +381 -0
  40. backend/services/importgraph.py +986 -0
  41. backend/services/integrations.py +263 -0
  42. backend/services/licenses.py +505 -0
  43. backend/services/llm.py +117 -0
  44. backend/services/long_functions.py +101 -0
  45. backend/services/ownership.py +194 -0
  46. backend/services/package_purposes.py +112 -0
  47. backend/services/pr_reading.py +181 -0
  48. backend/services/release_map.py +402 -0
  49. backend/services/report_export.py +232 -0
  50. backend/services/risk.py +88 -0
  51. backend/services/scanner.py +546 -0
  52. backend/services/schedules.py +369 -0
  53. backend/services/security.py +445 -0
  54. backend/services/settings_map.py +234 -0
  55. backend/services/symbols.py +605 -0
  56. backend/services/techdebt.py +124 -0
  57. backend/services/too_many_params.py +102 -0
  58. backend/services/typing_coverage.py +184 -0
  59. codeabc-0.1.0.dist-info/METADATA +283 -0
  60. codeabc-0.1.0.dist-info/RECORD +62 -0
  61. codeabc-0.1.0.dist-info/WHEEL +4 -0
  62. codeabc-0.1.0.dist-info/licenses/LICENSE +21 -0
backend/__init__.py ADDED
File without changes
backend/app.py ADDED
@@ -0,0 +1,95 @@
1
+ """CodeABC backend — FastAPI application."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from contextlib import asynccontextmanager
7
+ from pathlib import Path
8
+
9
+ from fastapi import FastAPI, HTTPException
10
+ from fastapi.middleware.cors import CORSMiddleware
11
+ from fastapi.responses import FileResponse
12
+
13
+ from backend.routers import analyze, project
14
+ from backend.services.cache import init_db
15
+
16
+
17
+ @asynccontextmanager
18
+ async def lifespan(app: FastAPI):
19
+ # startup: init sqlite cache
20
+ await init_db()
21
+ yield
22
+ # shutdown: nothing to clean up for now
23
+
24
+
25
+ app = FastAPI(
26
+ title="CodeABC",
27
+ description="AI-powered code reader for non-programmers",
28
+ version="0.1.0",
29
+ lifespan=lifespan,
30
+ )
31
+
32
+ # CORS — allow the Vite dev server and the Tauri desktop shell. The desktop
33
+ # webview loads from a tauri:// origin (http://tauri.localhost on Windows,
34
+ # tauri://localhost on macOS/Linux) and calls this backend on 127.0.0.1:8000,
35
+ # which is cross-origin, so those origins must be allow-listed too.
36
+ app.add_middleware(
37
+ CORSMiddleware,
38
+ allow_origins=[
39
+ "http://localhost:5173", # vite dev
40
+ "http://localhost:3000",
41
+ "http://127.0.0.1:5173",
42
+ "tauri://localhost", # Tauri desktop (macOS/Linux)
43
+ "http://tauri.localhost", # Tauri desktop (Windows)
44
+ "https://tauri.localhost",
45
+ os.getenv("FRONTEND_ORIGIN", ""),
46
+ ],
47
+ allow_credentials=True,
48
+ allow_methods=["*"],
49
+ allow_headers=["*"],
50
+ )
51
+
52
+ # analyze router must come first: its /file/{path}/annotations route
53
+ # needs to match before project's greedy /file/{path:path} route
54
+ app.include_router(analyze.router, prefix="/api")
55
+ app.include_router(project.router, prefix="/api")
56
+
57
+
58
+ @app.get("/api/health")
59
+ async def health():
60
+ return {"status": "ok"}
61
+
62
+
63
+ # Serve the built frontend from the same process, so the whole app is one
64
+ # command and one URL — no separate dev server for someone who just wants to
65
+ # run it. Skipped automatically when the frontend hasn't been built (e.g. in
66
+ # CI or a backend-only checkout), so imports and API tests are unaffected.
67
+ _FRONTEND_DIST = Path(
68
+ os.getenv("CODEABC_FRONTEND_DIST")
69
+ or Path(__file__).resolve().parent.parent / "frontend" / "dist"
70
+ )
71
+
72
+
73
+ def _mount_frontend() -> None:
74
+ index = _FRONTEND_DIST / "index.html"
75
+ if not index.is_file():
76
+ return
77
+
78
+ @app.get("/")
79
+ async def _spa_root() -> FileResponse:
80
+ return FileResponse(index)
81
+
82
+ @app.get("/{full_path:path}")
83
+ async def _spa_fallback(full_path: str) -> FileResponse:
84
+ # API 404s stay 404s; never shadow them with the SPA shell.
85
+ if full_path.startswith("api/"):
86
+ raise HTTPException(404, "Not found")
87
+ candidate = (_FRONTEND_DIST / full_path).resolve()
88
+ # serve a real built asset if it exists (and stays inside dist),
89
+ # otherwise hand back index.html so client-side routes work on reload.
90
+ if candidate.is_file() and candidate.is_relative_to(_FRONTEND_DIST):
91
+ return FileResponse(candidate)
92
+ return FileResponse(index)
93
+
94
+
95
+ _mount_frontend()
@@ -0,0 +1,46 @@
1
+ """Entry point for the bundled desktop backend (Tauri sidecar).
2
+
3
+ The desktop app ships this as a standalone binary (built with PyInstaller) and
4
+ spawns it on startup, so a user who just wants the native window doesn't have to
5
+ start a Python server themselves. It runs the same FastAPI app on a loopback
6
+ port; the desktop webview talks to it over 127.0.0.1.
7
+
8
+ The built frontend isn't next to this binary, so ``backend.app`` skips mounting
9
+ the SPA and serves the API only — the Tauri shell already serves the UI.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+ import sys
16
+ import threading
17
+
18
+ import uvicorn
19
+
20
+ from backend.app import app
21
+
22
+
23
+ def _exit_when_parent_dies() -> None:
24
+ """Shut down when our stdin closes — i.e. when the desktop app dies.
25
+
26
+ Tauri wires our stdin to the parent process. When that process goes away
27
+ (a normal quit, but also a crash or a force-kill that never runs the app's
28
+ cleanup), the pipe hits EOF and we exit, so we never linger as an orphaned
29
+ server holding the port. Run standalone from a terminal, stdin stays open
30
+ and this simply waits.
31
+ """
32
+ try:
33
+ sys.stdin.read()
34
+ except Exception:
35
+ pass
36
+ os._exit(0)
37
+
38
+
39
+ def main() -> None:
40
+ threading.Thread(target=_exit_when_parent_dies, daemon=True).start()
41
+ port = int(os.getenv("CODEABC_PORT", "8000"))
42
+ uvicorn.run(app, host="127.0.0.1", port=port, log_level="warning")
43
+
44
+
45
+ if __name__ == "__main__":
46
+ main()