Fixed virtualenv management in support directory. The switch from Python 2 to Python 3 creates problems with managing the virtual environment in the support directory if a developer regularly toggles between Python 2 and 3. For example, we want the virtual environment to always use the same version of Python the user uses to invoke the python linter from the command line through mesos-style.py.
This commit fixes the issue by adding a new check in the function of `mesos-style.py` called `should_build_virtualenv` to see if the Python interpreter version currently used is the one in the virtual environement. If not, the virtual environment will get recreated. Review: https://reviews.apache.org/r/67910/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dd07b14d Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dd07b14d Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dd07b14d Branch: refs/heads/master Commit: dd07b14df02d1a944004e63a03d97161c413e706 Parents: 6936fb5 Author: Armand Grillet <agril...@mesosphere.io> Authored: Fri Jul 13 22:10:46 2018 +0200 Committer: Kevin Klues <klue...@gmail.com> Committed: Fri Jul 13 22:41:27 2018 +0200 ---------------------------------------------------------------------- support/mesos-style.py | 10 ++++++++-- support/python3/mesos-style.py | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/dd07b14d/support/mesos-style.py ---------------------------------------------------------------------- diff --git a/support/mesos-style.py b/support/mesos-style.py index 5591be0..f9b4742 100755 --- a/support/mesos-style.py +++ b/support/mesos-style.py @@ -450,11 +450,17 @@ def should_build_virtualenv(modified_files): have changed or if the support script is run with no arguments (meaning that the entire codebase should be linted). """ - # NOTE: If the file list is empty, we are linting the entire - # codebase. We should always rebuild the virtualenv in this case. + # NOTE: If the file list is empty, we are linting the entire test + # codebase. We should always rebuild the vI've irtualenv in this case. if not modified_files: return True + support_dir = os.path.dirname(__file__) + interpreter = os.path.basename(sys.executable) + interpreter = os.path.join(support_dir, '.virtualenv', 'bin', interpreter) + if not os.path.isfile(interpreter): + return True + basenames = [os.path.basename(path) for path in modified_files] if 'pip-requirements.txt' in basenames: http://git-wip-us.apache.org/repos/asf/mesos/blob/dd07b14d/support/python3/mesos-style.py ---------------------------------------------------------------------- diff --git a/support/python3/mesos-style.py b/support/python3/mesos-style.py index 09e26a8..10caf8c 100755 --- a/support/python3/mesos-style.py +++ b/support/python3/mesos-style.py @@ -450,11 +450,19 @@ def should_build_virtualenv(modified_files): have changed or if the support script is run with no arguments (meaning that the entire codebase should be linted). """ - # NOTE: If the file list is empty, we are linting the entire + # NOTE: If the file list is empty, we are linting the entire test # codebase. We should always rebuild the virtualenv in this case. if not modified_files: return True + # TODO(ArmandGrillet): Remove one os.path.dirname once python 3 + # support scripts are moved from support/python3/ to support/. + support_dir = os.path.dirname(os.path.dirname(__file__)) + interpreter = os.path.basename(sys.executable) + interpreter = os.path.join(support_dir, '.virtualenv', 'bin', interpreter) + if not os.path.isfile(interpreter): + return True + basenames = [os.path.basename(path) for path in modified_files] if 'pip-requirements.txt' in basenames: