Commit bc0378b3 by Eric Coissac

work on the installation script

parent be4be4c6
......@@ -80,7 +80,7 @@ def install_requirements(skip_virtualenv=True,pip=None):
if pip is None:
pip = get_a_pip_module()
try:
requirements = open('requirements.txt').readlines()
requirements = [x.strip() for x in requirements]
......@@ -161,6 +161,9 @@ def pip_install_package(package,directory=None,pip=None):
log.info('installing %s in directory %s' % (package,str(directory)))
if 'http_proxy' in os.environ and 'https_proxy' not in os.environ:
os.environ['https_proxy']=os.environ['http_proxy']
if pip is None:
pip = get_a_pip_module()
......
......@@ -27,10 +27,21 @@ import pkgutil
def is_pip_installed(minversion=PIP_MINVERSION):
try:
import pip # @UnresolvedImport
ok = LooseVersion(pip.__version__) >= LooseVersion(minversion)
except:
log.info("Try to load pip module...")
pipmodule = importlib.import_module('pip')
if hasattr(pipmodule,'__version__'):
ok = LooseVersion(pipmodule.__version__) >= LooseVersion(minversion)
log.info("Pip installed version %s" % pipmodule.__version__)
else:
ok = False
log.info("A too old version of pip is installed on your system")
for m in [x for x in sys.modules if x.startswith('pip.' or x=='pip')]:
del sys.modules[m]
except Exception,e:
ok = False
log.info("No pip installed on your system")
return ok
......@@ -43,8 +54,11 @@ def get_a_pip_module(minversion=PIP_MINVERSION):
if not local_pip:
if not is_pip_installed(minversion):
try:
if 'http_proxy' in os.environ and 'https_proxy' not in os.environ:
os.environ['https_proxy']=os.environ['http_proxy']
pipinstallscript = urllib2.urlopen('https://bootstrap.pypa.io/get-pip.py')
except:
except Exception,e:
print(str(e))
raise DistutilsError,"Pip (>=%s) is not install on your system and I cannot install it" % PIP_MINVERSION
script = pipinstallscript.read()
......@@ -58,30 +72,37 @@ def get_a_pip_module(minversion=PIP_MINVERSION):
ZIPFILE=getpip.ZIPFILE
pip_zip = os.path.join(tmpdir, "pip.zip")
print pip_zip
with open(pip_zip, "wb") as fp:
log.info("Installing temporary pip...")
fp.write(base64.decodestring(ZIPFILE))
log.info(" done.")
# Add the zipfile to sys.path so that we can import it
sys.path = [pip_zip] + sys.path
sys.path.insert(0,pip_zip)
zi = zipimport.zipimporter(pip_zip)
pip = zi.load_module("pip")
pipmodule = importlib.import_module('pip')
# Prepare the CERT certificat for https download
else:
import pip
local_pip.append(pip)
print pip.__file__
# Prepare the CERT certificat for https download
cert_path = os.path.join(tmpdir, "cacert.pem")
cert_path = os.path.join(tmpdir, "cacert.pem")
with open(cert_path, "wb") as cert:
cert.write(pkgutil.get_data("pip._vendor.requests", "cacert.pem"))
os.environ.setdefault("PIP_CERT", cert_path)
certificate = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
with open(cert_path, "wb") as cert:
cert.write(certificate)
assert LooseVersion(pipmodule.__version__) >= minversion, \
os.environ.setdefault("PIP_CERT", cert_path)
assert hasattr(pip,'__version__') and LooseVersion(pip.__version__) >= minversion, \
"Unable to find suitable version of pip get %s instead of %s" % (pipmodule.__version__,
minversion)
local_pip.append(pipmodule)
return local_pip[0]
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