100
100
"index_urls" ,
101
101
type = str ,
102
102
metavar = "INDEX" ,
103
- default = utils_thirdparty .PYPI_INDEXES ,
103
+ default = utils_thirdparty .PYPI_INDEX_URLS ,
104
104
show_default = True ,
105
105
multiple = True ,
106
106
help = "PyPI index URL(s) to use for wheels and sources, in order of preferences." ,
107
107
)
108
+ @click .option (
109
+ "--use-cached-index" ,
110
+ is_flag = True ,
111
+ help = "Use on disk cached PyPI indexes list of packages and versions and do not refetch if present." ,
112
+ )
113
+
108
114
@click .help_option ("-h" , "--help" )
109
115
def fetch_thirdparty (
110
116
requirements_files ,
@@ -116,26 +122,34 @@ def fetch_thirdparty(
116
122
wheels ,
117
123
sdists ,
118
124
index_urls ,
125
+ use_cached_index ,
119
126
):
120
127
"""
121
- Download to --dest-dir THIRDPARTY_DIR the PyPI wheels, source distributions,
128
+ Download to --dest THIRDPARTY_DIR the PyPI wheels, source distributions,
122
129
and their ABOUT metadata, license and notices files.
123
130
124
131
Download the PyPI packages listed in the combination of:
125
132
- the pip requirements --requirements REQUIREMENT-FILE(s),
126
133
- the pip name==version --specifier SPECIFIER(s)
127
134
- any pre-existing wheels or sdsists found in --dest-dir THIRDPARTY_DIR.
128
135
129
- Download wheels with the --wheels option for the ``--python-version`` PYVER(s)
130
- and ``--operating_system`` OS(s) combinations defaulting to all supported combinations.
136
+ Download wheels with the --wheels option for the ``--python-version``
137
+ PYVER(s) and ``--operating_system`` OS(s) combinations defaulting to all
138
+ supported combinations.
131
139
132
140
Download sdists tarballs with the --sdists option.
133
141
134
- Generate or Download .ABOUT, .LICENSE and .NOTICE files for all the wheels and sources fetched.
142
+ Generate or Download .ABOUT, .LICENSE and .NOTICE files for all the wheels
143
+ and sources fetched.
135
144
136
- Download wheels and sdists the provided PyPI simple --index-url INDEX(s) URLs.
145
+ Download from the provided PyPI simple --index-url INDEX(s) URLs.
137
146
"""
147
+ if not (wheels or sdists ):
148
+ print ("Error: one or both of --wheels and --sdists is required." )
149
+ sys .exit (1 )
150
+
138
151
print (f"COLLECTING REQUIRED NAMES & VERSIONS FROM { dest_dir } " )
152
+
139
153
existing_packages_by_nv = {
140
154
(package .name , package .version ): package
141
155
for package in utils_thirdparty .get_local_packages (directory = dest_dir )
@@ -151,134 +165,88 @@ def fetch_thirdparty(
151
165
required_name_versions .update (nvs )
152
166
153
167
for specifier in specifiers :
154
- nv = utils_requirements .get_name_version (
168
+ nv = utils_requirements .get_required_name_version (
155
169
requirement = specifier ,
156
170
with_unpinned = latest_version ,
157
171
)
158
172
required_name_versions .add (nv )
159
173
174
+ if latest_version :
175
+ names = set (name for name , _version in sorted (required_name_versions ))
176
+ required_name_versions = {(n , None ) for n in names }
177
+
160
178
if not required_name_versions :
161
179
print ("Error: no requirements requested." )
162
180
sys .exit (1 )
163
181
164
- if not os .listdir (dest_dir ) and not (wheels or sdists ):
165
- print ("Error: one or both of --wheels and --sdists is required." )
166
- sys .exit (1 )
167
-
168
- if latest_version :
169
- latest_name_versions = set ()
170
- names = set (name for name , _version in sorted (required_name_versions ))
171
- for name in sorted (names ):
172
- latests = utils_thirdparty .PypiPackage .sorted (
173
- utils_thirdparty .get_package_versions (
174
- name = name , version = None , index_urls = index_urls
175
- )
176
- )
177
- if not latests :
178
- print (f"No distribution found for: { name } " )
179
- continue
180
- latest = latests [- 1 ]
181
- latest_name_versions .add ((latest .name , latest .version ))
182
- required_name_versions = latest_name_versions
183
-
184
- if TRACE :
185
- print ("required_name_versions:" , required_name_versions )
182
+ if TRACE_DEEP :
183
+ print ("required_name_versions:" )
184
+ for n , v in required_name_versions :
185
+ print (f" { n } @ { v } " )
186
186
187
+ # create the environments matrix we need for wheels
188
+ environments = None
187
189
if wheels :
188
- # create the environments matrix we need for wheels
189
190
evts = itertools .product (python_versions , operating_systems )
190
191
environments = [utils_thirdparty .Environment .from_pyver_and_os (pyv , os ) for pyv , os in evts ]
191
192
192
- wheels_not_found = {}
193
- sdists_not_found = {}
194
- # iterate over requirements, one at a time
193
+ # Collect PyPI repos
194
+ repos = []
195
+ for index_url in index_urls :
196
+ index_url = index_url .strip ("/" )
197
+ existing = utils_thirdparty .DEFAULT_PYPI_REPOS_BY_URL .get (index_url )
198
+ if existing :
199
+ existing .use_cached_index = use_cached_index
200
+ repos .append (existing )
201
+ else :
202
+ repo = utils_thirdparty .PypiSimpleRepository (
203
+ index_url = index_url ,
204
+ use_cached_index = use_cached_index ,
205
+ )
206
+ repos .append (repo )
207
+
208
+ wheels_fetched = []
209
+ wheels_not_found = []
210
+
211
+ sdists_fetched = []
212
+ sdists_not_found = []
213
+
195
214
for name , version in sorted (required_name_versions ):
196
215
nv = name , version
197
- existing_package = existing_packages_by_nv . get ( nv )
216
+ print ( f"Processing: { name } @ { version } " )
198
217
if wheels :
199
218
for environment in environments :
200
- if existing_package :
201
- existing_wheels = list (
202
- existing_package .get_supported_wheels (environment = environment )
203
- )
204
- else :
205
- existing_wheels = None
206
-
207
- if existing_wheels :
208
- if TRACE_DEEP :
209
- print (
210
- f"====> Wheels already available: { name } =={ version } on: { environment } : { existing_package .wheels !r} "
211
- )
212
- if all (w .is_pure () for w in existing_wheels ):
213
- break
214
- else :
215
- continue
216
-
217
- if TRACE_DEEP :
218
- print (f"Fetching wheel for: { name } =={ version } on: { environment } " )
219
-
220
- try :
221
- (
222
- fetched_wheel_filenames ,
223
- existing_wheel_filenames ,
224
- ) = utils_thirdparty .download_wheel (
225
- name = name ,
226
- version = version ,
227
- environment = environment ,
228
- dest_dir = dest_dir ,
229
- index_urls = index_urls ,
230
- )
231
- if TRACE :
232
- if existing_wheel_filenames :
233
- print (
234
- f" ====> Wheels already available: { name } =={ version } on: { environment } "
235
- )
236
- for whl in existing_wheel_filenames :
237
- print (f" { whl } " )
238
- if fetched_wheel_filenames :
239
- print (f" ====> Wheels fetched: { name } =={ version } on: { environment } " )
240
- for whl in fetched_wheel_filenames :
241
- print (f" { whl } " )
242
-
243
- fwfns = fetched_wheel_filenames + existing_wheel_filenames
244
-
245
- if all (utils_thirdparty .Wheel .from_filename (f ).is_pure () for f in fwfns ):
246
- break
247
-
248
- except utils_thirdparty .DistributionNotFound as e :
249
- wheels_not_found [f"{ name } =={ version } " ] = str (e )
250
-
251
- if sdists :
252
- if existing_package and existing_package .sdist :
253
219
if TRACE :
254
- print (
255
- f" ====> Sdist already available: { name } =={ version } : { existing_package .sdist !r} "
256
- )
257
- continue
258
-
259
- if TRACE :
260
- print (f" Fetching sdist for: { name } =={ version } " )
261
-
262
- try :
263
- fetched = utils_thirdparty .download_sdist (
220
+ print (f" ==> Fetching wheel for envt: { environment } " )
221
+ fwfns = utils_thirdparty .download_wheel (
264
222
name = name ,
265
223
version = version ,
224
+ environment = environment ,
266
225
dest_dir = dest_dir ,
267
- index_urls = index_urls ,
226
+ repos = repos ,
268
227
)
228
+ if fwfns :
229
+ wheels_fetched .extend (fwfns )
230
+ else :
231
+ wheels_not_found .append (f"{ name } =={ version } for: { environment } " )
232
+ if TRACE :
233
+ print (f" NOT FOUND" )
269
234
235
+ if sdists :
236
+ if TRACE :
237
+ print (f" ==> Fetching sdist: { name } =={ version } " )
238
+ fetched = utils_thirdparty .download_sdist (
239
+ name = name ,
240
+ version = version ,
241
+ dest_dir = dest_dir ,
242
+ repos = repos ,
243
+ )
244
+ if fetched :
245
+ sdists_fetched .append (fetched )
246
+ else :
247
+ sdists_not_found .append (f"{ name } =={ version } " )
270
248
if TRACE :
271
- if not fetched :
272
- print (
273
- f" ====> Sdist already available: { name } =={ version } "
274
- )
275
- else :
276
- print (
277
- f" ====> Sdist fetched: { fetched } for { name } =={ version } "
278
- )
279
-
280
- except utils_thirdparty .DistributionNotFound as e :
281
- sdists_not_found [f"{ name } =={ version } " ] = str (e )
249
+ print (f" NOT FOUND" )
282
250
283
251
if wheels and wheels_not_found :
284
252
print (f"==> MISSING WHEELS" )
@@ -291,7 +259,7 @@ def fetch_thirdparty(
291
259
print (f" { sd } " )
292
260
293
261
print (f"==> FETCHING OR CREATING ABOUT AND LICENSE FILES" )
294
- utils_thirdparty .fetch_abouts_and_licenses (dest_dir = dest_dir )
262
+ utils_thirdparty .fetch_abouts_and_licenses (dest_dir = dest_dir , use_cached_index = use_cached_index )
295
263
utils_thirdparty .clean_about_files (dest_dir = dest_dir )
296
264
297
265
# check for problems
0 commit comments