Skip to content

Python: Add yeast-python infrastructure - #23209

Merged
tausbn merged 4 commits into
mainfrom
tausbn/python-yeast-parser-infrastructure
Nov 24, 2026
Merged

tausbn merged 4 commits into
mainfrom
tausbn/python-yeast-parser-infrastructure

Conversation

@tausbn

@tausbn tausbn commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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.

@tausbn tausbn added the no-change-note-required This PR does not need a change note label Nov 23, 2026
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`.
@tausbn
tausbn force-pushed the tausbn/python-yeast-parser-infrastructure branch 2 times, most recently from 4e9b6f5 to 5b6f8ee Compare November 23, 2026 15:43
@tausbn
tausbn requested a max review from Copilot November 23, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread python/extractor/yeast-python/build.rs Resolved
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.
@tausbn
tausbn force-pushed the tausbn/python-yeast-parser-infrastructure branch from 5b6f8ee to bbb5675 Compare November 23, 2026 17:02
@tausbn
tausbn requested a max review from Copilot November 23, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@tausbn
tausbn marked this pull request as ready for review November 24, 2026 12:48
@tausbn
tausbn requested review from a team as code owners November 24, 2026 12:48
[package]
name = "yeast-python"
version = "0.1.0"
authors = ["Taus Brock-Nannestad <tausbn@github.com>"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want our personal names in here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (and force-pushed to remove from the commit history).

jketema
jketema previously approved these changes Nov 24, 2026

@jketema jketema left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. You might want to delete your name 😄

@@ -0,0 +1,28 @@
use std::path::Path;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: At a high level, why do we need this build script?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Cargo.toml
"shared/yeast",
"shared/yeast-macros",
"shared/yeast-schema",
"python/extractor/yeast-python",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see (parts of) the Python extractor get included in the workspace 🤩

Comment thread python/scripts/create-extractor-pack.sh Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could get away with this, which is a bit cleaner.

Suggested change
cargo build --release --manifest-path extractor/yeast-python/Cargo.toml
cargo build --release --project yeast-python

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@tausbn
tausbn force-pushed the tausbn/python-yeast-parser-infrastructure branch from bbb5675 to a8c05f0 Compare November 24, 2026 14:14
@tausbn
tausbn merged commit 3a962bb into main Nov 24, 2026
41 checks passed
@tausbn
tausbn deleted the tausbn/python-yeast-parser-infrastructure branch November 24, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants