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
--- 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.