Skip to content

Commit 19f50d2

Browse files
committed
Merge branch 'main' of https://github.com/bazelbuild/rules_python into feat/default-version-python-hub
Resolve changelog conflict
2 parents 6cbe12a + 413690f commit 19f50d2

File tree

23 files changed

+918
-304
lines changed

23 files changed

+918
-304
lines changed

.github/workflows/stale.yml

Lines changed: 0 additions & 73 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ A brief description of the categories of changes:
3333
have all of the python versions.
3434
* (bzlmod) The default value for the {obj}`--python_version` flag will now be
3535
always set to the default python toolchain version value.
36+
* (whl_filegroup): Provide per default also the `RECORD` file
3637

3738
### Added
38-
* Nothing yet
39+
* (py_wheel) Now supports `compress = (True|False)` to allow disabling
40+
compression to speed up development.
3941

4042
### Removed
4143
* Nothing yet
@@ -87,7 +89,6 @@ A brief description of the categories of changes:
8789
* (toolchain) The {bzl:obj}`gen_python_config_settings` has been fixed to include
8890
the flag_values from the platform definitions.
8991

90-
9192
### Added
9293
* (bzlmod): Toolchain overrides can now be done using the new
9394
{bzl:obj}`python.override`, {bzl:obj}`python.single_version_override` and

python/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ bzl_library(
167167
name = "py_info_bzl",
168168
srcs = ["py_info.bzl"],
169169
deps = [
170+
"//python/private:py_info_bzl",
170171
"//python/private:reexports_bzl",
171-
"//python/private/common:providers_bzl",
172172
"@rules_python_internal//:rules_python_config_bzl",
173173
],
174174
)

python/private/BUILD.bazel

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ bzl_library(
6969
],
7070
)
7171

