Skip to content

Commit 300c994

Browse files
committed
avoid allocation of a dict when constructing a whl_alias
1 parent 282b696 commit 300c994

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

examples/bzlmod/MODULE.bazel.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/private/pypi/render_pkg_aliases.bzl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,27 @@ def whl_alias(*, repo, version = None, config_setting = None, filename = None, t
167167
if not p.startswith("cp"):
168168
fail("target_platform should start with 'cp' denoting the python version, got: " + p)
169169

170-
kwargs = {
171-
"config_setting": config_setting,
172-
"filename": filename,
173-
"repo": repo,
174-
"target_platforms": target_platforms,
175-
"version": version,
176-
}
170+
def as_dict():
171+
ret = {
172+
"repo": repo,
173+
}
174+
if config_setting:
175+
ret["config_setting"] = config_setting
176+
if filename:
177+
ret["filename"] = filename
178+
if target_platforms:
179+
ret["target_platforms"] = target_platforms
180+
if version:
181+
ret["version"] = version
182+
return ret
183+
177184
return struct(
178-
as_dict = lambda: {k: v for k, v in kwargs.items() if v},
179-
**kwargs
185+
config_setting = config_setting,
186+
filename = filename,
187+
repo = repo,
188+
target_platforms = target_platforms,
189+
version = version,
190+
as_dict = as_dict,
180191
)
181192

182193
def render_multiplatform_pkg_aliases(*, aliases, **kwargs):

0 commit comments

Comments
 (0)