py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-06-22 21:00:50 +02:00
|
|
|
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
2017-09-22 08:15:01 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
2016-06-22 21:00:50 +02:00
|
|
|
if ZULIP_PATH not in sys.path:
|
|
|
|
sys.path.append(ZULIP_PATH)
|
|
|
|
|
2019-08-30 00:14:43 +02:00
|
|
|
from scripts.lib.zulip_tools import os_families, overwrite_symlink, run, parse_os_release
|
2019-01-05 01:25:33 +01:00
|
|
|
from scripts.lib.setup_venv import (
|
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
|
|
|
setup_virtualenv, get_venv_dependencies,
|
2019-01-05 01:25:33 +01:00
|
|
|
)
|
2016-06-22 21:00:50 +02:00
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Create a production virtualenv with caching")
|
2016-11-20 05:45:53 +01:00
|
|
|
parser.add_argument("deploy_path")
|
2016-06-22 21:00:50 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# install dependencies for setting up the virtualenv
|
2019-08-25 01:23:14 +02:00
|
|
|
distro_info = parse_os_release()
|
2020-03-17 20:27:35 +01:00
|
|
|
vendor = distro_info['ID']
|
|
|
|
os_version = distro_info['VERSION_ID']
|
|
|
|
VENV_DEPENDENCIES = get_venv_dependencies(vendor, os_version)
|
2019-08-30 00:14:43 +02:00
|
|
|
if "debian" in os_families():
|
2019-01-05 01:25:33 +01:00
|
|
|
run(["apt-get", "-y", "install"] + VENV_DEPENDENCIES)
|
2019-08-30 00:14:43 +02:00
|
|
|
elif "fedora" in os_families():
|
2020-03-22 21:06:37 +01:00
|
|
|
run(["yum", "-y", "install"] + VENV_DEPENDENCIES)
|
2019-01-05 01:25:33 +01:00
|
|
|
else:
|
2019-08-30 00:14:43 +02:00
|
|
|
print("Unsupported platform: {}".format(distro_info['ID']))
|
2019-01-05 01:25:33 +01:00
|
|
|
sys.exit(1)
|
2016-06-22 21:00:50 +02:00
|
|
|
|
2017-03-26 04:00:56 +02:00
|
|
|
# Set the current working directory to the Zulip checkout, so the api/
|
2017-11-17 02:41:06 +01:00
|
|
|
# relative path in requirements/common.in works.
|
2017-03-26 04:00:56 +02:00
|
|
|
os.chdir(ZULIP_PATH)
|
|
|
|
|
2019-01-10 01:30:44 +01:00
|
|
|
venv_name = "zulip-py3-venv"
|
2016-10-11 06:30:28 +02:00
|
|
|
cached_venv_path = setup_virtualenv(
|
2016-12-08 10:55:36 +01:00
|
|
|
os.path.join(args.deploy_path, venv_name),
|
2020-02-05 06:54:43 +01:00
|
|
|
os.path.join(ZULIP_PATH, "requirements", "prod.txt"))
|
2016-12-08 10:55:36 +01:00
|
|
|
|
|
|
|
current_venv_path = os.path.join(args.deploy_path, 'zulip-current-venv')
|
2018-07-18 23:50:15 +02:00
|
|
|
overwrite_symlink(venv_name, current_venv_path)
|