@@ -256,89 +256,96 @@ def run(self, options, args):
256
256
"cache."
257
257
)
258
258
259
- session = self ._build_session (options )
260
-
261
- finder = self ._build_package_finder (options , index_urls , session )
262
-
263
- requirement_set = RequirementSet (
264
- build_dir = options .build_dir ,
265
- src_dir = options .src_dir ,
266
- download_dir = options .download_dir ,
267
- upgrade = options .upgrade ,
268
- as_egg = options .as_egg ,
269
- ignore_installed = options .ignore_installed ,
270
- ignore_dependencies = options .ignore_dependencies ,
271
- force_reinstall = options .force_reinstall ,
272
- use_user_site = options .use_user_site ,
273
- target_dir = temp_target_dir ,
274
- session = session ,
275
- pycompile = options .compile ,
276
- )
277
- for name in args :
278
- requirement_set .add_requirement (
279
- InstallRequirement .from_line (name , None ))
280
- for name in options .editables :
281
- requirement_set .add_requirement (
282
- InstallRequirement .from_editable (
283
- name ,
284
- default_vcs = options .default_vcs
285
- )
259
+ with self ._build_session (options ) as session :
260
+
261
+ finder = self ._build_package_finder (options , index_urls , session )
262
+
263
+ requirement_set = RequirementSet (
264
+ build_dir = options .build_dir ,
265
+ src_dir = options .src_dir ,
266
+ download_dir = options .download_dir ,
267
+ upgrade = options .upgrade ,
268
+ as_egg = options .as_egg ,
269
+ ignore_installed = options .ignore_installed ,
270
+ ignore_dependencies = options .ignore_dependencies ,
271
+ force_reinstall = options .force_reinstall ,
272
+ use_user_site = options .use_user_site ,
273
+ target_dir = temp_target_dir ,
274
+ session = session ,
275
+ pycompile = options .compile ,
286
276
)
287
- for filename in options .requirements :
288
- for req in parse_requirements (
289
- filename , finder = finder , options = options , session = session ):
290
- requirement_set .add_requirement (req )
291
- if not requirement_set .has_requirements :
292
- opts = {'name' : self .name }
293
- if options .find_links :
294
- msg = ('You must give at least one requirement to %(name)s '
295
- '(maybe you meant "pip %(name)s %(links)s"?)' %
296
- dict (opts , links = ' ' .join (options .find_links )))
297
- else :
298
- msg = ('You must give at least one requirement '
299
- 'to %(name)s (see "pip help %(name)s")' % opts )
300
- logger .warn (msg )
301
- return
302
-
303
- try :
304
- if not options .no_download :
305
- requirement_set .prepare_files (finder )
306
- else :
307
- requirement_set .locate_files ()
308
-
309
- if not options .no_install :
310
- requirement_set .install (
311
- install_options ,
312
- global_options ,
313
- root = options .root_path ,
314
- )
315
- installed = ' ' .join ([req .name for req in
316
- requirement_set .successfully_installed ])
317
- if installed :
318
- logger .notify ('Successfully installed %s' % installed )
319
- else :
320
- downloaded = ' ' .join ([
321
- req .name for req in requirement_set .successfully_downloaded
322
- ])
323
- if downloaded :
324
- logger .notify ('Successfully downloaded %s' % downloaded )
325
- except PreviousBuildDirError :
326
- options .no_clean = True
327
- raise
328
- finally :
329
- # Clean up
330
- if ((not options .no_clean )
331
- and ((not options .no_install ) or options .download_dir )):
332
- requirement_set .cleanup_files ()
333
-
334
- if options .target_dir :
335
- if not os .path .exists (options .target_dir ):
336
- os .makedirs (options .target_dir )
337
- lib_dir = distutils_scheme ('' , home = temp_target_dir )['purelib' ]
338
- for item in os .listdir (lib_dir ):
339
- shutil .move (
340
- os .path .join (lib_dir , item ),
341
- os .path .join (options .target_dir , item ),
277
+ for name in args :
278
+ requirement_set .add_requirement (
279
+ InstallRequirement .from_line (name , None ))
280
+ for name in options .editables :
281
+ requirement_set .add_requirement (
282
+ InstallRequirement .from_editable (
283
+ name ,
284
+ default_vcs = options .default_vcs
285
+ )
342
286
)
343
- shutil .rmtree (temp_target_dir )
344
- return requirement_set
287
+ for filename in options .requirements :
288
+ for req in parse_requirements (
289
+ filename ,
290
+ finder = finder , options = options , session = session ):
291
+ requirement_set .add_requirement (req )
292
+ if not requirement_set .has_requirements :
293
+ opts = {'name' : self .name }
294
+ if options .find_links :
295
+ msg = ('You must give at least one requirement to %(name)s'
296
+ ' (maybe you meant "pip %(name)s %(links)s"?)' %
297
+ dict (opts , links = ' ' .join (options .find_links )))
298
+ else :
299
+ msg = ('You must give at least one requirement '
300
+ 'to %(name)s (see "pip help %(name)s")' % opts )
301
+ logger .warn (msg )
302
+ return
303
+
304
+ try :
305
+ if not options .no_download :
306
+ requirement_set .prepare_files (finder )
307
+ else :
308
+ requirement_set .locate_files ()
309
+
310
+ if not options .no_install :
311
+ requirement_set .install (
312
+ install_options ,
313
+ global_options ,
314
+ root = options .root_path ,
315
+ )
316
+ installed = ' ' .join ([
317
+ req .name for req in
318
+ requirement_set .successfully_installed
319
+ ])
320
+ if installed :
321
+ logger .notify ('Successfully installed %s' % installed )
322
+ else :
323
+ downloaded = ' ' .join ([
324
+ req .name
325
+ for req in requirement_set .successfully_downloaded
326
+ ])
327
+ if downloaded :
328
+ logger .notify (
329
+ 'Successfully downloaded %s' % downloaded
330
+ )
331
+ except PreviousBuildDirError :
332
+ options .no_clean = True
333
+ raise
334
+ finally :
335
+ # Clean up
336
+ if ((not options .no_clean )
337
+ and ((not options .no_install )
338
+ or options .download_dir )):
339
+ requirement_set .cleanup_files ()
340
+
341
+ if options .target_dir :
342
+ if not os .path .exists (options .target_dir ):
343
+ os .makedirs (options .target_dir )
344
+ lib_dir = distutils_scheme ('' , home = temp_target_dir )['purelib' ]
345
+ for item in os .listdir (lib_dir ):
346
+ shutil .move (
347
+ os .path .join (lib_dir , item ),
348
+ os .path .join (options .target_dir , item ),
349
+ )
350
+ shutil .rmtree (temp_target_dir )
351
+ return requirement_set
0 commit comments