WIP - Other pip installations methods draft
authorArmen Zambrano G. <armenzg@mozilla.com>
Sun, 07 May 2017 21:14:14 -0400
changeset 573822 b36efb231f734d318a307631cff978a9fa47ed0b
parent 573821 270ab0b73ab7f9ca3fbf8fd8a7006857880dd11f
child 573823 dfa92955d5d79c81c3bc69b8766e6e2a9cb74be3
push id57517
push userarmenzg@mozilla.com
push dateMon, 08 May 2017 01:17:17 +0000
milestone55.0a1
WIP - Other pip installations methods MozReview-Commit-ID: LS8nFripjPh
testing/mozharness/mozharness/base/python.py
--- a/testing/mozharness/mozharness/base/python.py
+++ b/testing/mozharness/mozharness/base/python.py
@@ -848,15 +848,51 @@ class Python3Virtualenv(object):
     @py3_venv_initialized
     def py3_install_modules(self, modules):
         if not os.path.exists(self.py3_venv_path):
             raise Exception('You need to call py3_create_venv() first.')
 
         for m in modules:
             self.run_command('%s install %s' % (self.py3_pip_path, m))
 
+    def _mozharness_pip_args(self):
+        '''We have information in Mozharness configs that apply to pip'''
+        c = self.config
+        pip_args = []
+        # To avoid timeouts with our pypi server, increase default timeout:
+        # https://bugzilla.mozilla.org/show_bug.cgi?id=1007230#c802
+        pip_args += ['--timeout', str(c.get('pip_timeout', 120))]
+
+        if c.get('find_links') and not c["pip_index"]:
+            pip_args += ['--no-index']
+
+        # XXX: Look at the code from https://dxr.mozilla.org/mozilla-central/source/testing/mozharness/mozharness/base/python.py#264-281
+        #      and evaluate what we need from it
+        for find_link in c.get('find_links'):
+            pip_args += ['--find-links', find_link]
+
+        return pip_args
+
+    @py3_venv_initialized
+    def py3_install_requirement_files(self, requirements, pip_args=[],
+                                      use_mozharness_pip_config=True):
+        '''
+        requirements - You can specify multiple requiments paths
+        '''
+        cmd = ['%s install' % self.py3_pip_path]
+        for arg in pip_args:
+            cmd += [' ' + arg]
+
+        if use_mozharness_pip_config:
+            cmd += self._mozharness_pip_args()
+
+        for requirement_path in requirements:
+            cmd += ['-r %s' % requirement_path]
+
+        self.run_command(' '.join(cmd))
+
 
 # __main__ {{{1
 
 if __name__ == '__main__':
     '''TODO: unit tests.
     '''
     pass