2019-07-19 08:06:34 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import glob
|
2020-06-11 00:54:34 +02:00
|
|
|
import os
|
2019-07-19 08:06:34 +02:00
|
|
|
import shutil
|
2020-06-11 00:54:34 +02:00
|
|
|
import sys
|
2020-04-20 13:18:06 +02:00
|
|
|
from typing import List
|
|
|
|
|
2019-07-19 08:06:34 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
|
|
sys.path.append(ZULIP_PATH)
|
2021-08-03 05:15:51 +02:00
|
|
|
import pygments
|
2020-09-29 22:20:46 +02:00
|
|
|
from pytz import VERSION as timezones_version
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-06-11 08:00:50 +02:00
|
|
|
from scripts.lib import clean_unused_caches
|
2020-06-11 00:54:34 +02:00
|
|
|
from scripts.lib.zulip_tools import (
|
|
|
|
ENDC,
|
|
|
|
OKBLUE,
|
|
|
|
get_dev_uuid_var_path,
|
|
|
|
is_digest_obsolete,
|
|
|
|
run,
|
|
|
|
write_new_digest,
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
from tools.setup.generate_zulip_bots_static_files import generate_zulip_bots_static_files
|
2020-06-11 00:54:34 +02:00
|
|
|
from version import PROVISION_VERSION
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-08-03 05:15:51 +02:00
|
|
|
pygments_version = pygments.__version__ # type: ignore[attr-defined] # private member missing from stubs
|
|
|
|
|
2019-07-19 08:06:34 +02:00
|
|
|
VENV_PATH = "/srv/zulip-py3-venv"
|
|
|
|
UUID_VAR_PATH = get_dev_uuid_var_path()
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-17 12:42:06 +02:00
|
|
|
def create_var_directories() -> None:
|
|
|
|
# create var/coverage, var/log, etc.
|
2021-02-12 08:20:45 +01:00
|
|
|
var_dir = os.path.join(ZULIP_PATH, "var")
|
2020-04-17 12:42:06 +02:00
|
|
|
sub_dirs = [
|
2021-02-12 08:20:45 +01:00
|
|
|
"coverage",
|
|
|
|
"log",
|
|
|
|
"node-coverage",
|
|
|
|
"test_uploads",
|
|
|
|
"uploads",
|
|
|
|
"xunit-test-results",
|
2020-04-17 12:42:06 +02:00
|
|
|
]
|
|
|
|
for sub_dir in sub_dirs:
|
|
|
|
path = os.path.join(var_dir, sub_dir)
|
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-20 13:18:06 +02:00
|
|
|
def build_pygments_data_paths() -> List[str]:
|
|
|
|
paths = [
|
|
|
|
"tools/setup/build_pygments_data",
|
|
|
|
"tools/setup/lang.json",
|
|
|
|
]
|
|
|
|
return paths
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-09-29 22:20:46 +02:00
|
|
|
def build_timezones_data_paths() -> List[str]:
|
|
|
|
paths = [
|
|
|
|
"tools/setup/build_timezone_values",
|
|
|
|
]
|
|
|
|
return paths
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-20 13:18:06 +02:00
|
|
|
def compilemessages_paths() -> List[str]:
|
2021-02-12 08:20:45 +01:00
|
|
|
paths = ["zerver/management/commands/compilemessages.py"]
|
|
|
|
paths += glob.glob("locale/*/LC_MESSAGES/*.po")
|
|
|
|
paths += glob.glob("locale/*/translations.json")
|
2020-04-20 13:18:06 +02:00
|
|
|
return paths
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-20 13:18:06 +02:00
|
|
|
def inline_email_css_paths() -> List[str]:
|
|
|
|
paths = [
|
|
|
|
"scripts/setup/inline_email_css.py",
|
|
|
|
"templates/zerver/emails/email.css",
|
|
|
|
]
|
2021-02-12 08:20:45 +01:00
|
|
|
paths += glob.glob("templates/zerver/emails/*.source.html")
|
2020-04-20 13:18:06 +02:00
|
|
|
return paths
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-29 12:03:15 +02:00
|
|
|
def configure_rabbitmq_paths() -> List[str]:
|
|
|
|
paths = [
|
|
|
|
"scripts/setup/configure-rabbitmq",
|
|
|
|
]
|
|
|
|
return paths
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def setup_shell_profile(shell_profile: str) -> None:
|
2019-07-19 08:06:34 +02:00
|
|
|
shell_profile_path = os.path.expanduser(shell_profile)
|
|
|
|
|
python: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting
assignment type annotations, which require Python 3.6), followed by
some manual whitespace adjustment, and six fixes for runtime issues:
- def __init__(self, token: Token, parent: Optional[Node]) -> None:
+ def __init__(self, token: Token, parent: "Optional[Node]") -> None:
-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":
-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":
-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:
-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:
- method_kwarg_pairs: List[FuncKwargPair],
+ method_kwarg_pairs: "List[FuncKwargPair]",
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-19 03:48:37 +02:00
|
|
|
def write_command(command: str) -> None:
|
2019-07-19 08:06:34 +02:00
|
|
|
if os.path.exists(shell_profile_path):
|
2020-04-09 21:51:58 +02:00
|
|
|
with open(shell_profile_path) as shell_profile_file:
|
2019-07-19 08:06:34 +02:00
|
|
|
lines = [line.strip() for line in shell_profile_file.readlines()]
|
|
|
|
if command not in lines:
|
2021-02-12 08:20:45 +01:00
|
|
|
with open(shell_profile_path, "a+") as shell_profile_file:
|
|
|
|
shell_profile_file.writelines(command + "\n")
|
2019-07-19 08:06:34 +02:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
with open(shell_profile_path, "w") as shell_profile_file:
|
|
|
|
shell_profile_file.writelines(command + "\n")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
|
|
|
source_activate_command = "source " + os.path.join(VENV_PATH, "bin", "activate")
|
|
|
|
write_command(source_activate_command)
|
2021-02-12 08:20:45 +01:00
|
|
|
if os.path.exists("/srv/zulip"):
|
|
|
|
write_command("cd /srv/zulip")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-09-07 01:57:44 +02:00
|
|
|
def setup_bash_profile() -> None:
|
|
|
|
"""Select a bash profile file to add setup code to."""
|
|
|
|
|
|
|
|
BASH_PROFILES = [
|
2021-02-12 08:19:30 +01:00
|
|
|
os.path.expanduser(p) for p in ("~/.bash_profile", "~/.bash_login", "~/.profile")
|
2019-09-07 01:57:44 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def clear_old_profile() -> None:
|
|
|
|
# An earlier version of this script would output a fresh .bash_profile
|
|
|
|
# even though a .profile existed in the image used. As a convenience to
|
|
|
|
# existing developers (and, perhaps, future developers git-bisecting the
|
|
|
|
# provisioning scripts), check for this situation, and blow away the
|
|
|
|
# created .bash_profile if one is found.
|
|
|
|
|
|
|
|
BASH_PROFILE = BASH_PROFILES[0]
|
|
|
|
DOT_PROFILE = BASH_PROFILES[2]
|
2021-02-12 03:52:14 +01:00
|
|
|
OLD_PROFILE_TEXT = "source /srv/zulip-py3-venv/bin/activate\ncd /srv/zulip\n"
|
2019-09-07 01:57:44 +02:00
|
|
|
|
|
|
|
if os.path.exists(DOT_PROFILE):
|
|
|
|
try:
|
2020-04-09 21:51:58 +02:00
|
|
|
with open(BASH_PROFILE) as f:
|
2019-09-07 01:57:44 +02:00
|
|
|
profile_contents = f.read()
|
|
|
|
if profile_contents == OLD_PROFILE_TEXT:
|
|
|
|
os.unlink(BASH_PROFILE)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
clear_old_profile()
|
|
|
|
|
|
|
|
for candidate_profile in BASH_PROFILES:
|
|
|
|
if os.path.exists(candidate_profile):
|
|
|
|
setup_shell_profile(candidate_profile)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
# no existing bash profile found; claim .bash_profile
|
|
|
|
setup_shell_profile(BASH_PROFILES[0])
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-16 15:00:48 +02:00
|
|
|
def need_to_run_build_pygments_data() -> bool:
|
|
|
|
if not os.path.exists("static/generated/pygments_data.json"):
|
|
|
|
return True
|
|
|
|
|
2020-04-20 15:16:16 +02:00
|
|
|
return is_digest_obsolete(
|
2020-04-16 15:00:48 +02:00
|
|
|
"build_pygments_data_hash",
|
2020-04-20 14:24:36 +02:00
|
|
|
build_pygments_data_paths(),
|
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
|
|
|
[pygments_version],
|
2020-04-16 15:00:48 +02:00
|
|
|
)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-09-29 22:20:46 +02:00
|
|
|
def need_to_run_build_timezone_data() -> bool:
|
|
|
|
if not os.path.exists("static/generated/timezones.json"):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return is_digest_obsolete(
|
|
|
|
"build_timezones_data_hash",
|
|
|
|
build_timezones_data_paths(),
|
|
|
|
[timezones_version],
|
|
|
|
)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-16 13:27:47 +02:00
|
|
|
def need_to_run_compilemessages() -> bool:
|
2021-02-12 08:20:45 +01:00
|
|
|
if not os.path.exists("locale/language_name_map.json"):
|
2022-02-28 22:15:06 +01:00
|
|
|
# User may have cleaned their Git checkout.
|
2021-02-12 08:20:45 +01:00
|
|
|
print("Need to run compilemessages due to missing language_name_map.json")
|
2020-04-16 13:29:50 +02:00
|
|
|
return True
|
|
|
|
|
2020-04-20 15:16:16 +02:00
|
|
|
return is_digest_obsolete(
|
2020-04-20 14:24:36 +02:00
|
|
|
"last_compilemessages_hash",
|
2020-04-20 13:18:06 +02:00
|
|
|
compilemessages_paths(),
|
|
|
|
)
|
2020-04-16 13:27:47 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-16 17:39:12 +02:00
|
|
|
def need_to_run_inline_email_css() -> bool:
|
2021-02-12 08:20:45 +01:00
|
|
|
if not os.path.exists("templates/zerver/emails/compiled/"):
|
2020-04-16 17:46:01 +02:00
|
|
|
return True
|
|
|
|
|
2020-04-20 15:16:16 +02:00
|
|
|
return is_digest_obsolete(
|
2020-04-20 14:24:36 +02:00
|
|
|
"last_email_source_files_hash",
|
2020-04-20 13:18:06 +02:00
|
|
|
inline_email_css_paths(),
|
|
|
|
)
|
2020-04-16 17:39:12 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-30 07:52:54 +02:00
|
|
|
def need_to_run_configure_rabbitmq(settings_list: List[str]) -> bool:
|
2020-04-29 12:03:15 +02:00
|
|
|
obsolete = is_digest_obsolete(
|
2021-02-12 08:20:45 +01:00
|
|
|
"last_configure_rabbitmq_hash",
|
2020-04-29 12:03:15 +02:00
|
|
|
configure_rabbitmq_paths(),
|
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
|
|
|
settings_list,
|
2020-04-29 12:03:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if obsolete:
|
|
|
|
return True
|
|
|
|
|
|
|
|
try:
|
|
|
|
from zerver.lib.queue import SimpleQueueClient
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-04-29 12:03:15 +02:00
|
|
|
SimpleQueueClient()
|
|
|
|
return False
|
|
|
|
except Exception:
|
|
|
|
return True
|
|
|
|
|
2020-04-30 19:12:13 +02:00
|
|
|
|
2019-07-19 08:06:34 +02:00
|
|
|
def main(options: argparse.Namespace) -> int:
|
2019-09-07 01:57:44 +02:00
|
|
|
setup_bash_profile()
|
2021-02-12 08:20:45 +01:00
|
|
|
setup_shell_profile("~/.zprofile")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
|
|
|
# This needs to happen before anything that imports zproject.settings.
|
|
|
|
run(["scripts/setup/generate_secrets.py", "--development"])
|
|
|
|
|
2020-04-17 12:42:06 +02:00
|
|
|
create_var_directories()
|
2019-07-19 08:06:34 +02:00
|
|
|
|
|
|
|
# The `build_emoji` script requires `emoji-datasource` package
|
|
|
|
# which we install via npm; thus this step is after installing npm
|
|
|
|
# packages.
|
|
|
|
run(["tools/setup/emoji/build_emoji"])
|
|
|
|
|
|
|
|
# copy over static files from the zulip_bots package
|
|
|
|
generate_zulip_bots_static_files()
|
|
|
|
|
2020-04-16 15:00:48 +02:00
|
|
|
if options.is_force or need_to_run_build_pygments_data():
|
2019-07-19 08:06:34 +02:00
|
|
|
run(["tools/setup/build_pygments_data"])
|
2020-04-20 15:16:16 +02:00
|
|
|
write_new_digest(
|
2021-02-12 08:20:45 +01:00
|
|
|
"build_pygments_data_hash",
|
2020-04-20 15:16:16 +02:00
|
|
|
build_pygments_data_paths(),
|
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
|
|
|
[pygments_version],
|
2020-04-20 15:16:16 +02:00
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
else:
|
|
|
|
print("No need to run `tools/setup/build_pygments_data`.")
|
|
|
|
|
2020-09-29 22:20:46 +02:00
|
|
|
if options.is_force or need_to_run_build_timezone_data():
|
|
|
|
run(["tools/setup/build_timezone_values"])
|
|
|
|
write_new_digest(
|
|
|
|
"build_timezones_data_hash",
|
|
|
|
build_timezones_data_paths(),
|
|
|
|
[timezones_version],
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
print("No need to run `tools/setup/build_timezone_values`.")
|
|
|
|
|
2020-04-16 17:39:12 +02:00
|
|
|
if options.is_force or need_to_run_inline_email_css():
|
2020-04-06 02:40:19 +02:00
|
|
|
run(["scripts/setup/inline_email_css.py"])
|
2020-04-20 15:16:16 +02:00
|
|
|
write_new_digest(
|
|
|
|
"last_email_source_files_hash",
|
|
|
|
inline_email_css_paths(),
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
else:
|
2020-04-06 02:40:19 +02:00
|
|
|
print("No need to run `scripts/setup/inline_email_css.py`.")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2020-06-03 21:07:33 +02:00
|
|
|
if not options.is_build_release_tarball_only:
|
|
|
|
# The following block is skipped when we just need the development
|
|
|
|
# environment to build a release tarball.
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2020-04-20 20:41:44 +02:00
|
|
|
# Need to set up Django before using template_status
|
2019-07-19 08:06:34 +02:00
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "zproject.settings")
|
|
|
|
import django
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-07-19 08:06:34 +02:00
|
|
|
django.setup()
|
|
|
|
|
2020-06-11 00:54:34 +02:00
|
|
|
from django.conf import settings
|
|
|
|
|
2020-04-20 17:21:22 +02:00
|
|
|
from zerver.lib.test_fixtures import (
|
|
|
|
DEV_DATABASE,
|
|
|
|
TEST_DATABASE,
|
|
|
|
destroy_leaked_test_databases,
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
if options.is_force or need_to_run_configure_rabbitmq([settings.RABBITMQ_PASSWORD]):
|
2019-07-19 08:06:34 +02:00
|
|
|
run(["scripts/setup/configure-rabbitmq"])
|
2020-04-29 12:03:15 +02:00
|
|
|
write_new_digest(
|
2021-02-12 08:20:45 +01:00
|
|
|
"last_configure_rabbitmq_hash",
|
2020-04-29 12:03:15 +02:00
|
|
|
configure_rabbitmq_paths(),
|
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
|
|
|
[settings.RABBITMQ_PASSWORD],
|
2020-04-29 12:03:15 +02:00
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
else:
|
2020-04-16 15:15:11 +02:00
|
|
|
print("No need to run `scripts/setup/configure-rabbitmq.")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2020-04-20 20:41:44 +02:00
|
|
|
dev_template_db_status = DEV_DATABASE.template_status()
|
2021-02-12 08:20:45 +01:00
|
|
|
if options.is_force or dev_template_db_status == "needs_rebuild":
|
2020-10-26 22:50:18 +01:00
|
|
|
run(["tools/setup/postgresql-init-dev-db"])
|
2020-05-18 17:19:15 +02:00
|
|
|
if options.skip_dev_db_build:
|
|
|
|
# We don't need to build the manual development
|
2021-03-15 18:37:12 +01:00
|
|
|
# database on continuous integration for running tests, so we can
|
2020-05-18 17:19:15 +02:00
|
|
|
# just leave it as a template db and save a minute.
|
|
|
|
#
|
|
|
|
# Important: We don't write a digest as that would
|
|
|
|
# incorrectly claim that we ran migrations.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
run(["tools/rebuild-dev-database"])
|
|
|
|
DEV_DATABASE.write_new_db_digest()
|
2021-02-12 08:20:45 +01:00
|
|
|
elif dev_template_db_status == "run_migrations":
|
2020-04-20 17:21:22 +02:00
|
|
|
DEV_DATABASE.run_db_migrations()
|
2021-02-12 08:20:45 +01:00
|
|
|
elif dev_template_db_status == "current":
|
2019-07-19 08:06:34 +02:00
|
|
|
print("No need to regenerate the dev DB.")
|
|
|
|
|
2020-04-20 20:41:44 +02:00
|
|
|
test_template_db_status = TEST_DATABASE.template_status()
|
2021-02-12 08:20:45 +01:00
|
|
|
if options.is_force or test_template_db_status == "needs_rebuild":
|
2020-10-26 22:50:18 +01:00
|
|
|
run(["tools/setup/postgresql-init-test-db"])
|
2020-04-21 22:03:12 +02:00
|
|
|
run(["tools/rebuild-test-database"])
|
2020-04-30 09:25:29 +02:00
|
|
|
TEST_DATABASE.write_new_db_digest()
|
2021-02-12 08:20:45 +01:00
|
|
|
elif test_template_db_status == "run_migrations":
|
2020-04-20 17:21:22 +02:00
|
|
|
TEST_DATABASE.run_db_migrations()
|
2021-02-12 08:20:45 +01:00
|
|
|
elif test_template_db_status == "current":
|
2019-07-19 08:06:34 +02:00
|
|
|
print("No need to regenerate the test DB.")
|
|
|
|
|
2020-04-16 13:27:47 +02:00
|
|
|
if options.is_force or need_to_run_compilemessages():
|
2019-07-19 08:06:34 +02:00
|
|
|
run(["./manage.py", "compilemessages"])
|
2020-04-20 15:16:16 +02:00
|
|
|
write_new_digest(
|
|
|
|
"last_compilemessages_hash",
|
|
|
|
compilemessages_paths(),
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
else:
|
|
|
|
print("No need to run `manage.py compilemessages`.")
|
|
|
|
|
|
|
|
destroyed = destroy_leaked_test_databases()
|
|
|
|
if destroyed:
|
2020-06-10 06:41:04 +02:00
|
|
|
print(f"Dropped {destroyed} stale test databases!")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-06-11 08:00:50 +02:00
|
|
|
clean_unused_caches.main(
|
|
|
|
argparse.Namespace(
|
|
|
|
threshold_days=6,
|
|
|
|
# The defaults here should match parse_cache_script_args in zulip_tools.py
|
|
|
|
dry_run=False,
|
|
|
|
verbose=False,
|
|
|
|
no_headings=True,
|
|
|
|
)
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
|
|
|
|
# Keeping this cache file around can cause eslint to throw
|
|
|
|
# random TypeErrors when new/updated dependencies are added
|
2021-02-12 08:20:45 +01:00
|
|
|
if os.path.isfile(".eslintcache"):
|
2019-07-19 08:06:34 +02:00
|
|
|
# Remove this block when
|
|
|
|
# https://github.com/eslint/eslint/issues/11639 is fixed
|
|
|
|
# upstream.
|
2021-02-12 08:20:45 +01:00
|
|
|
os.remove(".eslintcache")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
|
|
|
# Clean up the root of the `var/` directory for various
|
|
|
|
# testing-related files that we have migrated to
|
|
|
|
# `var/<uuid>/test-backend`.
|
|
|
|
print("Cleaning var/ directory files...")
|
2021-02-12 08:20:45 +01:00
|
|
|
var_paths = glob.glob("var/test*")
|
|
|
|
var_paths.append("var/bot_avatar")
|
2019-07-19 08:06:34 +02:00
|
|
|
for path in var_paths:
|
|
|
|
try:
|
|
|
|
if os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
else:
|
|
|
|
os.remove(path)
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
version_file = os.path.join(UUID_VAR_PATH, "provision_version")
|
|
|
|
print(f"writing to {version_file}\n")
|
|
|
|
with open(version_file, "w") as f:
|
|
|
|
f.write(PROVISION_VERSION + "\n")
|
2019-07-19 08:06:34 +02:00
|
|
|
|
|
|
|
print()
|
|
|
|
print(OKBLUE + "Zulip development environment setup succeeded!" + ENDC)
|
|
|
|
return 0
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-07-19 08:06:34 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser()
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"--force",
|
|
|
|
action="store_true",
|
|
|
|
dest="is_force",
|
2021-02-12 08:19:30 +01:00
|
|
|
help="Ignore all provisioning optimizations.",
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"--build-release-tarball-only",
|
|
|
|
action="store_true",
|
|
|
|
dest="is_build_release_tarball_only",
|
2021-02-12 08:19:30 +01:00
|
|
|
help="Provision for test suite with production settings.",
|
|
|
|
)
|
2019-07-19 08:06:34 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
parser.add_argument(
|
2021-02-12 08:20:45 +01:00
|
|
|
"--skip-dev-db-build", action="store_true", help="Don't run migrations on dev database."
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-05-18 17:19:15 +02:00
|
|
|
|
2019-07-19 08:06:34 +02:00
|
|
|
options = parser.parse_args()
|
|
|
|
sys.exit(main(options))
|