|
5 | 5 | import os |
6 | 6 | import platform |
7 | 7 | import random |
| 8 | +import subprocess |
8 | 9 | import sys |
9 | 10 | import time |
10 | 11 | import traceback |
@@ -293,24 +294,30 @@ def generate_option_group(parser: optparse.OptionParser, prefix: str = "") -> op |
293 | 294 | def init_from_options(options: Any, client: Optional[str] = None) -> "Client": |
294 | 295 | if getattr(options, "provision", False): |
295 | 296 | requirements_path = os.path.abspath(os.path.join(sys.path[0], "requirements.txt")) |
296 | | - try: |
297 | | - import pip |
298 | | - except ImportError: |
299 | | - traceback.print_exc() |
300 | | - print( |
301 | | - "Module `pip` is not installed. To install `pip`, follow the instructions here: " |
302 | | - "https://pip.pypa.io/en/stable/installing/" |
303 | | - ) |
304 | | - sys.exit(1) |
305 | | - if not pip.main(["install", "--upgrade", "--requirement", requirements_path]): |
306 | | - print( |
307 | | - "{color_green}You successfully provisioned the dependencies for {script}.{end_color}".format( |
308 | | - color_green="\033[92m", |
309 | | - end_color="\033[0m", |
310 | | - script=os.path.splitext(os.path.basename(sys.argv[0]))[0], |
311 | | - ) |
| 297 | + current_python_executable = os.path.abspath(sys.executable) |
| 298 | + provisioning_exit_code = subprocess.call( |
| 299 | + [ |
| 300 | + current_python_executable, |
| 301 | + "-m", |
| 302 | + "pip", |
| 303 | + "install", |
| 304 | + "--upgrade", |
| 305 | + "--requirement", |
| 306 | + requirements_path, |
| 307 | + ] |
| 308 | + ) |
| 309 | + provisioning_succeeded = provisioning_exit_code == 0 |
| 310 | + color_green = "\033[92m" |
| 311 | + color_red = "\033[91m" |
| 312 | + print( |
| 313 | + "{text_color}Dependency provisioning {status_text} for {script}.{end_color}".format( |
| 314 | + text_color=color_green if provisioning_succeeded else color_red, |
| 315 | + end_color="\033[0m", |
| 316 | + script=os.path.splitext(os.path.basename(sys.argv[0]))[0], |
| 317 | + status_text="succeeded" if provisioning_succeeded else "failed", |
312 | 318 | ) |
313 | | - sys.exit(0) |
| 319 | + ) |
| 320 | + sys.exit(provisioning_exit_code) |
314 | 321 |
|
315 | 322 | if options.zulip_client is not None: |
316 | 323 | client = options.zulip_client |
|
0 commit comments