From 9773d1f2f1d74b8915bfb81b323679d16fc28260 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Thu, 10 May 2018 19:05:30 +0200 Subject: [PATCH] Bug 1460402 - Create a new class to manage pip install r=ahal MozReview-Commit-ID: JnscCmC4gBt --HG-- extra : rebase_source : ffd9c67d50d1ad8a9d81df3eb48ddac0ee614b6f --- python/mozlint/mozlint/util/__init__.py | 0 python/mozlint/mozlint/util/pip.py | 34 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 python/mozlint/mozlint/util/__init__.py create mode 100644 python/mozlint/mozlint/util/pip.py diff --git a/python/mozlint/mozlint/util/__init__.py b/python/mozlint/mozlint/util/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/python/mozlint/mozlint/util/pip.py b/python/mozlint/mozlint/util/pip.py new file mode 100644 index 000000000000..bf0f71ae6f6a --- /dev/null +++ b/python/mozlint/mozlint/util/pip.py @@ -0,0 +1,34 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from __future__ import print_function +from __future__ import absolute_import + +import subprocess + + +def _run_pip(*args): + """ + Helper function that runs pip with subprocess + """ + try: + subprocess.check_output(['pip'] + list(args), + stderr=subprocess.STDOUT) + return True + except subprocess.CalledProcessError as e: + print(e.output) + return False + + +def reinstall_program(REQ_PATH): + """ + Try to install flake8 at the target version, returns True on success + otherwise prints the otuput of the pip command and returns False + """ + if _run_pip('install', '-U', + '--require-hashes', '-r', + REQ_PATH): + return True + + return False