@suss/adapter-python 0.33.1 → 0.34.1
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.
- package/README.md +11 -11
- package/dist/index.cjs +7082 -3037
- package/dist/index.d.cts +589 -284
- package/dist/index.d.ts +589 -284
- package/dist/index.js +6501 -2411
- package/grammar/README.md +26 -23
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Read a Python codebase with [suss](https://github.com/nimbuscloud-ai/suss).
|
|
4
4
|
|
|
5
|
-
suss reads both sides of every call in a repository and
|
|
5
|
+
suss reads both sides of every call in a repository and reports where the two disagree. A client might ask for a field the route stopped returning, a status might go unhandled, or a queue might have no consumer. It reads the code itself, without a model or network access. This package reads Python. It parses with tree-sitter, binds names the way Python does, and records what each route declares and what each handler reaches.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -15,31 +15,31 @@ The adapter ships inside the CLI, so there is nothing else to install.
|
|
|
15
15
|
## Read a FastAPI service
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
npx suss extract --lang python -f fastapi -f sqlalchemy -f requests -o summaries/python.json
|
|
19
|
-
npx suss check --dir summaries/
|
|
18
|
+
npx @suss/cli extract --lang python -f fastapi -f sqlalchemy -f requests -o summaries/python.json
|
|
19
|
+
npx @suss/cli check --dir summaries/
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
`suss init` reads your requirements file or pyproject and writes those two commands out for your own project.
|
|
23
23
|
|
|
24
24
|
## What it reads
|
|
25
25
|
|
|
26
|
-
- FastAPI and flask-restx routes, including a decorator a project re-exports through a wrapper module
|
|
27
|
-
- The path a route is served under
|
|
28
|
-
- SQLAlchemy calls, `requests` / `httpx` / `aiohttp` call sites, what a file reads from the environment, and what a handler calls out to
|
|
29
|
-
- A statement the project wrote as SQL
|
|
30
|
-
- Environment reads written through a project helper
|
|
26
|
+
- FastAPI and flask-restx routes, including a decorator a project re-exports through a wrapper module. It takes `response_model` and `status_code` as the declared contract.
|
|
27
|
+
- The path a route is served under. It composes `include_router` prefixes through any number of mounts, including a mount written inside a function or spread out of a dictionary.
|
|
28
|
+
- SQLAlchemy calls, `requests` / `httpx` / `aiohttp` call sites, what a file reads from the environment, and what a handler calls out to. These are recorded as facts that the checker's rules run over.
|
|
29
|
+
- A statement the project wrote as SQL. The statement can go to a function the library exports, as with SQLAlchemy's `text`, or to a method on a client object the library gave the project. The value evaluator reads the statement, so an f-string, or a table name kept in another module's constant, reads the same as one written out at the call.
|
|
30
|
+
- Environment reads written through a project helper. With `def env(key): return os.environ[key]`, a call to `env("DATABASE_URL")` is a read of `DATABASE_URL`, however many helpers the name passes through on the way. The helper can be what a factory returned, as in `env = make_reader()`. It can also read through an environment object it received, as when `make_reader(os.environ)` returns `lambda name: env[name]`. Three cases are not covered: a name built with an f-string (`env(f"{prefix}_URL")`), a name the helper takes off a dict, and a helper built by `functools.partial`.
|
|
31
31
|
|
|
32
32
|
How each of those is decided, and where it stops: [how the Python adapter reads a project](./DESIGN.md).
|
|
33
33
|
|
|
34
34
|
## Reading a value
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
Code outside the facility never reads a node's text to find out what a value is. `values/evaluator.ts` is the evaluator. `evaluatedValue` runs the statements ahead of an expression and returns what it comes to. `stringValueOf` returns the string when the value settles to one, so a path built out of an f-string or a module constant reads the same as one written out. `facts/resolve.ts` works out where a name came from, with `writtenValueOf` and `originsOf`. The literal readers in `ast.ts` (`stringLiteralValue`, `booleanLiteralValue`) are for the places where a literal is written out in the source. When one of them cannot read a spelling, add the case to the evaluator's lowering or to the resolution rules. `npm run check:readers` at the repo root fails on a reader written beside a call site instead. [`design/docs-internal/style.md#reading-a-value`](../../../design/docs-internal/style.md#reading-a-value) has the rule.
|
|
37
37
|
|
|
38
38
|
## Where it fits
|
|
39
39
|
|
|
40
|
-
It depends on `@suss/extractor`, `@suss/behavioral-ir`, `@suss/datalog` and `web-tree-sitter`. The `fastapi`, `flask-restx` and `sqlalchemy` packs consume its `PythonPack` contract
|
|
40
|
+
It depends on `@suss/extractor`, `@suss/behavioral-ir`, `@suss/datalog` and `web-tree-sitter`. The `fastapi`, `flask-restx` and `sqlalchemy` packs consume its `PythonPack` contract. Nothing in this package hardcodes what a particular library's decorators are called.
|
|
41
41
|
|
|
42
|
-
`grammar/tree-sitter-python.wasm` is a checked-in binary,
|
|
42
|
+
`grammar/tree-sitter-python.wasm` is a checked-in binary, and the build does not produce it. [Where it comes from](./grammar/README.md).
|
|
43
43
|
|
|
44
44
|
## More
|
|
45
45
|
|