Commit 5a9445cd authored by PJ Eby's avatar PJ Eby

Add bootstrap installation support that "hitches a ride" on other packages

being installed via the normal distutils "setup.py install".  Also, don't
repeatedly download the setuptools egg if it's already in the target
location.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041069
parent 13c8739a
...@@ -63,8 +63,10 @@ def use_setuptools( ...@@ -63,8 +63,10 @@ def use_setuptools(
sys.exit(2) sys.exit(2)
except ImportError: except ImportError:
sys.path.insert(0, download_setuptools(version, download_base, to_dir)) egg = download_setuptools(version, download_base, to_dir)
sys.path.insert(0, egg)
import setuptools; setuptools.bootstrap_install_from = egg
import pkg_resources import pkg_resources
try: try:
pkg_resources.require("setuptools>="+version) pkg_resources.require("setuptools>="+version)
...@@ -78,8 +80,6 @@ def use_setuptools( ...@@ -78,8 +80,6 @@ def use_setuptools(
) % version ) % version
sys.exit(2) sys.exit(2)
def download_setuptools( def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir
): ):
...@@ -95,13 +95,19 @@ def download_setuptools( ...@@ -95,13 +95,19 @@ def download_setuptools(
saveto = os.path.join(to_dir, egg_name) saveto = os.path.join(to_dir, egg_name)
src = dst = None src = dst = None
try: if not os.path.exists(saveto): # Avoid repeated downloads
src = urllib2.urlopen(url) try:
dst = open(saveto,"wb") from distutils import log
shutil.copyfileobj(src,dst) log.warn("Downloading %s", url)
finally: src = urllib2.urlopen(url)
if src: src.close() # Read/write all in one block, so we don't create a corrupt file
if dst: dst.close() # if the download is interrupted.
data = src.read()
dst = open(saveto,"wb")
dst.write(data)
finally:
if src: src.close()
if dst: dst.close()
return os.path.realpath(saveto) return os.path.realpath(saveto)
...@@ -115,12 +121,6 @@ def download_setuptools( ...@@ -115,12 +121,6 @@ def download_setuptools(
def main(argv, version=DEFAULT_VERSION): def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall""" """Install or upgrade setuptools and EasyInstall"""
......
...@@ -15,6 +15,7 @@ __all__ = [ ...@@ -15,6 +15,7 @@ __all__ = [
'find_packages' 'find_packages'
] ]
bootstrap_install_from = None
def find_packages(where='.'): def find_packages(where='.'):
"""Return a list all Python packages found within directory 'where' """Return a list all Python packages found within directory 'where'
...@@ -38,7 +39,6 @@ def find_packages(where='.'): ...@@ -38,7 +39,6 @@ def find_packages(where='.'):
def setup(**attrs): def setup(**attrs):
"""Do package setup """Do package setup
...@@ -56,6 +56,12 @@ class Command(_Command): ...@@ -56,6 +56,12 @@ class Command(_Command):
command_consumes_arguments = False command_consumes_arguments = False
def __init__(self, dist, **kw):
# Add support for keyword arguments
_Command.__init__(self,dist)
for k,v in kw.items():
setattr(self,k,v)
def reinitialize_command(self, command, reinit_subcommands=0, **kw): def reinitialize_command(self, command, reinit_subcommands=0, **kw):
cmd = _Command.reinitialize_command(self, command, reinit_subcommands) cmd = _Command.reinitialize_command(self, command, reinit_subcommands)
for k,v in kw.items(): for k,v in kw.items():
...@@ -74,9 +80,3 @@ class Command(_Command): ...@@ -74,9 +80,3 @@ class Command(_Command):
...@@ -8,6 +8,7 @@ from setuptools.command.install import install ...@@ -8,6 +8,7 @@ from setuptools.command.install import install
from setuptools.command.install_lib import install_lib from setuptools.command.install_lib import install_lib
from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from distutils.errors import DistutilsSetupError from distutils.errors import DistutilsSetupError
import setuptools
sequence = tuple, list sequence = tuple, list
...@@ -36,7 +37,6 @@ sequence = tuple, list ...@@ -36,7 +37,6 @@ sequence = tuple, list
class Distribution(_Distribution): class Distribution(_Distribution):
...@@ -348,18 +348,18 @@ class Distribution(_Distribution): ...@@ -348,18 +348,18 @@ class Distribution(_Distribution):
return not not self.requires return not not self.requires
def run_commands(self):
if setuptools.bootstrap_install_from and 'install' in self.commands:
# Bootstrap self-installation of setuptools
from easy_install import easy_install
cmd = easy_install(
self, args=[setuptools.bootstrap_install_from], zip_ok=1
)
cmd.ensure_finalized()
cmd.run()
setuptools.bootstrap_install_from = None
_Distribution.run_commands(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment