setup_venv: Require same Python version for virtualenv-clone.

This prevents us cloning a virtualenv in a way that would cause us to
ignore a newly updated Python version on the system.
This commit is contained in:
Tim Abbott 2020-07-10 14:02:37 -07:00 committed by Tim Abbott
parent 685ec2a098
commit 525b42cecc
1 changed files with 11 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import shutil
import subprocess
from typing import List, Optional, Set, Tuple
from scripts.lib.hash_reqs import expand_reqs
from scripts.lib.hash_reqs import expand_reqs, python_version
from scripts.lib.zulip_tools import ENDC, WARNING, os_families, run, run_as_root
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -163,6 +163,7 @@ def try_to_copy_venv(venv_path: str, new_packages: Set[str]) -> bool:
if not os.path.exists(VENV_CACHE_PATH):
return False
desired_python_version = python_version()
venv_name = os.path.basename(venv_path)
overlaps = [] # type: List[Tuple[int, str, Set[str]]]
@ -173,6 +174,15 @@ def try_to_copy_venv(venv_path: str, new_packages: Set[str]) -> bool:
not os.path.exists(get_index_filename(curr_venv_path))):
continue
# Check the Python version in the venv matches the version we want to use.
venv_python3 = os.path.join(curr_venv_path, "bin", "python3")
if not os.path.exists(venv_python3):
continue
venv_python_version = subprocess.check_output([
venv_python3, "-VV"], universal_newlines=True)
if desired_python_version != venv_python_version:
continue
old_packages = get_venv_packages(curr_venv_path)
# We only consider using using old virtualenvs that only
# contain packages that we want in our new virtualenv.