You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aa4b256
Browse filesBrowse the repository at this point in the historyBrowse files
chore(codegen): use alphabetical order in the generated API
- Removes scripts/codegen/legacy_order.json and the code that applied it.
- Classes, members, keyword-only parameters, events and TypedDicts are in
alphabetical order; a class comes after the class that it extends or
uses. Positional parameters, union members and TypedDict fields keep
the docs order. Docstrings are wrapped after member links are
rendered. compare_api.py shows no other difference.
- The roll skill, ROLLING.md, CONTRIBUTING.md and update_api.sh now ask
for a microsoft/playwright checkout used only for rolls, on the exact
release-<new> branch, and list the checks that it is on that branch,
clean, and up to date with origin.
Check the checkout before you generate, and again before you commit:
61
+
62
+
```sh
63
+
git -C "$PW_SRC_DIR" rev-parse --abbrev-ref HEAD # must print release-<new>
64
+
git -C "$PW_SRC_DIR" status --porcelain # must print nothing
65
+
git -C "$PW_SRC_DIR" rev-parse HEAD origin/release-<new># both lines must be equal
50
66
```
51
67
52
68
Then bump the pins and assemble the driver:
@@ -73,7 +89,7 @@ the walk.
73
89
74
90
### 3. Identify the commit range
75
91
76
-
Use the nearby `microsoft/playwright` checkout at `$PW_SRC_DIR` (from step 2).
92
+
Use the roll checkout at `$PW_SRC_DIR` (from step 2).
77
93
Bring it up to date and ensure release branches/tags are present before walking
78
94
the range:
79
95
@@ -221,7 +237,7 @@ Tick the box in `/tmp/roll-<new>-commits.md` with one line: `[x] <sha> <subject>
221
237
### 5. Regenerate
222
238
223
239
```sh
224
-
PW_SRC_DIR=../playwright ./scripts/update_api.sh # PW_SRC_DIR already exported in step 2
240
+
./scripts/update_api.sh #uses PW_SRC_DIR from step 2; run the checkout checks there first
225
241
```
226
242
227
243
The script, for `sync` and then `async`:
@@ -250,10 +266,10 @@ Failure modes and fixes:
250
266
| mypy: incompatible argument type in `_generated.py`| The docs type changed, or `_impl/` declares a narrower type. | Match the type in `_impl/`, or record a `typeOverrides` entry for a justified divergence. |
251
267
| generator: `No Python name for the struct at X.y.z`| A new inline `[Object]` with no `* alias:` in the docs. | Name it: `alias-python` upstream, or `structNamesByPlace` / `structRenames`. |
252
268
| generator: `The struct X has different fields at A and B`| Two places in the docs share one struct name, but their fields differ. | Give one place its own name in `structNamesByPlace`, or fix the docs. |
269
+
|`_generated.py` gains or loses members that the commit walk never mentioned |`PW_SRC_DIR` is not on `release-<new>` (for example on `main` or a feature branch), or is behind `origin/release-<new>`. | Run the checkout checks from step 2, fix the checkout, regenerate. |
253
270
| generator: `Unknown docs type "T" at X.y`| A docs type the type table in `generate_api.js` (`toPy`) does not know. | Add it to `toPy`. |
254
271
| generator: `required parameter z follows an optional one`| The docs order params so that Python would need a default before a non-default. | Add a `positional` entry with the Python order. |
255
272
| generator: `the entry "…" no longer matches anything; remove it`| An upstream change made a rules entry unnecessary (or renamed what it points at). | Delete it, or re-key it to the new docs name. |
256
-
| generator: `legacy_order.json: … has no …; remove it`| A member, parameter or TypedDict in the temporary legacy order was removed or renamed upstream. | Delete that name from `scripts/codegen/legacy_order.json`. New members need no entry; they go last. |
257
273
|`pyright … reportInconsistentOverload` (single-event class) | A class gained its first event, so there is one `Literal[…]` overload + impl, which pyright wants ≥2 of. | The generator already handles this — `emitEvents` adds a second `@typing.overload` with `event: str` when a class has exactly one event. |
258
274
|`pre-commit` keeps reformatting `_generated.py` on each run | First run after regen always reformats once; rerun until idle. |`pre-commit run --all-files` to settle. |
259
275
| A kwarg in `_impl/` that the docs don't mention (e.g. legacy name from a doc rename) | Nothing fails: the generator simply never passes it. | If the param is positional with no default, just rename it in `_impl/`. Check `packages/protocol/spec/*.yml` and the server dispatcher — if the wire field renamed too, also update the channel-send dict key. Only use `extraOptions` for genuinely hidden internal kwargs (`default_browser_type`). |
@@ -281,6 +297,8 @@ For each PORT, add one async test and a matching sync test. Conventions:
281
297
282
298
### 8. Final verification
283
299
300
+
Repeat the checkout checks from step 2: the committed `_generated.py` must come from `release-<new>`.
301
+
284
302
```sh
285
303
pre-commit run --all-files
286
304
mypy playwright # 2 pre-existing errors in _json_pipe.py and _artifact.py are unrelated
Copy file name to clipboardExpand all lines: CLAUDE.md
+1-2Lines changed: 1 addition & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,13 +12,12 @@ Python bindings for [Playwright](https://playwright.dev). The Python client talk
12
12
-`playwright/async_api/_generated.py`, `playwright/sync_api/_generated.py`, and the public TypedDicts in `playwright/_impl/_api_structures.py` — **auto-generated** from the upstream API docs. Never edit by hand; rerun `./scripts/update_api.sh` after a roll or after changing `scripts/codegen/`.
13
13
-`scripts/codegen/generate_api.js` — the generator. A Node.js script that loads the upstream doc parser (`utils/doclint/api_parser.js`) from `$PW_SRC_DIR`, filters the docs for Python, and writes the whole public API: signatures, types, docstrings, event overloads, the calls into `_impl/`, and the TypedDicts. It does not read `_impl/`.
14
14
-`scripts/codegen/python_rules.js` — the Python facts that the docs do not contain (positional parameters, struct names and `total=`, type overrides, hidden members). Policy: the shipped Python API wins; each entry is a candidate for an upstream docs fix, and the generator fails on entries that no longer match anything. Every entry needs a one-line rationale comment above it.
15
-
-`scripts/codegen/legacy_order.json` — **temporary**. The old generator's order of classes, members, keyword-only parameters and union members, and the hand-written order of the TypedDicts. The generator applies it, and more old habits marked `TEMPORARY` in the generator, so that the switch to the docs generator has a small diff. New members go last. If the generator reports an entry that no longer matches, remove the entry. A follow-up change deletes the file and the `TEMPORARY` code.
16
15
-`scripts/codegen/compare_api.py` — compares two generated files (signatures, annotations, call bodies, docstrings) and lists every difference. Use it to check that a generator change does not change the API.
17
16
-`tests/async/`, `tests/sync/` — pytest suites. Most new tests are added to the async file with a sync mirror.
18
17
-`DRIVER_VERSION` — the single source of truth for which Playwright release the driver is assembled from (one line, the `playwright-core` npm version, e.g. `1.61.0`, no `v` prefix). Read by `setup.py`, `scripts/build_driver.py`, and CI. The wheel build downloads `playwright-core` at this version from npm plus the matching Node.js binary and assembles the per-platform bundles — no source build. The version is baked into the staged bundle filenames (`driver/playwright-<version>-<suffix>.zip`), so it doubles as the build cache key.
19
18
-`NODE_VERSION` — the Node.js version bundled with the driver (one line, e.g. `24.16.0`). Maintained at roll time by `scripts/update_node_version.py` (latest LTS, mirroring upstream's `utils/build/update-playwright-node.mjs`).
20
19
-`scripts/build_driver.py` — assembles the per-platform driver bundles into `driver/` by downloading the `playwright-core` npm package (`DRIVER_VERSION`) and the official Node.js binaries (`NODE_VERSION`). Fetches `playwright-core` with `npm pack` (needs Node.js/npm on PATH; honours a root `.npmrc`) and the Node.js binaries over plain HTTP; invoked from `setup.py`'s `bdist_wheel` with the target platform's suffix (no arg builds all six).
21
-
- The API docs are **not** shipped in the bundle. `scripts/update_api.sh` reads them from a nearby`microsoft/playwright` checkout (`$PW_SRC_DIR`, at the release branch for `DRIVER_VERSION`). Needed only when regenerating the API, never at runtime.
20
+
- The API docs are **not** shipped in the bundle. `scripts/update_api.sh` reads them from a separate`microsoft/playwright` checkout (`$PW_SRC_DIR`) on the exact release branch for `DRIVER_VERSION`, never from a checkout on `main` or a feature branch. Needed only when regenerating the API, never at runtime.
22
21
-`ROLLING.md`, `CONTRIBUTING.md` — human-facing setup and roll docs.
Copy file name to clipboardExpand all lines: ROLLING.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ pip install -e .
13
13
```
14
14
* change the driver pin in `DRIVER_VERSION` (the `playwright-core` npm version, e.g. `1.61.0`) and refresh `NODE_VERSION`: `python scripts/update_node_version.py`
15
15
* download the new driver: `python -m build --wheel` (fetches `playwright-core` via `npm pack` + the matching Node.js binary and assembles the bundle; no source build).
16
-
* generate API from the docs (needs a nearby`microsoft/playwright` checkout at the release branch for the new version, e.g. `release-1.64`): `PW_SRC_DIR=../playwright ./scripts/update_api.sh`
16
+
* generate API from the docs. This needs a separate`microsoft/playwright` checkout used only for rolls, on the exact release branch for the new version (e.g. `release-1.64`), clean and up to date with `origin`: `PW_SRC_DIR=../playwright-for-python ./scripts/update_api.sh`
17
17
* run `mypy playwright`: every error in `_generated.py` points at an implementation method in `playwright/_impl/` that lacks a new member or option. Implement it there, or record the difference in `scripts/codegen/python_rules.js`.
0 commit comments