Skip to content

Commit 7e50e9f

Browse files
committed
remove dead code
1 parent e4cc572 commit 7e50e9f

File tree

3 files changed

+30
-137
lines changed

3 files changed

+30
-137
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: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ which has a "null" version value and will not match version constraints.
7373
def _render_whl_library_alias(
7474
*,
7575
name,
76-
default_config_setting,
7776
aliases,
7877
target_name,
7978
**kwargs):
@@ -97,9 +96,6 @@ def _render_whl_library_alias(
9796
for alias in sorted(aliases, key = lambda x: x.version):
9897
actual = "@{repo}//:{name}".format(repo = alias.repo, name = target_name)
9998
selects.setdefault(actual, []).append(alias.config_setting)
100-
if alias.config_setting == default_config_setting:
101-
selects[actual].append("//conditions:default")
102-
no_match_error = None
10399

104100
return render.alias(
105101
name = name,
@@ -121,7 +117,7 @@ def _render_whl_library_alias(
121117
**kwargs
122118
)
123119

124-
def _render_common_aliases(*, name, aliases, default_config_setting = None, group_name = None):
120+
def _render_common_aliases(*, name, aliases, group_name = None):
125121
lines = [
126122
"""load("@bazel_skylib//lib:selects.bzl", "selects")""",
127123
"""package(default_visibility = ["//visibility:public"])""",
@@ -131,9 +127,7 @@ def _render_common_aliases(*, name, aliases, default_config_setting = None, grou
131127
if aliases:
132128
config_settings = sorted([v.config_setting for v in aliases if v.config_setting])
133129

134-
if not config_settings or default_config_setting in config_settings:
135-
pass
136-
else:
130+
if config_settings:
137131
error_msg = NO_MATCH_ERROR_MESSAGE_TEMPLATE_V2.format(
138132
config_settings = render.indent(
139133
"\n".join(config_settings),
@@ -145,10 +139,6 @@ def _render_common_aliases(*, name, aliases, default_config_setting = None, grou
145139
error_msg = error_msg,
146140
))
147141

148-
# This is to simplify the code in _render_whl_library_alias and to ensure
149-
# that we don't pass a 'default_version' that is not in 'versions'.
150-
default_config_setting = None
151-
152142
lines.append(
153143
render.alias(
154144
name = name,
@@ -159,7 +149,6 @@ def _render_common_aliases(*, name, aliases, default_config_setting = None, grou
159149
[
160150
_render_whl_library_alias(
161151
name = name,
162-
default_config_setting = default_config_setting,
163152
aliases = aliases,
164153
target_name = target_name,
165154
visibility = ["//_groups:__subpackages__"] if name.startswith("_") else None,
@@ -188,7 +177,7 @@ def _render_common_aliases(*, name, aliases, default_config_setting = None, grou
188177

189178
return "\n\n".join(lines)
190179

191-
def render_pkg_aliases(*, aliases, default_config_setting = None, requirement_cycles = None):
180+
def render_pkg_aliases(*, aliases, requirement_cycles = None):
192181
"""Create alias declarations for each PyPI package.
193182
194183
The aliases should be appended to the pip_repository BUILD.bazel file. These aliases
@@ -198,9 +187,6 @@ def render_pkg_aliases(*, aliases, default_config_setting = None, requirement_cy
198187
Args:
199188
aliases: dict, the keys are normalized distribution names and values are the
200189
whl_alias instances.
201-
default_config_setting: the default to be used for the aliases. Effectively
202-
only used in WORKSPACE because we are not setting the value of the
203-
{obj}`--python_version` by default there.
204190
requirement_cycles: any package groups to also add.
205191
206192
Returns:
@@ -229,7 +215,6 @@ def render_pkg_aliases(*, aliases, default_config_setting = None, requirement_cy
229215
"{}/BUILD.bazel".format(normalize_name(name)): _render_common_aliases(
230216
name = normalize_name(name),
231217
aliases = pkg_aliases,
232-
default_config_setting = default_config_setting,
233218
group_name = whl_group_mapping.get(normalize_name(name)),
234219
).strip()
235220
for name, pkg_aliases in aliases.items()

tests/pypi/render_pkg_aliases/render_pkg_aliases_test.bzl

Lines changed: 25 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ _tests.append(_test_legacy_aliases)
110110
def _test_bzlmod_aliases(env):
111111
# Use this function as it is used in pip_repository
112112
actual = render_multiplatform_pkg_aliases(
113-
default_config_setting = "//:my_config_setting",
114113
aliases = {
115114
"bar-baz": [
116115
whl_alias(version = "3.2", repo = "pypi_32_bar_baz", config_setting = "//:my_config_setting"),
@@ -124,6 +123,23 @@ load("@bazel_skylib//lib:selects.bzl", "selects")
124123
125124
package(default_visibility = ["//visibility:public"])
126125
126+
_NO_MATCH_ERROR = \"\"\"\\
127+
No matching wheel for current configuration's Python version.
128+
129+
The current build configuration's Python version doesn't match any of the Python
130+
wheels available for this wheel. This wheel supports the following Python
131+
configuration settings:
132+
//:my_config_setting
133+
134+
To determine the current configuration's Python version, run:
135+
`bazel config <config id>` (shown further below)
136+
and look for
137+
rules_python//python/config_settings:python_version
138+
139+
If the value is missing, then the "default" Python version is being used,
140+
which has a "null" version value and will not match version constraints.
141+
\"\"\"
142+
127143
alias(
128144
name = "bar_baz",
129145
actual = ":pkg",
@@ -133,47 +149,39 @@ alias(
133149
name = "pkg",
134150
actual = selects.with_or(
135151
{
136-
(
137-
"//:my_config_setting",
138-
"//conditions:default",
139-
): "@pypi_32_bar_baz//:pkg",
152+
"//:my_config_setting": "@pypi_32_bar_baz//:pkg",
140153
},
154+
no_match_error = _NO_MATCH_ERROR,
141155
),
142156
)
143157
144158
alias(
145159
name = "whl",
146160
actual = selects.with_or(
147161
{
148-
(
149-
"//:my_config_setting",
150-
"//conditions:default",
151-
): "@pypi_32_bar_baz//:whl",
162+
"//:my_config_setting": "@pypi_32_bar_baz//:whl",
152163
},
164+
no_match_error = _NO_MATCH_ERROR,
153165
),
154166
)
155167
156168
alias(
157169
name = "data",
158170
actual = selects.with_or(
159171
{
160-
(
161-
"//:my_config_setting",
162-
"//conditions:default",
163-
): "@pypi_32_bar_baz//:data",
172+
"//:my_config_setting": "@pypi_32_bar_baz//:data",
164173
},
174+
no_match_error = _NO_MATCH_ERROR,
165175
),
166176
)
167177
168178
alias(
169179
name = "dist_info",
170180
actual = selects.with_or(
171181
{
172-
(
173-
"//:my_config_setting",
174-
"//conditions:default",
175-
): "@pypi_32_bar_baz//:dist_info",
182+
"//:my_config_setting": "@pypi_32_bar_baz//:dist_info",
176183
},
184+
no_match_error = _NO_MATCH_ERROR,
177185
),
178186
)"""
179187

@@ -198,7 +206,6 @@ _tests.append(_test_bzlmod_aliases)
198206

199207
def _test_bzlmod_aliases_with_no_default_version(env):
200208
actual = render_multiplatform_pkg_aliases(
201-
default_config_setting = None,
202209
aliases = {
203210
"bar-baz": [
204211
whl_alias(
@@ -291,106 +298,8 @@ alias(
291298

292299
_tests.append(_test_bzlmod_aliases_with_no_default_version)
293300

294-
def _test_bzlmod_aliases_for_non_root_modules(env):
295-
actual = render_pkg_aliases(
296-
# NOTE @aignas 2024-01-17: if the default X.Y version coincides with the
297-
# versions that are used in the root module, then this would be the same as
298-
# as _test_bzlmod_aliases.
299-
#
300-
# However, if the root module uses a different default version than the
301-
# non-root module, then we will have a no-match-error because the
302-
# default_config_setting is not in the list of the versions in the
303-
# whl_map.
304-
default_config_setting = "//_config:is_python_3.3",
305-
aliases = {
306-
"bar-baz": [
307-
whl_alias(version = "3.2", repo = "pypi_32_bar_baz"),
308-
whl_alias(version = "3.1", repo = "pypi_31_bar_baz"),
309-
],
310-
},
311-
)
312-
313-
want_key = "bar_baz/BUILD.bazel"
314-
want_content = """\
315-
load("@bazel_skylib//lib:selects.bzl", "selects")
316-
317-
package(default_visibility = ["//visibility:public"])
318-
319-
_NO_MATCH_ERROR = \"\"\"\\
320-
No matching wheel for current configuration's Python version.
321-
322-
The current build configuration's Python version doesn't match any of the Python
323-
wheels available for this wheel. This wheel supports the following Python
324-
configuration settings:
325-
//_config:is_python_3.1
326-
//_config:is_python_3.2
327-
328-
To determine the current configuration's Python version, run:
329-
`bazel config <config id>` (shown further below)
330-
and look for
331-
rules_python//python/config_settings:python_version
332-
333-
If the value is missing, then the "default" Python version is being used,
334-
which has a "null" version value and will not match version constraints.
335-
\"\"\"
336-
337-
alias(
338-
name = "bar_baz",
339-
actual = ":pkg",
340-
)
341-
342-
alias(
343-
name = "pkg",
344-
actual = selects.with_or(
345-
{
346-
"//_config:is_python_3.1": "@pypi_31_bar_baz//:pkg",
347-
"//_config:is_python_3.2": "@pypi_32_bar_baz//:pkg",
348-
},
349-
no_match_error = _NO_MATCH_ERROR,
350-
),
351-
)
352-
353-
alias(
354-
name = "whl",
355-
actual = selects.with_or(
356-
{
357-
"//_config:is_python_3.1": "@pypi_31_bar_baz//:whl",
358-
"//_config:is_python_3.2": "@pypi_32_bar_baz//:whl",
359-
},
360-
no_match_error = _NO_MATCH_ERROR,
361-
),
362-
)
363-
364-
alias(
365-
name = "data",
366-
actual = selects.with_or(
367-
{
368-
"//_config:is_python_3.1": "@pypi_31_bar_baz//:data",
369-
"//_config:is_python_3.2": "@pypi_32_bar_baz//:data",
370-
},
371-
no_match_error = _NO_MATCH_ERROR,
372-
),
373-
)
374-
375-
alias(
376-
name = "dist_info",
377-
actual = selects.with_or(
378-
{
379-
"//_config:is_python_3.1": "@pypi_31_bar_baz//:dist_info",
380-
"//_config:is_python_3.2": "@pypi_32_bar_baz//:dist_info",
381-
},
382-
no_match_error = _NO_MATCH_ERROR,
383-
),
384-
)"""
385-
386-
env.expect.that_collection(actual.keys()).contains_exactly([want_key])
387-
env.expect.that_str(actual[want_key]).equals(want_content)
388-
389-
_tests.append(_test_bzlmod_aliases_for_non_root_modules)
390-
391301
def _test_aliases_are_created_for_all_wheels(env):
392302
actual = render_pkg_aliases(
393-
default_config_setting = "//_config:is_python_3.2",
394303
aliases = {
395304
"bar": [
396305
whl_alias(version = "3.1", repo = "pypi_31_bar"),
@@ -414,7 +323,6 @@ _tests.append(_test_aliases_are_created_for_all_wheels)
414323

415324
def _test_aliases_with_groups(env):
416325
actual = render_pkg_aliases(
417-
default_config_setting = "//_config:is_python_3.2",
418326
aliases = {
419327
"bar": [
420328
whl_alias(version = "3.1", repo = "pypi_31_bar"),

0 commit comments

Comments
 (0)