@@ -82,8 +82,7 @@ def pip_config_settings(
82
82
target_platforms = [],
83
83
name = None ,
84
84
visibility = None ,
85
- alias_rule = None ,
86
- config_setting_rule = None ):
85
+ native = native ):
87
86
"""Generate all of the pip config settings.
88
87
89
88
Args:
@@ -100,10 +99,9 @@ def pip_config_settings(
100
99
constraint values for each condition.
101
100
visibility (list[str], optional): The visibility to be passed to the
102
101
exposed labels. All other labels will be private.
103
- alias_rule (rule): The alias rule to use for creating the
104
- objects. Can be overridden for unit tests reasons.
105
- config_setting_rule (rule): The config setting rule to use for creating the
106
- objects. Can be overridden for unit tests reasons.
102
+ native (struct): The struct containing alias and config_setting rules
103
+ to use for creating the objects. Can be overridden for unit tests
104
+ reasons.
107
105
"""
108
106
109
107
glibc_versions = ["" ] + glibc_versions
@@ -114,38 +112,25 @@ def pip_config_settings(
114
112
for t in target_platforms
115
113
]
116
114
117
- alias_rule = alias_rule or native .alias
118
- config_setting_rule = config_setting_rule or _dist_config_setting
119
-
120
- for version in ["default" ] + python_versions :
121
- is_python = "is_python_{}" .format (version )
122
- alias_rule (
115
+ for python_version in ["" ] + python_versions :
116
+ is_python = "is_python_{}" .format (python_version or "version_unset" )
117
+ native .alias (
123
118
name = is_python ,
124
119
actual = Label ("//python/config_settings:" + is_python ),
125
120
visibility = visibility ,
126
121
)
127
122
128
- for os , cpu in target_platforms :
129
- constraint_values = []
130
- suffix = ""
131
- if os :
132
- constraint_values .append ("@platforms//os:" + os )
133
- suffix += "_" + os
134
- if cpu :
135
- constraint_values .append ("@platforms//cpu:" + cpu )
136
- suffix += "_" + cpu
137
-
138
- for python_version in ["" ] + python_versions :
139
- sdist = "cp{}_sdist" .format (python_version ) if python_version else "sdist"
140
- config_setting_rule (
141
- name = "is_{}{}" .format (sdist , suffix ),
142
- python_version = python_version ,
143
- flag_values = {_flags .dist : "" },
144
- is_pip_whl = FLAGS .is_pip_whl_no ,
145
- constraint_values = constraint_values ,
146
- visibility = visibility ,
147
- )
148
- _whl_config_settings (
123
+ for os , cpu in target_platforms :
124
+ constraint_values = []
125
+ suffix = ""
126
+ if os :
127
+ constraint_values .append ("@platforms//os:" + os )
128
+ suffix += "_" + os
129
+ if cpu :
130
+ constraint_values .append ("@platforms//cpu:" + cpu )
131
+ suffix += "_" + cpu
132
+
133
+ _dist_config_settings (
149
134
suffix = suffix ,
150
135
plat_flag_values = _plat_flag_values (
151
136
os = os ,
@@ -156,39 +141,45 @@ def pip_config_settings(
156
141
),
157
142
constraint_values = constraint_values ,
158
143
python_version = python_version ,
159
- is_pip_whl = FLAGS . is_pip_whl_only ,
144
+ is_python = is_python ,
160
145
visibility = visibility ,
161
- config_setting_rule = config_setting_rule ,
146
+ native = native ,
162
147
)
163
148
164
- def _whl_config_settings (* , suffix , plat_flag_values , config_setting_rule , ** kwargs ):
165
- # With the following three we cover different per-version wheels
166
- python_version = kwargs .get ("python_version" )
167
- py = "cp{}_py" .format (python_version ) if python_version else "py"
168
- pycp = "cp{}_cp3x" .format (python_version ) if python_version else "cp3x"
169
-
170
- flag_values = {
171
- _flags .dist : "" ,
172
- }
149
+ def _dist_config_settings (* , suffix , plat_flag_values , ** kwargs ):
150
+ flag_values = {_flags .dist : "" }
151
+
152
+ # First create an sdist, we will be building upon the flag values, which
153
+ # will ensure that each sdist config setting is the least specialized of
154
+ # all. However, we need at least one flag value to cover the case where we
155
+ # have `sdist` for any platform, hence we have a non-empty `flag_values`
156
+ # here.
157
+ _dist_config_setting (
158
+ name = "sdist{}" .format (suffix ),
159
+ flag_values = flag_values ,
160
+ is_pip_whl = FLAGS .is_pip_whl_no ,
161
+ ** kwargs
162
+ )
173
163
174
- for name , f in {
175
- "is_{}_none_any{}" . format ( py , suffix ): _flags .whl_py2_py3 ,
176
- "is_{}3_none_any{}" . format ( py , suffix ): _flags .whl_py3 ,
177
- "is_{}3_abi3_any{}" . format ( py , suffix ): _flags .whl_py3_abi3 ,
178
- "is_{}_none_any{}" . format ( pycp , suffix ): _flags .whl_pycp3x ,
179
- "is_{}_abi3_any{}" . format ( pycp , suffix ): _flags .whl_pycp3x_abi3 ,
180
- "is_{}_cp_any{}" . format ( pycp , suffix ): _flags .whl_pycp3x_abicp ,
181
- }. items () :
164
+ for name , f in [
165
+ ( "py_none" , _flags .whl_py2_py3 ) ,
166
+ ( "py3_none" , _flags .whl_py3 ) ,
167
+ ( "py3_abi3" , _flags .whl_py3_abi3 ) ,
168
+ ( "cp3x_none" , _flags .whl_pycp3x ) ,
169
+ ( "cp3x_abi3" , _flags .whl_pycp3x_abi3 ) ,
170
+ ( "cp3x_cp" , _flags .whl_pycp3x_abicp ) ,
171
+ ] :
182
172
if f in flag_values :
183
173
# This should never happen as all of the different whls should have
184
174
# unique flag values.
185
175
fail ("BUG: the flag {} is attempted to be added twice to the list" .format (f ))
186
176
else :
187
177
flag_values [f ] = ""
188
178
189
- config_setting_rule (
190
- name = name ,
179
+ _dist_config_setting (
180
+ name = "{}_any{}" . format ( name , suffix ) ,
191
181
flag_values = flag_values ,
182
+ is_pip_whl = FLAGS .is_pip_whl_only ,
192
183
** kwargs
193
184
)
194
185
@@ -197,24 +188,25 @@ def _whl_config_settings(*, suffix, plat_flag_values, config_setting_rule, **kwa
197
188
for (suffix , flag_values ) in plat_flag_values :
198
189
flag_values = flag_values | generic_flag_values
199
190
200
- for name , f in {
201
- "is_{}_none_{}" . format ( py , suffix ): _flags .whl_plat ,
202
- "is_{}3_none_{}" . format ( py , suffix ): _flags .whl_plat_py3 ,
203
- "is_{}3_abi3_{}" . format ( py , suffix ): _flags .whl_plat_py3_abi3 ,
204
- "is_{}_none_{}" . format ( pycp , suffix ): _flags .whl_plat_pycp3x ,
205
- "is_{}_abi3_{}" . format ( pycp , suffix ): _flags .whl_plat_pycp3x_abi3 ,
206
- "is_{}_cp_{}" . format ( pycp , suffix ): _flags .whl_plat_pycp3x_abicp ,
207
- }. items () :
191
+ for name , f in [
192
+ ( "py_none" , _flags .whl_plat ) ,
193
+ ( "py3_none" , _flags .whl_plat_py3 ) ,
194
+ ( "py3_abi3" , _flags .whl_plat_py3_abi3 ) ,
195
+ ( "cp3x_none" , _flags .whl_plat_pycp3x ) ,
196
+ ( "cp3x_abi3" , _flags .whl_plat_pycp3x_abi3 ) ,
197
+ ( "cp3x_cp" , _flags .whl_plat_pycp3x_abicp ) ,
198
+ ] :
208
199
if f in flag_values :
209
200
# This should never happen as all of the different whls should have
210
201
# unique flag values.
211
202
fail ("BUG: the flag {} is attempted to be added twice to the list" .format (f ))
212
203
else :
213
204
flag_values [f ] = ""
214
205
215
- config_setting_rule (
216
- name = name ,
206
+ _dist_config_setting (
207
+ name = "{}_{}" . format ( name , suffix ) ,
217
208
flag_values = flag_values ,
209
+ is_pip_whl = FLAGS .is_pip_whl_only ,
218
210
** kwargs
219
211
)
220
212
@@ -284,24 +276,28 @@ def _plat_flag_values(os, cpu, osx_versions, glibc_versions, muslc_versions):
284
276
285
277
return ret
286
278
287
- def _dist_config_setting (* , name , is_pip_whl , python_version = "" , ** kwargs ):
279
+ def _dist_config_setting (* , name , is_pip_whl , is_python , python_version , native = native , ** kwargs ):
288
280
"""A macro to create a target that matches is_pip_whl_auto and one more value.
289
281
290
282
Args:
291
283
name: The name of the public target.
292
284
is_pip_whl: The config setting to match in addition to
293
285
`is_pip_whl_auto` when evaluating the config setting.
294
- python_version: The python version to match.
286
+ is_python: The python version config_setting to match.
287
+ python_version: The python version name.
288
+ native (struct): The struct containing alias and config_setting rules
289
+ to use for creating the objects. Can be overridden for unit tests
290
+ reasons.
295
291
**kwargs: The kwargs passed to the config_setting rule. Visibility of
296
292
the main alias target is also taken from the kwargs.
297
293
"""
294
+ name = "is_cp{}_{}" .format (python_version , name ) if python_version else "is_{}" .format (name )
298
295
if python_version :
299
296
_name = name .replace ("is_cp{}" .format (python_version ), "_is" )
300
297
else :
301
298
_name = "_" + name
302
299
303
300
# First match by the python version
304
- is_python = ":is_python_" + (python_version or "default" )
305
301
visibility = kwargs .get ("visibility" )
306
302
native .alias (
307
303
name = name ,
0 commit comments