mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-01 15:20:55 +00:00
setup: copy in the latest version of ez_setup.py, which works even if setuptools is already imported, or can be imported, into the current Python interpreter, but can't be imported into a new Python interpreter in a subprocess
This actually happens in practice -- this fixes the Desert Island scenario. Thanks to PJE.
This commit is contained in:
parent
922234ec29
commit
f71b9312a5
43
ez_setup.py
43
ez_setup.py
@ -68,10 +68,33 @@ def parse_version(s):
|
|||||||
def setuptools_is_new_enough(required_version):
|
def setuptools_is_new_enough(required_version):
|
||||||
"""Return True if setuptools is already installed and has a version
|
"""Return True if setuptools is already installed and has a version
|
||||||
number >= required_version."""
|
number >= required_version."""
|
||||||
(cin, cout, cerr,) = os.popen3("%s -c \"import setuptools;print setuptools.__version__\"" % (sys.executable,))
|
if 'pkg_resources' in sys.modules:
|
||||||
verstr = cout.read().strip()
|
import pkg_resources
|
||||||
ver = parse_version(verstr)
|
try:
|
||||||
return ver and ver >= parse_version(required_version)
|
pkg_resources.require('setuptools >= %s' % (required_version,))
|
||||||
|
except pkg_resources.VersionConflict:
|
||||||
|
# An insufficiently new version is installed.
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import pkg_resources
|
||||||
|
except ImportError:
|
||||||
|
# Okay it is not installed.
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
pkg_resources.require('setuptools >= %s' % (required_version,))
|
||||||
|
except pkg_resources.VersionConflict:
|
||||||
|
# An insufficiently new version is installed.
|
||||||
|
pkg_resources.__dict__.clear() # "If you want to be absolutely sure... before deleting it." --said PJE on IRC
|
||||||
|
del sys.modules['pkg_resources']
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
pkg_resources.__dict__.clear() # "If you want to be absolutely sure... before deleting it." --said PJE on IRC
|
||||||
|
del sys.modules['pkg_resources']
|
||||||
|
return True
|
||||||
|
|
||||||
def use_setuptools(
|
def use_setuptools(
|
||||||
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
|
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
|
||||||
@ -91,12 +114,12 @@ def use_setuptools(
|
|||||||
if min_version is None:
|
if min_version is None:
|
||||||
min_version = version
|
min_version = version
|
||||||
if not setuptools_is_new_enough(min_version):
|
if not setuptools_is_new_enough(min_version):
|
||||||
egg = download_setuptools(version, download_base, to_dir, download_delay)
|
egg = download_setuptools(version, min_version, download_base, to_dir, download_delay)
|
||||||
sys.path.insert(0, egg)
|
sys.path.insert(0, egg)
|
||||||
import setuptools; setuptools.bootstrap_install_from = egg
|
import setuptools; setuptools.bootstrap_install_from = egg
|
||||||
|
|
||||||
def download_setuptools(
|
def download_setuptools(
|
||||||
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
|
version=DEFAULT_VERSION, min_version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
|
||||||
delay = 15
|
delay = 15
|
||||||
):
|
):
|
||||||
"""Download setuptools from a specified location and return its filename
|
"""Download setuptools from a specified location and return its filename
|
||||||
@ -117,8 +140,8 @@ def download_setuptools(
|
|||||||
if delay:
|
if delay:
|
||||||
log.warn("""
|
log.warn("""
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
This script requires setuptools version %s to run (even to display
|
This script requires setuptools version >= %s to run (even to display
|
||||||
help). I will attempt to download it for you (from
|
help). I will attempt to download setuptools for you (from
|
||||||
%s), but
|
%s), but
|
||||||
you may need to enable firewall access for this script first.
|
you may need to enable firewall access for this script first.
|
||||||
I will start the download in %d seconds.
|
I will start the download in %d seconds.
|
||||||
@ -129,7 +152,7 @@ I will start the download in %d seconds.
|
|||||||
|
|
||||||
and place it in this directory before rerunning this script.)
|
and place it in this directory before rerunning this script.)
|
||||||
---------------------------------------------------------------------------""",
|
---------------------------------------------------------------------------""",
|
||||||
version, download_base, delay, url
|
min_version, download_base, delay, url
|
||||||
); from time import sleep; sleep(delay)
|
); from time import sleep; sleep(delay)
|
||||||
log.warn("Downloading %s", url)
|
log.warn("Downloading %s", url)
|
||||||
src = urllib2.urlopen(url)
|
src = urllib2.urlopen(url)
|
||||||
@ -155,7 +178,7 @@ def main(argv, version=DEFAULT_VERSION):
|
|||||||
else:
|
else:
|
||||||
egg = None
|
egg = None
|
||||||
try:
|
try:
|
||||||
egg = download_setuptools(version, delay=0)
|
egg = download_setuptools(version, min_version=version, delay=0)
|
||||||
sys.path.insert(0,egg)
|
sys.path.insert(0,egg)
|
||||||
from setuptools.command.easy_install import main
|
from setuptools.command.easy_install import main
|
||||||
return main(list(argv)+[egg]) # we're done here
|
return main(list(argv)+[egg]) # we're done here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user