From f1c9182f8026ee295aff7f1fc6bc1f4d924bc326 Mon Sep 17 00:00:00 2001
From: lguyot <luc.guyot@epfl.ch>
Date: Mon, 28 May 2018 14:52:25 +0200
Subject: [PATCH] [FIX] Supports pip version >= 10.* AND upgrade pip to 9.0.3

Change-Id: If4a78a905e1dc310ae6aab919c01ea435a36c1d8
---
 Makefile                       |  2 ++
 hbp_nrp_virtual_coach/setup.py | 20 ++++++++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 8edaf7b..ebc9d9d 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,8 @@ COVER_PACKAGES=hbp_nrp_virtual_coach
 DOC_MODULES=hbp_nrp_virtual_coach/doc
 DOC_REPO=--doc-repo ssh://bbpcode.epfl.ch/infra/jekylltest
 
+PYTHON_PIP_VERSION?=pip==9.0.3
+
 ##### DO NOT MODIFY BELOW #####################
 
 ifeq ($(NRP_INSTALL_MODE),user)
diff --git a/hbp_nrp_virtual_coach/setup.py b/hbp_nrp_virtual_coach/setup.py
index ad2d499..1bab640 100644
--- a/hbp_nrp_virtual_coach/setup.py
+++ b/hbp_nrp_virtual_coach/setup.py
@@ -10,25 +10,33 @@ except ImportError:
 import hbp_nrp_virtual_coach
 import pip
 
-from pip.req import parse_requirements
 from optparse import Option
 options = Option('--workaround')
 options.skip_requirements_regex = None
 reqs_file = './requirements.txt'
 # Hack for old pip versions
-# Versions greater than 1.x have a required parameter "session" in
-# parse_requirements
-if pip.__version__.startswith('1.'):
+if pip.__version__.startswith('10.'):
+    # Versions greater or equal to 10.x don't rely on pip.req.parse_requirements
+    install_reqs = list(val.strip() for val in open(reqs_file))
+    reqs = install_reqs
+elif pip.__version__.startswith('1.'):
+    # Versions 1.x rely on pip.req.parse_requirements
+    # but don't require a "session" parameter
+    from pip.req import parse_requirements # pylint:disable=no-name-in-module, import-error
     install_reqs = parse_requirements(reqs_file, options=options)
+    reqs = [str(ir.req) for ir in install_reqs]
 else:
-    from pip.download import PipSession  # pylint:disable=no-name-in-module
+    # Versions greater than 1.x but smaller than 10.x rely on pip.req.parse_requirements
+    # and requires a "session" parameter
+    from pip.req import parse_requirements # pylint:disable=no-name-in-module, import-error
+    from pip.download import PipSession  # pylint:disable=no-name-in-module, import-error
     options.isolated_mode = False
     install_reqs = parse_requirements(  # pylint:disable=unexpected-keyword-arg
         reqs_file,
         session=PipSession,
         options=options
     )
-reqs = [str(ir.req) for ir in install_reqs]
+    reqs = [str(ir.req) for ir in install_reqs]
 
 config = {
     'description': 'Virtual Coach command-line Neurorobotics Platform interface for HBP SP10',
-- 
GitLab