@@ -27,6 +27,10 @@ def _path_inside_wheel(input_file):
27
27
fail ("input_file.path '%s' does not start with expected root '%s'" % (input_file .path , root ))
28
28
return input_file .path [len (root ):]
29
29
30
+ def _input_file_to_arg (input_file ):
31
+ """Converts a File object to string for --input_file argument to wheelmaker"""
32
+ return "%s;%s" % (_path_inside_wheel (input_file ), input_file .path )
33
+
30
34
def _py_package_impl (ctx ):
31
35
inputs = depset (
32
36
transitive = [dep [DefaultInfo ].data_runfiles .files for dep in ctx .attr .deps ] +
@@ -83,29 +87,23 @@ def _py_wheel_impl(ctx):
83
87
ctx .attr .platform ,
84
88
]) + ".whl" )
85
89
86
- inputs = depset (
90
+ inputs_to_package = depset (
87
91
direct = ctx .files .deps ,
88
92
)
89
93
90
- arguments = [
91
- "--name" ,
92
- ctx .attr .distribution ,
93
- "--version" ,
94
- ctx .attr .version ,
95
- "--python_tag" ,
96
- ctx .attr .python_tag ,
97
- "--abi" ,
98
- ctx .attr .abi ,
99
- "--platform" ,
100
- ctx .attr .platform ,
101
- "--out" ,
102
- outfile .path ,
103
- ]
94
+ # Inputs to this rule which are not to be packaged.
95
+ # Currently this is only the description file (if used).
96
+ other_inputs = []
97
+
98
+ args = ctx .actions .args ()
99
+ args .add ("--name" , ctx .attr .distribution )
100
+ args .add ("--version" , ctx .attr .version )
101
+ args .add ("--python_tag" , ctx .attr .python_tag )
102
+ args .add ("--abi" , ctx .attr .abi )
103
+ args .add ("--platform" , ctx .attr .platform )
104
+ args .add ("--out" , outfile .path )
104
105
105
- # TODO: Use args api instead of flattening the depset.
106
- for input_file in inputs .to_list ():
107
- arguments .append ("--input_file" )
108
- arguments .append ("%s;%s" % (_path_inside_wheel (input_file ), input_file .path ))
106
+ args .add_all (inputs_to_package , format_each = "--input_file=%s" , map_each = _input_file_to_arg )
109
107
110
108
extra_headers = []
111
109
if ctx .attr .author :
@@ -118,36 +116,30 @@ def _py_wheel_impl(ctx):
118
116
extra_headers .append ("License: %s" % ctx .attr .license )
119
117
120
118
for h in extra_headers :
121
- arguments .append ("--header" )
122
- arguments .append (h )
119
+ args .add ("--header" , h )
123
120
124
121
for c in ctx .attr .classifiers :
125
- arguments .append ("--classifier" )
126
- arguments .append (c )
122
+ args .add ("--classifier" , c )
127
123
128
124
for r in ctx .attr .requires :
129
- arguments .append ("--requires" )
130
- arguments .append (r )
125
+ args .add ("--requires" , r )
131
126
132
127
for option , requirements in ctx .attr .extra_requires .items ():
133
128
for r in requirements :
134
- arguments .append ("--extra_requires" )
135
- arguments .append (r + ";" + option )
129
+ args .add ("--extra_requires" , r + ";" + option )
136
130
137
131
for name , ref in ctx .attr .console_scripts .items ():
138
- arguments .append ("--console_script" )
139
- arguments .append (name + " = " + ref )
132
+ args .add ("--console_script" , name + " = " + ref )
140
133
141
134
if ctx .attr .description_file :
142
135
description_file = ctx .file .description_file
143
- arguments .append ("--description_file" )
144
- arguments .append (description_file .path )
145
- inputs = inputs .union ([description_file ])
136
+ args .add ("--description_file" , description_file )
137
+ other_inputs .append (description_file )
146
138
147
139
ctx .actions .run (
148
- inputs = inputs ,
140
+ inputs = depset ( direct = other_inputs , transitive = [ inputs_to_package ]) ,
149
141
outputs = [outfile ],
150
- arguments = arguments ,
142
+ arguments = [ args ] ,
151
143
executable = ctx .executable ._wheelmaker ,
152
144
progress_message = "Building wheel" ,
153
145
)
0 commit comments