Bug 1290765 - Add ability to install requirements.txt files in mozbuild/virtualenv.py, r?gps draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 23 Aug 2016 11:12:39 -0400
changeset 437700 e35ef4eb283704172f4f1dc5ae1fb498ab9da7ca
parent 437246 d38d06f85ef59c5dbb5d4a1a8d895957a78714de
child 437701 8f691a7c401710bb943ed700129c8e807720ccbc
push id35492
push userahalberstadt@mozilla.com
push dateFri, 11 Nov 2016 14:02:36 +0000
reviewersgps
bugs1290765
milestone52.0a1
Bug 1290765 - Add ability to install requirements.txt files in mozbuild/virtualenv.py, r?gps Some mach commands may want to re-use a requirements.txt file rather than installing packages individually. This enables --require-hashes which means all packages and dependencies must be listed with their hashes. For more details, see: https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode MozReview-Commit-ID: 3lOutbcSzIY
python/mozbuild/mozbuild/virtualenv.py
--- a/python/mozbuild/mozbuild/virtualenv.py
+++ b/python/mozbuild/mozbuild/virtualenv.py
@@ -482,16 +482,41 @@ class VirtualenvManager(object):
         args = [
             'install',
             '--use-wheel',
             package,
         ]
 
         return self._run_pip(args)
 
+    def install_pip_requirements(self, path, require_hashes=True):
+        """Install a pip requirements.txt file.
+
+        The supplied path is a text file containing pip requirement
+        specifiers.
+
+        If require_hashes is True, each specifier must contain the
+        expected hash of the downloaded package. See:
+        https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode
+        """
+
+        if not os.path.isabs(path):
+            path = os.path.join(self.topsrcdir, path)
+
+        args = [
+            'install',
+            '--requirement',
+            path,
+        ]
+
+        if require_hashes:
+            args.append('--require-hashes')
+
+        return self._run_pip(args)
+
     def _run_pip(self, args):
         # It's tempting to call pip natively via pip.main(). However,
         # the current Python interpreter may not be the virtualenv python.
         # This will confuse pip and cause the package to attempt to install
         # against the executing interpreter. By creating a new process, we
         # force the virtualenv's interpreter to be used and all is well.
         # It /might/ be possible to cheat and set sys.executable to
         # self.python_path. However, this seems more risk than it's worth.