Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #84 from keisukefukuda/fix-pip-version
Browse files Browse the repository at this point in the history
Fix pip version
  • Loading branch information
keisukefukuda committed Sep 26, 2017
2 parents 83a447f + 3cb551c commit 5a42e7c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 29 deletions.
66 changes: 66 additions & 0 deletions mpienv/pip.py
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 9 additions & 29 deletions mpienv/py.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5a42e7c

Please sign in to comment.