From aa437063d6d0c1ea99ce99932aefa18d05054824 Mon Sep 17 00:00:00 2001 From: Keisuke Fukuda Date: Tue, 26 Sep 2017 22:56:59 +0900 Subject: [PATCH 1/2] fixed the bug on pip 9 series --- mpienv/py.py | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/mpienv/py.py b/mpienv/py.py index 9b3a623..2df0213 100644 --- a/mpienv/py.py +++ b/mpienv/py.py @@ -6,9 +6,10 @@ import os import os.path import shutil -from subprocess import check_call import sys +import mpienv.pip + def mkdir_p(path): try: @@ -38,34 +39,13 @@ def is_installed(self): return len(libs) > 0 def install(self): - env = os.environ.copy() - - if 'LD_LIBRARY_PATH' not in env: - env['LD_LIBRARY_PATH'] = "" - - with open(os.devnull, 'w') as devnull: - sys.stderr.write( - "Installing {} using pip...".format(self._libname)) - sys.stderr.flush() - sys.stderr.write("build_dir={}\n".format(self._pybuild_dir)) - cmd = ['pip', 'install', - # '-q', - '--no-binary', ':all:', - '-t', self._pylib_dir, - '-b', self._pybuild_dir, - # '--no-cache-dir', - self._libname] - if os.environ.get("MPIENV_PIP_VERBOSE") is not None: - cmd[2:3] = ['-v'] - sys.stderr.write(' '.join(cmd) + "\n") - check_call(cmd, - stdout=sys.stderr, - # stdout=devnull, - env=env) - devnull # NOQA - sys.stderr.write(" done.\n") - sys.stderr.write("{}\n".format(' '.join(cmd))) - sys.stderr.flush() + sys.stderr.write( + "Installing {} using pip...".format(self._libname)) + sys.stderr.flush() + sys.stderr.write("build_dir={}\n".format(self._pybuild_dir)) + mpienv.pip.install(self._libname, self._pylib_dir, self._pybuild_dir) + sys.stderr.write(" done.\n") + sys.stderr.flush() def use(self): pypath = os.environ.get('PYTHONPATH', None) From 3cb551c08cb50b512b606a1c40a4b0eaed1a2abb Mon Sep 17 00:00:00 2001 From: Keisuke Fukuda Date: Tue, 26 Sep 2017 22:57:50 +0900 Subject: [PATCH 2/2] forgot to add pip.py --- mpienv/pip.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 mpienv/pip.py diff --git a/mpienv/pip.py b/mpienv/pip.py new file mode 100644 index 0000000..43e6069 --- /dev/null +++ b/mpienv/pip.py @@ -0,0 +1,66 @@ +# coding: utf-8 + +import os +import re +from subprocess import check_call +from subprocess import PIPE +from subprocess import Popen +import sys + +from mpienv import util + +# We support pip 9.x.x or 1.5 +_pip_ver = None + + +def _get_pip_ver(): + global _pip_ver + + p = Popen(['pip', '--version'], stdout=PIPE) + out, err = p.communicate() + + m = re.match(r'pip (\S+)', util.decode(out)) + ver = m.group(1) + + if ver.startswith("1.5"): + _pip_ver = '1.5' + elif ver.startswith("9"): + _pip_ver = '9' + else: + raise RuntimeError("Error: Unsupported pip version") + + +def install(libname, target_dir, build_dir): + if _pip_ver is None: + _get_pip_ver() + + env = os.environ.copy() + + if 'LD_LIBRARY_PATH' not in env: + env['LD_LIBRARY_PATH'] = "" + + cmd = None + + if _pip_ver == '9': + # 9.x.x + cmd = ['pip', 'install', + # '-q', + '--no-binary', ':all:', + '-t', target_dir, + '-b', build_dir, + # '--no-cache-dir', + libname] + else: + # 1.5.x + cmd = ['pip', 'install', + # '-q', + '-t', target_dir, + '-b', build_dir, + libname] + + if os.environ.get("MPIENV_PIP_VERBOSE") is not None: + cmd[2:3] = ['-v'] + sys.stderr.write("{}\n".format(' '.join(cmd))) + check_call(cmd, + stdout=sys.stderr, + env=env)