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
|
2020-06-11 00:54:34 +02:00
|
|
|
import fileinput
|
2017-03-30 20:02:21 +02:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import re
|
2020-06-11 00:54:34 +02:00
|
|
|
import sys
|
2017-03-30 20:02:21 +02:00
|
|
|
from typing import List
|
|
|
|
|
2020-06-11 00:54:34 +02: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 validate_order(order: List[int], length: int) -> None:
|
2017-03-30 20:02:21 +02:00
|
|
|
if len(order) != length:
|
|
|
|
print("Please enter the sequence of all the conflicting files at once")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
for i in order:
|
|
|
|
if i > length or i < 1 or order.count(i) > 1:
|
|
|
|
print("Incorrect input")
|
|
|
|
sys.exit(1)
|
|
|
|
|
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 renumber_migration(conflicts: List[str], order: List[int], last_correct_migration: str) -> None:
|
2020-04-22 01:09:50 +02:00
|
|
|
stack: List[str] = []
|
2017-03-30 20:02:21 +02:00
|
|
|
for i in order:
|
2021-02-12 08:19:30 +01:00
|
|
|
if conflicts[i - 1][0:4] not in stack:
|
|
|
|
stack.append(conflicts[i - 1][0:4])
|
2017-03-30 20:02:21 +02:00
|
|
|
else:
|
|
|
|
# Replace dependencies with the last correct migration
|
2021-02-12 08:20:45 +01:00
|
|
|
file = fileinput.FileInput("zerver/migrations/" + conflicts[i - 1], inplace=True)
|
2017-03-30 20:02:21 +02:00
|
|
|
for line in file:
|
2021-02-12 08:20:45 +01:00
|
|
|
print(re.sub(r"[\d]+(_[a-z0-9]+)+", last_correct_migration, line), end="")
|
2017-03-30 20:02:21 +02:00
|
|
|
|
|
|
|
# Rename the migration indexing at the end
|
2021-02-12 08:19:30 +01:00
|
|
|
new_name = conflicts[i - 1].replace(
|
2021-02-12 08:20:45 +01:00
|
|
|
conflicts[i - 1][0:4], f"{int(last_correct_migration[0:4]) + 1:04}"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2021-02-12 08:20:45 +01:00
|
|
|
os.rename("zerver/migrations/" + conflicts[i - 1], "zerver/migrations/" + new_name)
|
2017-03-30 20:02:21 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
last_correct_migration = new_name.replace(".py", "")
|
2017-03-30 20:02:21 +02:00
|
|
|
|
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 resolve_conflicts(conflicts: List[str], files_list: List[str]) -> None:
|
2017-03-30 20:02:21 +02:00
|
|
|
print("Conflicting migrations:")
|
|
|
|
for i in range(0, len(conflicts)):
|
2021-02-12 08:20:45 +01:00
|
|
|
print(str(i + 1) + ". " + conflicts[i])
|
2017-03-30 20:02:21 +02:00
|
|
|
|
|
|
|
order_input = input("Enter the order in which these migrations should be arranged: ")
|
|
|
|
order = list(map(int, order_input.split()))
|
|
|
|
validate_order(order, len(conflicts))
|
|
|
|
|
2017-09-22 16:51:05 +02:00
|
|
|
last_correct_migration = conflicts[order[0] - 1]
|
2017-03-30 20:02:21 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
last_correct_migration = last_correct_migration.replace(".py", "")
|
2017-03-30 20:02:21 +02:00
|
|
|
renumber_migration(conflicts, order, last_correct_migration)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
if __name__ == "__main__":
|
2017-03-30 20:02:21 +02:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
MIGRATIONS_TO_SKIP = {"0209", "0261"}
|
2017-03-30 20:02:21 +02:00
|
|
|
while True:
|
2020-04-22 01:09:50 +02:00
|
|
|
conflicts: List[str] = []
|
|
|
|
stack: List[str] = []
|
2017-03-30 20:02:21 +02:00
|
|
|
files_list = [os.path.basename(path) for path in glob.glob("zerver/migrations/????_*.py")]
|
|
|
|
file_index = [file[0:4] for file in files_list]
|
|
|
|
|
|
|
|
for file in file_index:
|
2018-07-10 16:52:16 +02:00
|
|
|
migration_number = file[0:4]
|
|
|
|
counter = file_index.count(migration_number)
|
2019-12-12 01:07:36 +01:00
|
|
|
|
2020-06-18 23:00:43 +02:00
|
|
|
if counter > 1 and file[0:4] not in stack:
|
|
|
|
# When we need to backport migrations to a previous
|
|
|
|
# release, we sometimes end up with multiple having
|
|
|
|
# the same ID number (which isn't a problem; the
|
|
|
|
# migrations graph structure, not the IDs, is what
|
|
|
|
# matters).
|
|
|
|
if migration_number not in MIGRATIONS_TO_SKIP:
|
2021-02-12 08:19:30 +01:00
|
|
|
conflicts += [
|
|
|
|
file_name
|
|
|
|
for file_name in files_list
|
|
|
|
if file_name.startswith(migration_number)
|
|
|
|
]
|
2020-06-18 23:00:43 +02:00
|
|
|
stack.append(migration_number)
|
2017-03-30 20:02:21 +02:00
|
|
|
|
|
|
|
if len(conflicts) > 0:
|
|
|
|
resolve_conflicts(conflicts, files_list)
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
print("All conflicts resolved")
|