@@ -226,9 +226,21 @@ def run_egg_info(self, force_root_egg_info=False):
226
226
logger .notify ('Running setup.py egg_info for package from %s' % self .url )
227
227
logger .indent += 2
228
228
try :
229
+
230
+ # if it's distribute>=0.7, it won't contain an importable
231
+ # setuptools, and having an egg-info dir blocks the ability of
232
+ # setup.py to find setuptools plugins, so delete the egg-info dir if
233
+ # no setuptools. it will get recreated by the run of egg_info
234
+ # NOTE: this self.name check only works when installing from a specifier
235
+ # (not archive path/urls)
236
+ # TODO: take this out later
237
+ if self .name == 'distribute' and not os .path .isdir (os .path .join (self .source_dir , 'setuptools' )):
238
+ rmtree (os .path .join (self .source_dir , 'distribute.egg-info' ))
239
+
229
240
script = self ._run_setup_py
230
241
script = script .replace ('__SETUP_PY__' , repr (self .setup_py ))
231
242
script = script .replace ('__PKG_NAME__' , repr (self .name ))
243
+ egg_info_cmd = [sys .executable , '-c' , script , 'egg_info' ]
232
244
# We can't put the .egg-info files at the root, because then the source code will be mistaken
233
245
# for an installed egg, causing problems
234
246
if self .editable or force_root_egg_info :
@@ -239,7 +251,7 @@ def run_egg_info(self, force_root_egg_info=False):
239
251
os .makedirs (egg_info_dir )
240
252
egg_base_option = ['--egg-base' , 'pip-egg-info' ]
241
253
call_subprocess (
242
- [ sys . executable , '-c' , script , 'egg_info' ] + egg_base_option ,
254
+ egg_info_cmd + egg_base_option ,
243
255
cwd = self .source_dir , filter_stdout = self ._filter_install , show_stdout = False ,
244
256
command_level = logger .VERBOSE_DEBUG ,
245
257
command_desc = 'python setup.py egg_info' )
@@ -584,13 +596,12 @@ def install(self, install_options, global_options=(), root=None):
584
596
temp_location = tempfile .mkdtemp ('-record' , 'pip-' )
585
597
record_filename = os .path .join (temp_location , 'install-record.txt' )
586
598
try :
587
- install_args = [
588
- sys .executable , '-c' ,
589
- "import setuptools;__file__=%r;" \
590
- "exec(compile(open(__file__).read().replace('\\ r\\ n', '\\ n'), __file__, 'exec'))" % self .setup_py ] + \
591
- list (global_options ) + [
592
- 'install' ,
593
- '--record' , record_filename ]
599
+ install_args = [sys .executable ]
600
+ install_args .append ('-c' )
601
+ install_args .append (
602
+ "import setuptools;__file__=%r;" \
603
+ "exec(compile(open(__file__).read().replace('\\ r\\ n', '\\ n'), __file__, 'exec'))" % self .setup_py )
604
+ install_args += list (global_options ) + ['install' ,'--record' , record_filename ]
594
605
595
606
if not self .as_egg :
596
607
install_args += ['--single-version-externally-managed' ]
@@ -702,7 +713,15 @@ def check_if_exists(self):
702
713
if self .req is None :
703
714
return False
704
715
try :
705
- self .satisfied_by = pkg_resources .get_distribution (self .req )
716
+ # if we've already set distribute as a conflict to setuptools
717
+ # then this check has already run before. we don't want it to
718
+ # run again, and return False, since it would block the uninstall
719
+ if (self .req .project_name == 'setuptools'
720
+ and self .conflicts_with
721
+ and self .conflicts_with .project_name == 'distribute' ):
722
+ return True
723
+ else :
724
+ self .satisfied_by = pkg_resources .get_distribution (self .req )
706
725
except pkg_resources .DistributionNotFound :
707
726
return False
708
727
except pkg_resources .VersionConflict :
@@ -830,8 +849,7 @@ class RequirementSet(object):
830
849
831
850
def __init__ (self , build_dir , src_dir , download_dir , download_cache = None ,
832
851
upgrade = False , ignore_installed = False , as_egg = False , target_dir = None ,
833
- ignore_dependencies = False , force_reinstall = False , use_user_site = False ,
834
- skip_reqs = {}):
852
+ ignore_dependencies = False , force_reinstall = False , use_user_site = False ):
835
853
self .build_dir = build_dir
836
854
self .src_dir = src_dir
837
855
self .download_dir = download_dir
@@ -849,10 +867,7 @@ def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
849
867
self .reqs_to_cleanup = []
850
868
self .as_egg = as_egg
851
869
self .use_user_site = use_user_site
852
- # Set from --target option
853
- self .target_dir = target_dir
854
- # Requirements (by project name) to be skipped
855
- self .skip_reqs = skip_reqs
870
+ self .target_dir = target_dir #set from --target option
856
871
857
872
def __str__ (self ):
858
873
reqs = [req for req in self .requirements .values ()
@@ -862,9 +877,6 @@ def __str__(self):
862
877
863
878
def add_requirement (self , install_req ):
864
879
name = install_req .name
865
- if name and name .lower () in self .skip_reqs :
866
- logger .notify ("Skipping %s: %s" % ( name , self .skip_reqs [name .lower ()]))
867
- return False
868
880
install_req .as_egg = self .as_egg
869
881
install_req .use_user_site = self .use_user_site
870
882
install_req .target_dir = self .target_dir
@@ -880,7 +892,6 @@ def add_requirement(self, install_req):
880
892
## FIXME: what about other normalizations? E.g., _ vs. -?
881
893
if name .lower () != name :
882
894
self .requirement_aliases [name .lower ()] = name
883
- return True
884
895
885
896
def has_requirement (self , project_name ):
886
897
for name in project_name , project_name .lower ():
@@ -1086,8 +1097,8 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
1086
1097
if is_bundle :
1087
1098
req_to_install .move_bundle_files (self .build_dir , self .src_dir )
1088
1099
for subreq in req_to_install .bundle_requirements ():
1089
- if self . add_requirement (subreq ):
1090
- reqs . append (subreq )
1100
+ reqs . append (subreq )
1101
+ self . add_requirement (subreq )
1091
1102
elif is_wheel :
1092
1103
req_to_install .source_dir = location
1093
1104
req_to_install .url = url .url
@@ -1101,8 +1112,8 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
1101
1112
continue
1102
1113
subreq = InstallRequirement (str (subreq ),
1103
1114
req_to_install )
1104
- if self . add_requirement (subreq ):
1105
- reqs . append (subreq )
1115
+ reqs . append (subreq )
1116
+ self . add_requirement (subreq )
1106
1117
elif self .is_download :
1107
1118
req_to_install .source_dir = location
1108
1119
req_to_install .run_egg_info ()
@@ -1149,8 +1160,8 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
1149
1160
## FIXME: check for conflict
1150
1161
continue
1151
1162
subreq = InstallRequirement (req , req_to_install )
1152
- if self . add_requirement (subreq ):
1153
- reqs . append (subreq )
1163
+ reqs . append (subreq )
1164
+ self . add_requirement (subreq )
1154
1165
if not self .has_requirement (req_to_install .name ):
1155
1166
#'unnamed' requirements will get added here
1156
1167
self .add_requirement (req_to_install )
@@ -1224,11 +1235,36 @@ def install(self, install_options, global_options=(), *args, **kwargs):
1224
1235
to_install = [r for r in self .requirements .values ()
1225
1236
if not r .satisfied_by ]
1226
1237
1238
+ # move distribute>=0.7 to the end because it does not contain an
1239
+ # importable setuptools. by moving it to the end, we ensure it's
1240
+ # setuptools dependency is handled first, which will provide an
1241
+ # importable setuptools package
1242
+ # TODO: take this out later
1243
+ distribute_req = pkg_resources .Requirement .parse ("distribute>=0.7" )
1244
+ for req in to_install :
1245
+ if req .name == 'distribute' and req .installed_version in distribute_req :
1246
+ to_install .remove (req )
1247
+ to_install .append (req )
1248
+
1227
1249
if to_install :
1228
1250
logger .notify ('Installing collected packages: %s' % ', ' .join ([req .name for req in to_install ]))
1229
1251
logger .indent += 2
1230
1252
try :
1231
1253
for requirement in to_install :
1254
+
1255
+ # when installing setuptools>=0.7.2 in py2, we need to force setuptools
1256
+ # to uninstall distribute. In py3, which is always using distribute, this
1257
+ # conversion is already happening in distribute's pkg_resources.
1258
+ # TODO: remove this later
1259
+ setuptools_req = pkg_resources .Requirement .parse ("setuptools>=0.7.2" )
1260
+ if requirement .name == 'setuptools' and requirement .installed_version in setuptools_req :
1261
+ try :
1262
+ existing_distribute = pkg_resources .get_distribution ("distribute" )
1263
+ requirement .conflicts_with = existing_distribute
1264
+ except :
1265
+ # distribute wasn't installed
1266
+ pass
1267
+
1232
1268
if requirement .conflicts_with :
1233
1269
logger .notify ('Found existing installation: %s'
1234
1270
% requirement .conflicts_with )
0 commit comments