diff options
author | George Burgess IV <gbiv@google.com> | 2020-05-13 13:21:18 -0700 |
---|---|---|
committer | George Burgess <gbiv@chromium.org> | 2020-05-13 20:59:05 +0000 |
commit | e7b6e75fe8307e7bbc6a95f9cbc73a410cd2ab4d (patch) | |
tree | 0eb893783bd8ffe2ee2220942c00fbf939b328b0 /toolchain_utils_githooks/check-presubmit.py | |
parent | 27d9f7954d0ebe64182f21db72afb8779583e1ce (diff) | |
download | toolchain-utils-e7b6e75fe8307e7bbc6a95f9cbc73a410cd2ab4d.tar.gz |
githooks: ensure pip + scipy are installed
Now that we always enter the chroot for presubmits, we might try to run
tests in a world where we run `crosperf` tests without `numpy` or
`scipy` installed.
There's probably a better solution here (this one is kinda bad because
presubmits are 'quiet' until we fail, and all of this setup can take up
to a minute), but until we find that, stop the bleeding (aka people
doing `--no-verify`)
BUG=chromium:980719
TEST=Ran crosperf tests with a fresh chroot.
Change-Id: I71275f6be0e38bf086b14d35b8bc4bfffcd7ab18
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2199644
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'toolchain_utils_githooks/check-presubmit.py')
-rwxr-xr-x | toolchain_utils_githooks/check-presubmit.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/toolchain_utils_githooks/check-presubmit.py b/toolchain_utils_githooks/check-presubmit.py index 8f204058..26373342 100755 --- a/toolchain_utils_githooks/check-presubmit.py +++ b/toolchain_utils_githooks/check-presubmit.py @@ -469,8 +469,12 @@ def find_repo_root(base_dir: str) -> t.Optional[str]: return None +def is_in_chroot() -> bool: + return os.path.exists('/etc/cros_chroot_version') + + def maybe_reexec_inside_chroot(autofix: bool, files: t.List[str]) -> None: - if os.path.exists('/etc/cros_chroot_version'): + if is_in_chroot(): return enter_chroot = True @@ -511,6 +515,25 @@ def maybe_reexec_inside_chroot(autofix: bool, files: t.List[str]) -> None: os.execvp(args[0], args) +# FIXME(crbug.com/980719): we probably want a better way of handling this. For +# now, as a workaround, ensure we have all dependencies installed as a part of +# presubmits. pip and scipy are fast enough to install (they take <1min +# combined on my machine), so hoooopefully users won't get too impatient. +def ensure_scipy_installed() -> None: + if not has_executable_on_path('pip'): + print('Autoinstalling `pip`...') + subprocess.check_call(['sudo', 'emerge', 'dev-python/pip']) + + exit_code = subprocess.call( + ['python3', '-c', 'import scipy'], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + if exit_code != 0: + print('Autoinstalling `scipy`...') + subprocess.check_call(['pip', 'install', '--user', 'scipy']) + + def main(argv): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( @@ -533,6 +556,11 @@ def main(argv): if opts.enter_chroot: maybe_reexec_inside_chroot(opts.autofix, opts.files) + # If you ask for --no_enter_chroot, you're on your own for installing these + # things. + if is_in_chroot(): + ensure_scipy_installed() + files = [os.path.abspath(f) for f in files] # Note that we extract .__name__s from these, so please name them in a |