-
Notifications
You must be signed in to change notification settings - Fork 5
Handle PyInfo removal in bazel 9.x #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,14 @@ directories (the results of other mypy builds), the underlying action first atte | |
directories. | ||
""" | ||
|
||
load("@bazel_features//:features.bzl", "bazel_features") | ||
load("@rules_mypy_pip//:requirements.bzl", "requirement") | ||
load("@rules_python//python:py_binary.bzl", "py_binary") | ||
load("@rules_python//python:py_info.bzl", RulesPythonPyInfo = "PyInfo") | ||
load(":py_type_library.bzl", "PyTypeLibraryInfo") | ||
|
||
_LegacyPyInfo = bazel_features.globals.PyInfo or RulesPythonPyInfo | ||
|
||
MypyCacheInfo = provider( | ||
doc = "Output details of the mypy build rule.", | ||
fields = { | ||
|
@@ -31,8 +34,8 @@ def _extract_import_dir(import_): | |
def _imports(target): | ||
if RulesPythonPyInfo in target: | ||
return target[RulesPythonPyInfo].imports.to_list() | ||
elif PyInfo in target: | ||
return target[PyInfo].imports.to_list() | ||
elif _LegacyPyInfo in target: | ||
return target[_LegacyPyInfo].imports.to_list() | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With
|
||
else: | ||
return [] | ||
|
||
|
@@ -69,7 +72,7 @@ def _mypy_impl(target, ctx): | |
if target.label.workspace_root != "": | ||
return [] | ||
|
||
if RulesPythonPyInfo not in target and PyInfo not in target: | ||
if RulesPythonPyInfo not in target and _LegacyPyInfo not in target: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To align with the suggested refactoring on line 16, this check for the legacy provider should also verify that it exists (is not
|
||
return [] | ||
|
||
# disable if a target is tagged with at least one suppression tag | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definition of
_LegacyPyInfo
can be misleading. On newer Bazel versions wherebazel_features.globals.PyInfo
isNone
, this variable will holdRulesPythonPyInfo
, which is the modern provider. This makes the name inaccurate and leads to redundantelif
checks in_imports
and_mypy_impl
.A clearer approach is to have this variable only hold the legacy provider. This makes the name accurate and simplifies the logic at the call sites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i considered this but didn't really feel worth complicating the callsites when this will be the low traffic path