virtualenv_wrapper: emit a short error message when venv fails
The wrapper module is the initial entry point for scripts, it is never
imported & used as a library. As such, if creating a virtualenv fails,
we can emit a short error message and not bother with tracebacks.
BUG=chromium:1109615
TEST=`./run_pytest -h` w/out virtualenv shows the failing command
Change-Id: I4b5ab12f40a2b455db84437ae4db693d7ea5ffa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2319775
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/virtualenv_wrapper.py b/scripts/virtualenv_wrapper.py
index 995eca9..61b9776 100755
--- a/scripts/virtualenv_wrapper.py
+++ b/scripts/virtualenv_wrapper.py
@@ -42,10 +42,14 @@
def _CreateVenv():
"""Create or update chromite venv."""
- return subprocess.check_output([
- _CREATE_VENV_PATH,
- _REQUIREMENTS,
- ]).rstrip().decode('utf-8')
+ result = subprocess.run(
+ [_CREATE_VENV_PATH, _REQUIREMENTS],
+ check=False, stdout=subprocess.PIPE, encoding='utf-8')
+ if result.returncode:
+ print(f'{os.path.basename(sys.argv[0])}: error: {" ".join(result.args)}: '
+ f'exited {result.returncode}', file=sys.stderr)
+ sys.exit(result.returncode)
+ return result.stdout.strip()
def _ExecInVenv(venvdir, args):