Bug 1667152 - Add --requirements argument to mach python r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D91313
This commit is contained in:
Ricky Stewart
2020-11-12 16:06:15 +00:00
parent fc6f299c8f
commit 16489a6d5b

View File

@@ -31,6 +31,7 @@ from mach.decorators import (
CommandProvider,
Command,
)
from mach.util import UserError
here = os.path.abspath(os.path.dirname(__file__))
@@ -53,8 +54,15 @@ class MachCommands(MachCommandBase):
default=False,
help="Use ipython instead of the default Python REPL.",
)
@CommandArgument(
"--requirements",
default=None,
help="Install this requirements file before running Python",
)
@CommandArgument("args", nargs=argparse.REMAINDER)
def python(self, no_virtualenv, no_activate, exec_file, ipython, args):
def python(
self, no_virtualenv, no_activate, exec_file, ipython, requirements, args
):
# Avoid logging the command
self.log_manager.terminal_handler.setLevel(logging.CRITICAL)
@@ -63,6 +71,9 @@ class MachCommands(MachCommandBase):
"PYTHONDONTWRITEBYTECODE": str("1"),
}
if requirements and no_virtualenv:
raise UserError("Cannot pass both --requirements and --no-virtualenv.")
if no_virtualenv:
from mach_bootstrap import mach_sys_path
@@ -73,6 +84,10 @@ class MachCommands(MachCommandBase):
if not no_activate:
self.virtualenv_manager.activate()
python_path = self.virtualenv_manager.python_path
if requirements:
self.virtualenv_manager.install_pip_requirements(
requirements, require_hashes=False
)
if exec_file:
exec(open(exec_file).read())