fix(ty): unconditionally include main workspace bin directory in import search paths#916
Open
udaya2899 wants to merge 2 commits into
Open
fix(ty): unconditionally include main workspace bin directory in import search paths#916udaya2899 wants to merge 2 commits into
udaya2899 wants to merge 2 commits into
Conversation
Unconditionally initialize 'import_paths' with 'ctx.bin_dir.path' so that generated files from the main workspace are correctly resolved. Without this, for generated dependencies belonging to the main workspace, 'dep.label.workspace_root' evaluates to empty, meaning they are completely skipped from the import search path inclusion. As a result, the static type checker 'ty' is unable to find generated dependencies (such as proto/gRPC _pb2/pb2_grpc files in the main workspace) and throws unresolved-import errors: error[unresolved-import]: Import 'foo.bar.my_proto_pb2' could not be resolved
…ndencies without imports
Author
|
Friendly ping @jbedard |
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.
This PR unconditionally adds
ctx.bin_dir.pathtoimport_pathsfortyaspect.Why?
Currently, lint/ty.bzl only populates import search paths from dep[PyInfo].imports or via dep.label.workspace_root (for external workspaces).
For standard generated targets in the main workspace (like a standard
py_proto_libraryorpy_grpc_librarygenerated from.protosources):PyInfoprovider.workspace_rootevaluates to "" (empty string).This doesn't let ty to resolve generated files' import paths that don't have an
importsattr.Changes are visible to end-users: No
Test plan