12
12
import itertools
13
13
import os
14
14
import sys
15
+ from collections import defaultdict
15
16
16
17
import click
17
18
110
111
is_flag = True ,
111
112
help = "Use on disk cached PyPI indexes list of packages and versions and do not refetch if present." ,
112
113
)
114
+ @click .option (
115
+ "--sdist-only" ,
116
+ "sdist_only" ,
117
+ type = str ,
118
+ metavar = "SDIST" ,
119
+ default = tuple (),
120
+ show_default = False ,
121
+ multiple = True ,
122
+ help = "Package name(s) that come only in sdist format (no wheels). "
123
+ "The command will not fail and exit if no wheel exists for these names" ,
124
+ )
125
+ @click .option (
126
+ "--wheel-only" ,
127
+ "wheel_only" ,
128
+ type = str ,
129
+ metavar = "WHEEL" ,
130
+ default = tuple (),
131
+ show_default = False ,
132
+ multiple = True ,
133
+ help = "Package name(s) that come only in wheel format (no sdist). "
134
+ "The command will not fail and exit if no sdist exists for these names" ,
135
+ )
136
+ @click .option (
137
+ "--no-dist" ,
138
+ "no_dist" ,
139
+ type = str ,
140
+ metavar = "DIST" ,
141
+ default = tuple (),
142
+ show_default = False ,
143
+ multiple = True ,
144
+ help = "Package name(s) that do not come either in wheel or sdist format. "
145
+ "The command will not fail and exit if no distribution exists for these names" ,
146
+ )
113
147
@click .help_option ("-h" , "--help" )
114
148
def fetch_thirdparty (
115
149
requirements_files ,
@@ -122,6 +156,9 @@ def fetch_thirdparty(
122
156
sdists ,
123
157
index_urls ,
124
158
use_cached_index ,
159
+ sdist_only ,
160
+ wheel_only ,
161
+ no_dist ,
125
162
):
126
163
"""
127
164
Download to --dest THIRDPARTY_DIR the PyPI wheels, source distributions,
@@ -204,58 +241,62 @@ def fetch_thirdparty(
204
241
)
205
242
repos .append (repo )
206
243
207
- wheels_fetched = []
208
- wheels_not_found = []
209
-
210
- sdists_fetched = []
211
- sdists_not_found = []
244
+ wheels_or_sdist_not_found = defaultdict (list )
212
245
213
246
for name , version in sorted (required_name_versions ):
214
247
nv = name , version
215
248
print (f"Processing: { name } @ { version } " )
216
249
if wheels :
217
250
for environment in environments :
251
+
218
252
if TRACE :
219
253
print (f" ==> Fetching wheel for envt: { environment } " )
220
- fwfns = utils_thirdparty .download_wheel (
254
+
255
+ fetched = utils_thirdparty .download_wheel (
221
256
name = name ,
222
257
version = version ,
223
258
environment = environment ,
224
259
dest_dir = dest_dir ,
225
260
repos = repos ,
226
261
)
227
- if fwfns :
228
- wheels_fetched .extend (fwfns )
229
- else :
230
- wheels_not_found .append (f"{ name } =={ version } for: { environment } " )
262
+ if not fetched :
263
+ wheels_or_sdist_not_found [f"{ name } =={ version } " ].append (environment )
231
264
if TRACE :
232
265
print (f" NOT FOUND" )
233
266
234
- if sdists :
267
+ if (sdists or
268
+ (f"{ name } =={ version } " in wheels_or_sdist_not_found and name in sdist_only )
269
+ ):
235
270
if TRACE :
236
271
print (f" ==> Fetching sdist: { name } =={ version } " )
272
+
237
273
fetched = utils_thirdparty .download_sdist (
238
274
name = name ,
239
275
version = version ,
240
276
dest_dir = dest_dir ,
241
277
repos = repos ,
242
278
)
243
- if fetched :
244
- sdists_fetched .append (fetched )
245
- else :
246
- sdists_not_found .append (f"{ name } =={ version } " )
279
+ if not fetched :
280
+ wheels_or_sdist_not_found [f"{ name } =={ version } " ].append ("sdist" )
247
281
if TRACE :
248
282
print (f" NOT FOUND" )
249
283
250
- if wheels and wheels_not_found :
251
- print (f"==> MISSING WHEELS" )
252
- for wh in wheels_not_found :
253
- print (f" { wh } " )
284
+ mia = []
285
+ for nv , dists in wheels_or_sdist_not_found .items ():
286
+ name , _ , version = nv .partition ("==" )
287
+ if name in no_dist :
288
+ continue
289
+ sdist_missing = sdists and "sdist" in dists and not name in wheel_only
290
+ if sdist_missing :
291
+ mia .append (f"SDist missing: { nv } { dists } " )
292
+ wheels_missing = wheels and any (d for d in dists if d != "sdist" ) and not name in sdist_only
293
+ if wheels_missing :
294
+ mia .append (f"Wheels missing: { nv } { dists } " )
254
295
255
- if sdists and sdists_not_found :
256
- print ( f"==> MISSING SDISTS" )
257
- for sd in sdists_not_found :
258
- print ( f" { sd } " )
296
+ if mia :
297
+ for m in mia :
298
+ print ( m )
299
+ raise Exception ( mia )
259
300
260
301
print (f"==> FETCHING OR CREATING ABOUT AND LICENSE FILES" )
261
302
utils_thirdparty .fetch_abouts_and_licenses (dest_dir = dest_dir , use_cached_index = use_cached_index )
0 commit comments