setup_venv: Replace virtualenv_args list with python2 bool.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-02-04 21:54:43 -08:00
committed by Tim Abbott
parent 8e5a45267d
commit d2e07ea51b
4 changed files with 10 additions and 14 deletions

View File

@@ -32,8 +32,6 @@ else:
print("Unsupported platform: {}".format(distro_info['ID']))
sys.exit(1)
python_version = sys.version_info[0]
# Set the current working directory to the Zulip checkout, so the api/
# relative path in requirements/common.in works.
os.chdir(ZULIP_PATH)
@@ -41,8 +39,7 @@ os.chdir(ZULIP_PATH)
venv_name = "zulip-py3-venv"
cached_venv_path = setup_virtualenv(
os.path.join(args.deploy_path, venv_name),
os.path.join(ZULIP_PATH, "requirements", "prod.txt"),
virtualenv_args=['-p', 'python{}'.format(python_version)])
os.path.join(ZULIP_PATH, "requirements", "prod.txt"))
current_venv_path = os.path.join(args.deploy_path, 'zulip-current-venv')
overwrite_symlink(venv_name, current_venv_path)

View File

@@ -31,4 +31,4 @@ venv_name = "zulip-thumbor-venv"
cached_venv_path = setup_virtualenv(
os.path.join(args.deploy_path, venv_name),
os.path.join(ZULIP_PATH, "requirements", "thumbor.txt"),
virtualenv_args=['-p', 'python2.7'])
python2=True)

View File

@@ -274,8 +274,8 @@ def do_patch_activate_script(venv_path):
with open(script_path, 'w') as f:
f.write("".join(lines))
def setup_virtualenv(target_venv_path, requirements_file, virtualenv_args=None, patch_activate_script=False):
# type: (Optional[str], str, Optional[List[str]], bool) -> str
def setup_virtualenv(target_venv_path, requirements_file, python2=False, patch_activate_script=False):
# type: (Optional[str], str, bool, bool) -> str
# Check if a cached version already exists
path = os.path.join(ZULIP_PATH, 'scripts', 'lib', 'hash_reqs.py')
@@ -287,7 +287,7 @@ def setup_virtualenv(target_venv_path, requirements_file, virtualenv_args=None,
cached_venv_path = os.path.join(VENV_CACHE_PATH, sha1sum, os.path.basename(target_venv_path))
success_stamp = os.path.join(cached_venv_path, "success-stamp")
if not os.path.exists(success_stamp):
do_setup_virtualenv(cached_venv_path, requirements_file, virtualenv_args or [])
do_setup_virtualenv(cached_venv_path, requirements_file, python2)
with open(success_stamp, 'w') as f:
f.close()
@@ -305,8 +305,8 @@ def add_cert_to_pipconf():
os.makedirs(confdir, exist_ok=True)
run(["crudini", "--set", conffile, "global", "cert", os.environ["CUSTOM_CA_CERTIFICATES"]])
def do_setup_virtualenv(venv_path, requirements_file, virtualenv_args):
# type: (str, str, List[str]) -> None
def do_setup_virtualenv(venv_path, requirements_file, python2):
# type: (str, str, bool) -> None
# Setup Python virtualenv
new_packages = set(get_package_names(requirements_file))
@@ -315,7 +315,7 @@ def do_setup_virtualenv(venv_path, requirements_file, virtualenv_args):
if not try_to_copy_venv(venv_path, new_packages):
# Create new virtualenv.
run_as_root(["mkdir", "-p", venv_path])
run_as_root(["virtualenv"] + virtualenv_args + [venv_path])
run_as_root(["virtualenv", "-p", "python2.7" if python2 else "python3", venv_path])
run_as_root(["chown", "-R",
"{}:{}".format(os.getuid(), os.getgid()), venv_path])
create_log_entry(get_logfile_name(venv_path), "", set(), new_packages)

View File

@@ -17,10 +17,9 @@ THUMBOR_REQS_FILE = os.path.join(ZULIP_PATH, "requirements", "thumbor-dev.txt")
def main() -> None:
setup_virtualenv("/srv/zulip-thumbor-venv", THUMBOR_REQS_FILE,
patch_activate_script=True, virtualenv_args=['-p', 'python2.7'])
patch_activate_script=True, python2=True)
cached_venv_path = setup_virtualenv(
VENV_PATH, DEV_REQS_FILE, patch_activate_script=True,
virtualenv_args=['-p', 'python3'])
VENV_PATH, DEV_REQS_FILE, patch_activate_script=True)
overwrite_symlink(cached_venv_path, os.path.join(ZULIP_PATH, "zulip-py3-venv"))
if __name__ == "__main__":