Skip to content

Commit

Permalink
Bug 1667152 - Add --requirements argument to mach python r=ahal
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky Stewart committed Nov 20, 2020
1 parent a2af0ee commit b295203
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion python/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CommandProvider,
Command,
)
from mach.util import UserError

here = os.path.abspath(os.path.dirname(__file__))

Expand All @@ -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)

Expand All @@ -63,6 +71,9 @@ def python(self, no_virtualenv, no_activate, exec_file, ipython, args):
"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

Expand All @@ -73,6 +84,10 @@ def python(self, no_virtualenv, no_activate, exec_file, ipython, args):
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())
Expand Down

0 comments on commit b295203

Please sign in to comment.