72+
bzl_library(
73+
name = "builders_bzl",
74+
srcs = ["builders.bzl"],
75+
deps = [
76+
"@bazel_skylib//lib:types",
77+
],
78+
)
79+
7280
bzl_library(
7381
name = "bzlmod_enabled_bzl",
7482
srcs = ["bzlmod_enabled.bzl"],
@@ -269,6 +277,17 @@ bzl_library(
269277
srcs = ["py_executable_info.bzl"],
270278
)
271279

280+
bzl_library(
281+
name = "py_info_bzl",
282+
srcs = ["py_info.bzl"],
283+
deps = [
284+
":builders_bzl",
285+
":reexports_bzl",
286+
":util_bzl",
287+
"@rules_python_internal//:rules_python_config_bzl",
288+
],
289+
)
290+
272291
bzl_library(
273292
name = "py_interpreter_program_bzl",
274293
srcs = ["py_interpreter_program.bzl"],
@@ -380,7 +399,10 @@ bzl_library(
380399
visibility = [
381400
"//:__subpackages__",
382401
],
383-
deps = ["@bazel_skylib//lib:types"],
402+
deps = [
403+
"@bazel_skylib//lib:types",
404+
"@rules_python_internal//:rules_python_config_bzl",
405+
],
384406
)
385407

386408
bzl_library(

python/private/builders.bzl

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Copyright 2024 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Builders to make building complex objects easier."""
15+
16+
load("@bazel_skylib//lib:types.bzl", "types")
17+
18+
def _DepsetBuilder():
19+
"""Create a builder for a depset."""
20+
21+
# buildifier: disable=uninitialized
22+
self = struct(
23+
_order = [None],
24+
add = lambda *a, **k: _DepsetBuilder_add(self, *a, **k),
25+
build = lambda *a, **k: _DepsetBuilder_build(self, *a, **k),
26+
direct = [],
27+
get_order = lambda *a, **k: _DepsetBuilder_get_order(self, *a, **k),
28+
set_order = lambda *a, **k: _DepsetBuilder_set_order(self, *a, **k),
29+
transitive = [],
30+
)
31+
return self
32+
33+
def _DepsetBuilder_add(self, *values):
34+
"""Add value to the depset.
35+
36+
Args:
37+
self: {type}`DepsetBuilder` implicitly added.
38+
*values: {type}`depset | list | object` Values to add to the depset.
39+
The values can be a depset, the non-depset value to add, or
40+
a list of such values to add.
41+
42+
Returns:
43+
{type}`DepsetBuilder`
44+
"""
45+
for value in values:
46+
if types.is_list(value):
47+
for sub_value in value:
48+
if types.is_depset(sub_value):
49+
self.transitive.append(sub_value)
50+
else:
51+
self.direct.append(sub_value)
52+
elif types.is_depset(value):
53+
self.transitive.append(value)
54+
else:
55+
self.direct.append(value)
56+
return self
57+
58+
def _DepsetBuilder_set_order(self, order):
59+
"""Sets the order to use.
60+
61+
Args:
62+
self: {type}`DepsetBuilder` implicitly added.
63+
order: {type}`str` One of the {obj}`depset` `order` values.
64+
65+
Returns:
66+
{type}`DepsetBuilder`
67+
"""
68+
self._order[0] = order
69+
return self
70+
71+
def _DepsetBuilder_get_order(self):
72+
"""Gets the depset order that will be used.
73+
74+
Args:
75+
self: {type}`DepsetBuilder` implicitly added.
76+
77+
Returns:
78+
{type}`str | None` If not previously set, `None` is returned.
79+
"""
80+
return self._order[0]
81+
82+
def _DepsetBuilder_build(self):
83+
"""Creates a {obj}`depset` from the accumulated values.
84+
85+
Args:
86+
self: {type}`DepsetBuilder` implicitly added.
87+
88+
Returns:
89+
{type}`depset`
90+
"""
91+
if not self.direct and len(self.transitive) == 1 and self._order[0] == None:
92+
return self.transitive[0]
93+
else:
94+
kwargs = {}
95+
if self._order[0] != None:
96+
kwargs["order"] = self._order[0]
97+
return depset(direct = self.direct, transitive = self.transitive, **kwargs)
98+
99+
def _RunfilesBuilder():
100+
"""Creates a `RunfilesBuilder`.
101+
102+
Returns:
103+
{type}`RunfilesBuilder`
104+
"""
105+
106+
# buildifier: disable=uninitialized
107+
self = struct(
108+
add = lambda *a, **k: _RunfilesBuilder_add(self, *a, **k),
109+
add_targets = lambda *a, **k: _RunfilesBuilder_add_targets(self, *a, **k),
110+
build = lambda *a, **k: _RunfilesBuilder_build(self, *a, **k),
111+
files = _DepsetBuilder(),
112+
root_symlinks = {},
113+
runfiles = [],
114+
symlinks = {},
115+
)
116+
return self
117+
118+
def _RunfilesBuilder_add(self, *values):
119+
"""Adds a value to the runfiles.
120+
121+
Args:
122+
self: {type}`RunfilesBuilder` implicitly added.
123+
*values: {type}`File | runfiles | list[File] | depset[File] | list[runfiles]`
124+
The values to add.
125+
126+
Returns:
127+
{type}`RunfilesBuilder`
128+
"""
129+
for value in values:
130+
if types.is_list(value):
131+
for sub_value in value:
132+
_RunfilesBuilder_add_internal(self, sub_value)
133+
else:
134+
_RunfilesBuilder_add_internal(self, value)
135+
return self
136+
137+
def _RunfilesBuilder_add_targets(self, targets):
138+
"""Adds runfiles from targets
139+
140+
Args:
141+
self: {type}`RunfilesBuilder` implicitly added.
142+
targets: {type}`list[Target]` targets whose default runfiles
143+
to add.
144+
145+
Returns:
146+
{type}`RunfilesBuilder`
147+
"""
148+
for t in targets:
149+
self.runfiles.append(t[DefaultInfo].default_runfiles)
150+
return self
151+
152+
def _RunfilesBuilder_add_internal(self, value):
153+
if _is_file(value):
154+
self.files.add(value)
155+
elif types.is_depset(value):
156+
self.files.add(value)
157+
elif _is_runfiles(value):
158+
self.runfiles.append(value)
159+
else:
160+
fail("Unhandled value: type {}: {}".format(type(value), value))
161+
162+
def _RunfilesBuilder_build(self, ctx, **kwargs):
163+
"""Creates a {obj}`runfiles` from the accumulated values.
164+
165+
Args:
166+
self: {type}`RunfilesBuilder` implicitly added.
167+
ctx: {type}`ctx` The rule context to use to create the runfiles object.
168+
**kwargs: additional args to pass along to {obj}`ctx.runfiles`.
169+
170+
Returns:
171+
{type}`runfiles`
172+
"""
173+
return ctx.runfiles(
174+
transitive_files = self.files.build(),
175+
symlinks = self.symlinks,
176+
root_symlinks = self.root_symlinks,
177+
**kwargs
178+
).merge_all(self.runfiles)
179+
180+
# Skylib's types module doesn't have is_file, so roll our own
181+
def _is_file(value):
182+
return type(value) == "File"
183+
184+
def _is_runfiles(value):
185+
return type(value) == "runfiles"
186+
187+
builders = struct(
188+
DepsetBuilder = _DepsetBuilder,
189+
RunfilesBuilder = _RunfilesBuilder,
190+
)

python/private/common/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ bzl_library(
2929
srcs = ["attributes.bzl"],
3030
deps = [
3131
":common_bzl",
32-
":providers_bzl",
3332
":py_internal_bzl",
3433
":semantics_bzl",
3534
"//python/private:enum_bzl",
3635
"//python/private:flags_bzl",
36+
"//python/private:py_info_bzl",
3737
"//python/private:reexports_bzl",
3838
"//python/private:rules_cc_srcs_bzl",
3939
"@bazel_skylib//rules:common_settings",
@@ -68,6 +68,7 @@ bzl_library(
6868
":providers_bzl",
6969
":py_internal_bzl",
7070
":semantics_bzl",
71+
"//python/private:py_info_bzl",
7172
"//python/private:reexports_bzl",
7273
"//python/private:rules_cc_srcs_bzl",
7374
],
@@ -133,6 +134,7 @@ bzl_library(
133134
":py_internal_bzl",
134135
"//python/private:flags_bzl",
135136
"//python/private:py_executable_info_bzl",
137+
"//python/private:py_info_bzl",
136138
"//python/private:rules_cc_srcs_bzl",
137139
"//python/private:toolchain_types_bzl",
138140
"@bazel_skylib//lib:dicts",

python/private/common/attributes.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
1717
load("@rules_cc//cc:defs.bzl", "CcInfo")
1818
load("//python/private:enum.bzl", "enum")
1919
load("//python/private:flags.bzl", "PrecompileFlag", "PrecompileSourceRetentionFlag")
20+
load("//python/private:py_info.bzl", "PyInfo")
2021
load("//python/private:reexports.bzl", "BuiltinPyInfo")
2122
load(":common.bzl", "union_attrs")
22-
load(":providers.bzl", "PyInfo")
2323
load(":py_internal.bzl", "py_internal")
2424
load(
2525
":semantics.bzl",

0 commit comments

Comments
 (0)