Python: expose Parse RPC on PythonRewriteRpc for explicit file lists#7987
Open
knutwannheden wants to merge 1 commit into
Open
Python: expose Parse RPC on PythonRewriteRpc for explicit file lists#7987knutwannheden wants to merge 1 commit into
knutwannheden wants to merge 1 commit into
Conversation
Expose the existing Parse RPC handler on the Java client so callers can parse an explicit list of Python files with ty rooted at a separate workspace root, rather than walking a whole directory as parseProject does. This lets a build parse one unit at a time (e.g. a single Bazel target) while cross-package first-party imports still resolve against the monorepo root.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PythonRewriteRpc.parseProject(...)walks a whole directory and rootsty(the type resolver) at that directory. That cannot serve a build that wants to parse one unit at a time — an explicit list of files — while resolving first-party imports against a broader workspace root.The concrete driver is a Bazel-monorepo Python build (in the Moderne CLI) that parses one Bazel target at a time: the target's
.pyfiles are an explicit list, butfrom pkg.other_module import Xmust resolve against the workspace root. RootingparseProjectat the monorepo root instead would also parse tens of thousands of unrelated files.The Python server already has a
Parsehandler that takes explicitinputsand rootstyatrelativeTo(and accepts adependencyPath). It was already consumed over the wire byPythonParservia the inheritedRewriteRpc.parse(...), but that path has no way to forwarddependencyPath, and there was no client entry point for "parse these files, resolve types against that root." This adds one.Note: the server's
Parsehandler is left unchanged — it returns bare id strings, which the inheritedRewriteRpc.parse()/PythonParserpath already depends on. Changing its return shape would have broken that path, so the new client reuses the existing bare-id contract with a uniformPy.CompilationUnittype hint (exactly asPythonParseralready does).Examples
Summary
PythonRewriteRpc.parse(List<Path> inputs, @Nullable Path relativeTo, @Nullable Path dependencyPath, ExecutionContext ctx)plus an overload taking per-parseoptions. Sends the existing"Parse"RPC and lazily streams each returned id back as aSourceFileviagetObject(...), mirroringparseProject's plumbing.Parserequest class (mirroringParseProject) carryinginputs(each{ "path": ... }),relativeTo,dependencyPath, andoptions. The coreParserequest is left untouched, so the JS contract is unaffected.parseProjectand the Python server'shandle_parseare unchanged.Test plan
PythonRewriteRpcParseTest: parses an explicit list of two files wherederived.pyimports a class frombase.py, withrelativeToset to their common root. Asserts both come back as attributedPy.CompilationUnits (notParseError) and that the cross-file first-party supertype resolves (theselfreceiver inDerivedis assignable toBase).PythonParserTest(the inheritedparse()RPC path) still passes — confirms theParsehandler's bare-id contract is unchanged.licenseFormatclean.