Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e2d7c06

Browse filesBrowse files
authored
Merge pull request #1 from opbro/long_cmds
Added new rule for putting package files path into a single file to a…
2 parents 708ed86 + 2fb6c07 commit e2d7c06
Copy full SHA for e2d7c06

File tree

Expand file treeCollapse file tree

3 files changed

+71
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+71
-4
lines changed

‎experimental/examples/wheel/BUILD

Copy file name to clipboardExpand all lines: experimental/examples/wheel/BUILD
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
load("//experimental/python:wheel.bzl", "py_package", "py_wheel")
15+
load("//experimental/python:wheel.bzl", "py_package", "py_wheel", "py_wrapped_input_files")
1616
load("//python:defs.bzl", "py_library", "py_test")
1717

1818
package(default_visibility = ["//visibility:public"])
@@ -53,6 +53,11 @@ py_package(
5353
deps = [":main"],
5454
)
5555

56+
py_wrapped_input_files(
57+
name = "wrapped_example_package",
58+
deps = [":example_pkg"],
59+
)
60+
5661
py_wheel(
5762
name = "minimal_with_py_package",
5863
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl"
@@ -62,6 +67,17 @@ py_wheel(
6267
deps = [":example_pkg"],
6368
)
6469

70+
py_wheel(
71+
name = "minimal_with_py_package_wrapped",
72+
# Package data. We're building "example_minimal_package-0.0.1-py3-none-any.whl"
73+
distribution = "example_minimal_package",
74+
python_tag = "py3",
75+
version = "0.0.1",
76+
wrapped_package_lists = [":wrapped_example_package"],
77+
deps = [":example_pkg", ":wrapped_example_package"],
78+
)
79+
80+
6581
# An example that uses all features provided by py_wheel.
6682
py_wheel(
6783
name = "customized",

‎experimental/python/wheel.bzl

Copy file name to clipboardExpand all lines: experimental/python/wheel.bzl
+42-3Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def _py_package_impl(ctx):
3939
transitive = [dep[DefaultInfo].data_runfiles.files for dep in ctx.attr.deps] +
4040
[dep[DefaultInfo].default_runfiles.files for dep in ctx.attr.deps],
4141
)
42-
4342
# TODO: '/' is wrong on windows, but the path separator is not available in skylark.
4443
# Fix this once ctx.configuration has directory separator information.
4544
packages = [p.replace(".", "/") for p in ctx.attr.packages]
@@ -54,8 +53,9 @@ def _py_package_impl(ctx):
5453
for package in packages:
5554
if wheel_path.startswith(package):
5655
filtered_files.append(input_file)
56+
5757
filtered_inputs = depset(direct = filtered_files)
58-
58+
5959
return [DefaultInfo(
6060
files = filtered_inputs,
6161
)]
@@ -81,6 +81,37 @@ Sub-packages are automatically included.
8181
},
8282
)
8383

84+
def _py_wrapped_input_files_impl(ctx):
85+
inputs_to_package = depset(
86+
direct = ctx.files.deps
87+
)
88+
packageinputfile = ctx.actions.declare_file(ctx.attr.name + '_target_wrapped_inputs.txt')
89+
content = ''
90+
for input_file in inputs_to_package.to_list():
91+
content += _input_file_to_arg(input_file) + '\n'
92+
ctx.actions.write(output = packageinputfile, content=content)
93+
94+
return [
95+
DefaultInfo(
96+
files = depset(direct = [packageinputfile])
97+
)
98+
]
99+
100+
101+
102+
py_wrapped_input_files = rule(
103+
implementation = _py_wrapped_input_files_impl,
104+
doc = """
105+
This was created to wrap the input files from py_package and use as in input to py_wheel,
106+
by setting the attribute wrapped_input_files to avoid long command lines for systems that cannot
107+
handle them.
108+
""",
109+
attrs = {
110+
"deps": attr.label_list()
111+
},
112+
)
113+
114+
84115
def _py_wheel_impl(ctx):
85116
outfile = ctx.actions.declare_file("-".join([
86117
ctx.attr.distribution,
@@ -107,7 +138,14 @@ def _py_wheel_impl(ctx):
107138
args.add("--out", outfile.path)
108139
args.add_all(ctx.attr.strip_path_prefixes, format_each = "--strip_path_prefix=%s")
109140

110-
args.add_all(inputs_to_package, format_each = "--input_file=%s", map_each = _input_file_to_arg)
141+
if ctx.attr.wrapped_package_lists:
142+
wrapped_inputs = depset(
143+
direct = ctx.files.wrapped_package_lists
144+
)
145+
print(wrapped_inputs.to_list())
146+
args.add_all(wrapped_inputs, format_each = "--input_file_list=%s")
147+
else:
148+
args.add_all(inputs_to_package, format_each = "--input_file=%s", map_each = _input_file_to_arg)
111149

112150
extra_headers = []
113151
if ctx.attr.author:
@@ -216,6 +254,7 @@ _other_attrs = {
216254
default = [],
217255
doc = "path prefixes to strip from files added to the generated package",
218256
),
257+
"wrapped_package_lists": attr.label_list(),
219258
}
220259

221260
py_wheel = rule(

‎experimental/rules_python/wheelmaker.py

Copy file name to clipboardExpand all lines: experimental/rules_python/wheelmaker.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def main():
242242
help="'package_path;real_path' pairs listing "
243243
"files to be included in the wheel. "
244244
"Can be supplied multiple times.")
245+
contents_group.add_argument(
246+
'--input_file_list', action='append',
247+
help='A file that has all the input files defined as a list to avoid the long command'
248+
)
245249
contents_group.add_argument(
246250
'--console_script', action='append',
247251
help="Defines a 'console_script' entry point. "
@@ -264,6 +268,14 @@ def main():
264268
input_files = [i.split(';') for i in arguments.input_file]
265269
else:
266270
input_files = []
271+
272+
if arguments.input_file_list:
273+
for input_file in arguments.input_file_list:
274+
with open(input_file) as _file:
275+
input_file_list = _file.read().splitlines()
276+
for _input_file in input_file_list:
277+
input_files.append(_input_file.split(';'))
278+
267279
all_files = get_files_to_package(input_files)
268280
# Sort the files for reproducible order in the archive.
269281
all_files = sorted(all_files.items())

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.