Skip to content

Commit b304fc6

Browse files
authored
fix: keep import path values if Bazel-builtin PyInfo is removed (bazel-contrib#2415)
The collect_imports() function added import strings from BuiltinPyInfo if it was non-None. However, operator precedence caused the `if-else` ternary to ignore both list comprehensions (one for PyInfo and one for BuiltinPyInfo) if BuiltinPyInfo was None. To fix, I rewrote the function as a regular for loop to eliminate the ambiguous looking ternary expression. Fixes: bazel-contrib#2414
1 parent 155efce commit b304fc6

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Unreleased changes template.
5656

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

6162
{#v0-0-0-added}
6263
### Added

python/private/common.bzl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,22 @@ def filter_to_py_srcs(srcs):
263263
return [f for f in srcs if f.extension == "py"]
264264

265265
def collect_imports(ctx, semantics):
266-
return depset(direct = semantics.get_imports(ctx), transitive = [
267-
dep[PyInfo].imports
268-
for dep in ctx.attr.deps
269-
if PyInfo in dep
270-
] + [
271-
dep[BuiltinPyInfo].imports
272-
for dep in ctx.attr.deps
273-
if BuiltinPyInfo in dep
274-
] if BuiltinPyInfo != None else [])
266+
"""Collect the direct and transitive `imports` strings.
267+
268+
Args:
269+
ctx: {type}`ctx` the current target ctx
270+
semantics: semantics object for fetching direct imports.
271+
272+
Returns:
273+
{type}`depset[str]` of import paths
274+
"""
275+
transitive = []
276+
for dep in ctx.attr.deps:
277+
if PyInfo in dep:
278+
transitive.append(dep[PyInfo].imports)
279+
if BuiltinPyInfo != None and BuiltinPyInfo in dep:
280+
transitive.append(dep[BuiltinPyInfo].imports)
281+
return depset(direct = semantics.get_imports(ctx), transitive = transitive)
275282

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy