Repository navigation
Python: Add yeast-python infrastructure - #23209
Conversation
This adds a new Rust binary called `yeast-python`, which will eventually house the new YEAST-based parser. At the moment, all it returns is a result in JSON saying "not parsed". You may wonder about the use of `unsafe` in setting up the tree-sitter lanugage. This is a temporary measure that will go away once `tsg-python` can be deleted. It is there due to version differences in the `tree-sitter` dependency between `tsg-python` and `yeast-python`.
4e9b6f5 to
5b6f8ee
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Source-tree Cargo execution can run an untrusted checkout's compiler wrapper, while import-time command validation can abort extraction before the existing parser fallback can run.
4 open issues
What changed in this PR
Adds the foundation for a YEAST-based Python parser within the extractor. The placeholder runs before the existing parsers and always declines parsing, exercising fallback while future changes add translation rules.
Changes:
- Adds a Rust parser CLI with a decoded-source stdin/JSON protocol.
- Integrates YEAST-first parsing and tests fallback, encoding transport, and packaged command validation.
- Connects the new binary to Cargo, Bazel, and extractor packaging.
| File | Description |
|---|---|
python/scripts/create-extractor-pack.sh |
Builds and packages the YEAST binary. |
python/extractor/yeast-python/src/parser.rs |
Constructs the syntax tree and returns the placeholder status. |
python/extractor/yeast-python/src/main.rs |
Implements CLI arguments, stdin input, and JSON output. |
python/extractor/yeast-python/README.md |
Documents placeholder behavior and source transport. |
python/extractor/yeast-python/Cargo.toml |
Defines the crate and its dependencies. |
python/extractor/yeast-python/build.rs |
Compiles the shared Python grammar and scanner. |
python/extractor/yeast-python/BUILD.bazel |
Adds the native binary’s Bazel targets. |
python/extractor/tsg-python/tsp/BUILD.bazel |
Exposes grammar sources for reuse. |
python/extractor/tests/test_yeast_parser.py |
Tests encoding transport and packaged command validation. |
python/extractor/tests/test_diagnostics.py |
Tests parser ordering, fallback, and existing usage counts. |
python/extractor/semmle/python/parser/yeast_parser.py |
Selects the native command and handles source/response transport. |
python/extractor/semmle/python/modules.py |
Attempts YEAST before the existing parser chain. |
python/BUILD.bazel |
Includes YEAST in the platform-specific extractor package. |
misc/bazel/3rdparty/rust_workspace_deps/crates.bzl |
Adds the crate’s Bazel dependency metadata. |
Cargo.toml |
Registers YEAST Python in the shared workspace. |
Cargo.lock |
Records the new crate’s dependency graph. |
Review effort: Max
We insert the new parser into the sequence of parsers _before_ the existing parsers, in anticipation that eventually it will be the only parser. However, if the parse fails for whatever reason (as it will now, since the parser does nothing), it seamlessly falls back to the next parser in the sequence. Also note that -- unlike `tsg-python` -- we pass the UTF-8-encoded source to `yeast-python`. This is because the parser can only handle UTF-8, and not all of the other encodings (e.g. Shift-JIS or Latin-1) that Python (and in particular the old parser) supports. Note that these encodings are not actually handled by `tsg-python` at the moment, but since we're in the process of getting rid of it, there seems to be little reason to fix that up now.
5b6f8ee to
bbb5675
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Automated coverage is incomplete: the workflow omits the yeast-python regression test and relevant path triggers, while mocked wrapper tests cannot detect real executable launch or response failures.
2 open issues
4 resolved since last review
Review effort: Max
| [package] | ||
| name = "yeast-python" | ||
| version = "0.1.0" | ||
| authors = ["Taus Brock-Nannestad <tausbn@github.com>"] |
There was a problem hiding this comment.
Do we want our personal names in here?
There was a problem hiding this comment.
Oh, huh. I wonder how that got added. Copilot must know things.
My full name is pretty easy to find online, but yeah, I might as well make it a bit harder to find. 🙂
There was a problem hiding this comment.
Done (and force-pushed to remove from the commit history).
jketema
left a comment
There was a problem hiding this comment.
LGTM. You might want to delete your name 😄
| @@ -0,0 +1,28 @@ | |||
| use std::path::Path; | |||
There was a problem hiding this comment.
Question: At a high level, why do we need this build script?
There was a problem hiding this comment.
Not sure... Perhaps because it watches the local tree-sitter-python parser files, which are external? I could certainly imagine that Cargo doesn't automatically infer that we should rebuild if various random .c and .h files change.
There was a problem hiding this comment.
Ah, it seems that it's also the presence of tsg-python and its conflicting version of tree-sitter that is the reason. Once we get rid of that, we should be able to simplify the build as well.
| "shared/yeast", | ||
| "shared/yeast-macros", | ||
| "shared/yeast-schema", | ||
| "python/extractor/yeast-python", |
There was a problem hiding this comment.
Love to see (parts of) the Python extractor get included in the workspace 🤩
| tsg_bin="extractor/tsg-python/target/release/tsg-python" | ||
|
|
||
| # Build the yeast-python Rust binary in the repository Cargo workspace. | ||
| cargo build --release --manifest-path extractor/yeast-python/Cargo.toml |
There was a problem hiding this comment.
I think we could get away with this, which is a bit cleaner.
| cargo build --release --manifest-path extractor/yeast-python/Cargo.toml | |
| cargo build --release --project yeast-python |
There was a problem hiding this comment.
Done (and force-pushed, to scrub my name).
Adds the Cargo and Bazel targets, generated dependency metadata, and extractor-pack packaging for `yeast-python`.
Addresses the issue brought up by github-advanced-security. Allow only supported CodeQL platforms and ensure the resolved tools directory and executable remain within the extractor pack before invoking the parser.
bbb5675 to
a8c05f0
Compare


Adds a placeholder Python parser based on YEAST (that currently just reports back that it cannot parse any files), and tries this parser before all other parsers. Future PRs will build up the parser itself, but doing it this way demonstrates that the fallback is working correctly.
Can be reviewed commit-by-commit. The commit messages themselves have further information about some of the design choices.