Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

setup_venv: Require same Python version for virtualenv-clone.

Tim Abbott525b42cecc66
diff --git a/scripts/lib/setup_venv.py b/scripts/lib/setup_venv.py
index 2f18991af2a..91cffe16cf9 100644
--- a/scripts/lib/setup_venv.py
+++ b/scripts/lib/setup_venv.py
@@ -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.