Skip to content

Commit 458139a

Browse files
Merge pull request #19 from estebanzimanyi/fix/vendor-parse-reads-the-mobilitydb-sources
Generate the dispatcher's table from the catalog CI derives, as MobilityAPI does
2 parents 1af9ad8 + b798b02 commit 458139a

19 files changed

Lines changed: 80343 additions & 376200 deletions

‎.github/workflows/python.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,43 @@ jobs:
2020
run: ruff check . || echo "::warning::ruff found issues — please fix before merging"
2121
continue-on-error: true
2222

23+
generated-table:
24+
name: The generated table is what the catalog declares
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.11"
31+
32+
# The MEOS-API catalog, derived here from MobilityDB master by the action
33+
# every binding in the ecosystem uses. It is never committed: it is a
34+
# derived artifact of one MobilityDB commit, and a tracked copy is drift
35+
# waiting to happen.
36+
- name: Derive the MEOS-API catalog
37+
id: provision
38+
uses: MobilityDB/MEOS-API/.github/actions/provision-meos@master
39+
with:
40+
mobilitydb-ref: master
41+
42+
# catalog_gen.py is the catalog's exposable functions projected into
43+
# Python, so it is generated rather than kept by hand, and this is what
44+
# makes the copy in the tree the current one. A function MEOS gains,
45+
# loses or changes arrives here as a difference to regenerate, which is
46+
# the whole reason the table is generated: a hand-kept copy goes stale
47+
# in silence instead.
48+
- name: The generated table is what the catalog declares
49+
run: |
50+
python3 tools/codegen.py -catalog "${{ steps.provision.outputs.catalog-path }}" \
51+
-o mobilityapi/catalog_gen.py
52+
if ! git diff --quiet -- mobilityapi/catalog_gen.py; then
53+
echo "::error::the generated table is not what the catalog declares. Regenerate it: python3 tools/codegen.py -catalog <meos-idl.json>"
54+
git diff --stat -- mobilityapi/catalog_gen.py
55+
git diff -- mobilityapi/catalog_gen.py | head -n 100
56+
exit 1
57+
fi
58+
echo "the committed table is what the catalog of MobilityDB master declares"
59+
2360
python-import:
2461
name: Import smoke test
2562
runs-on: ubuntu-latest

‎.github/workflows/vendor-drift.yml‎

Lines changed: 0 additions & 130 deletions
This file was deleted.

‎GENERATION.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Generation
2+
3+
MobilityAPI-Python is a tier over MEOS, so what it knows about MEOS is
4+
generated from the MEOS-API catalog rather than kept by hand. The generator
5+
lives in `tools/codegen.py`, its output is committed, and CI derives the catalog
6+
from MobilityDB master, regenerates against it, and refuses a difference. This
7+
is the arrangement of MobilityAPI's Go tier, whose generator is
8+
`tools/codegen/main.go`.
9+
10+
## What is generated
11+
12+
`mobilityapi/catalog_gen.py` holds `FUNCTIONS`, one entry per MEOS function the
13+
catalog states as exposable, ordered by name. Each entry is the catalog's own
14+
entry restricted to the keys the dispatcher reads: `name`, `category`,
15+
`params`, `returnType`, `network`, `wire` and `doc`.
16+
`FunctionSignature.from_catalog_entry` reads an entry of the table exactly as it
17+
reads one of the catalog, and the `Dispatcher` serves every function of the
18+
table: `GET /catalog` lists them and `POST /functions/{name}` invokes one.
19+
20+
Run it against a catalog:
21+
22+
```bash
23+
python3 tools/codegen.py -catalog <meos-idl.json> -o mobilityapi/catalog_gen.py
24+
```
25+
26+
A catalog entry without one of the keys the dispatcher reads, or a catalog
27+
stating no function as exposable, stops the generator.
28+
29+
## Where the facts come from
30+
31+
`meos-idl.json` is the machine-readable description of the MEOS C library that
32+
[MEOS-API](https://github.com/MobilityDB/MEOS-API) derives from the MEOS headers
33+
and sources, and that every binding in the ecosystem generates from. Whether a
34+
function is exposable, and how each parameter and the result travel over the
35+
wire, is the catalog's `network` and `wire` projection, which MEOS-API derives
36+
from each function's types, SQL name and group.
37+
38+
The catalog is a derived artifact of one MobilityDB commit, so it is never
39+
committed. CI derives it with
40+
`MobilityDB/MEOS-API/.github/actions/provision-meos@master`, the action every
41+
binding uses, and the `generated-table` job of `.github/workflows/python.yml`
42+
regenerates the table against it. A function MEOS gains, loses or changes on
43+
master arrives there as a difference to regenerate.
44+
45+
To derive the catalog by hand, run MEOS-API's `tools/provision-meos.sh` over a
46+
MobilityDB checkout:
47+
48+
```bash
49+
<MEOS-API>/tools/provision-meos.sh --mdb-src <MobilityDB> --catalog-out meos-idl.json
50+
```

‎Makefile‎

Lines changed: 0 additions & 98 deletions
This file was deleted.

‎mobilityapi/__init__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""MobilityAPI catalog-driven dispatcher package.
22
3-
The MobilityAPI ingestion plan (docs/MEOS_API_INGESTION_PLAN.md) calls for
4-
replacing the hand-written MEOS-dispatching endpoint modules with thin
5-
dispatchers driven by the vendored MEOS-API catalog. This package provides
3+
The MEOS-dispatching endpoints are thin dispatchers driven by the MEOS-API
4+
catalog, through the table mobilityapi/catalog_gen.py that tools/codegen.py
5+
generates from it. This package provides
66
the three foundation pieces the migrating endpoints share:
77
88
- ``Dispatcher`` — catalog-driven function lookup + invocation.

0 commit comments

Comments
 (0)