Skip to main content

Crate model_lang_python

Crate model_lang_python 

Source
Expand description

Python enricher for Model.

Runs after model-treesitter extraction, on the same ModelBuilder: it re-reads each .py file for facts a query cannot express and adds them with Provenance::Frontend.

HTTP endpoints, from

  • Flask: @app.route("/x", methods=[...]), @bp.get("/x");
  • FastAPI: @router.get("/x"), @app.api_route(...), with the prefix= of the APIRouter / Blueprint they are declared on;
  • Django: path(), re_path(), url() calls of a file defining urlpatterns (include(...) mounts are not followed: the route prefix of an included module is not composed).

Each endpoint is an entity of kind http.endpoint (shared with the Java and TypeScript enrichers) (archetype Variable, no FM3 class: the Famix Python metamodel’s class names are not settled), keyed under its handler (decorators) or its urls.py file (Django) with a Meta descriptor METHOD path:. Props: http.framework, http.verb, http.path, http.handler, http.route_name. Django endpoints also get a Calls relation to their view when one project function or class carries its name.

Structs§

Endpoint
One route, before it meets the model.
PythonStats

Enums§

Framework

Constants§

HTTP_ENDPOINT
Fine kind of an HTTP endpoint.
IGNORED_DIRS
Directories never descended into.

Functions§

declare_kinds
Defines the kinds this enricher adds (normally defined when first met), see model_treesitter::declare_kinds.
endpoints
Endpoints of one file, in source order.
enrich
Reads every .py file under root (gitignore honoured) accepted by keep (path relative to root, /-separated) and adds its endpoints.
enrich_sources
Adds the endpoints of files ((relative path, source)) to b.