Skip to content
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

fix: keep import path values if Bazel-builtin PyInfo is removed #2415

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Unreleased changes template.

{#v0-0-0-fixed}
### Fixed
* Nothing yet.
* (rules) Don't drop custom import paths if Bazel-builtin PyInfo is removed.
([2414](https://github.com/bazelbuild/rules_python/issues/2414)).

{#v0-0-0-added}
### Added
Expand Down
25 changes: 16 additions & 9 deletions python/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,22 @@ def filter_to_py_srcs(srcs):
return [f for f in srcs if f.extension == "py"]

def collect_imports(ctx, semantics):
return depset(direct = semantics.get_imports(ctx), transitive = [
dep[PyInfo].imports
for dep in ctx.attr.deps
if PyInfo in dep
] + [
dep[BuiltinPyInfo].imports
for dep in ctx.attr.deps
if BuiltinPyInfo in dep
] if BuiltinPyInfo != None else [])
"""Collect the direct and transitive `imports` strings.

Args:
ctx: {type}`ctx` the current target ctx
semantics: semantics object for fetching direct imports.

Returns:
{type}`depset[str]` of import paths
"""
transitive = []
for dep in ctx.attr.deps:
if PyInfo in dep:
transitive.append(dep[PyInfo].imports)
if BuiltinPyInfo != None and BuiltinPyInfo in dep:
transitive.append(dep[BuiltinPyInfo].imports)
return depset(direct = semantics.get_imports(ctx), transitive = transitive)

def collect_runfiles(ctx, files = depset()):
"""Collects the necessary files from the rule's context.
Expand Down