mirror of https://github.com/zulip/zulip.git
provision: Avoid distutils; keep PROVISION_VERSION as a tuple.
distutils is deprecated in Python 3.10 and will be removed in Python 3.12. We don’t need a full-powered version parser for this anyway. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
22ebf701aa
commit
412e90f601
|
@ -43,7 +43,7 @@ In `version.py`, we have a special parameter, `PROVISION_VERSION`,
|
||||||
which is used to help ensure developers don't spend time debugging
|
which is used to help ensure developers don't spend time debugging
|
||||||
test/linter/etc. failures that actually were caused by the developer
|
test/linter/etc. failures that actually were caused by the developer
|
||||||
rebasing and forgetting to provision". `PROVISION_VERSION` has a
|
rebasing and forgetting to provision". `PROVISION_VERSION` has a
|
||||||
format of `x.y`; when `x` doesn't match the value from the last time
|
format of `(x, y)`; when `x` doesn't match the value from the last time
|
||||||
the user provisioned, or `y` is higher than the value from last
|
the user provisioned, or `y` is higher than the value from last
|
||||||
time, most Zulip tools will crash early and ask the user to provision.
|
time, most Zulip tools will crash early and ask the user to provision.
|
||||||
This has empirically made a huge impact on how often developers spend
|
This has empirically made a huge impact on how often developers spend
|
||||||
|
|
|
@ -76,12 +76,12 @@ def check_django() -> bool:
|
||||||
def provision_version() -> bool:
|
def provision_version() -> bool:
|
||||||
fn = os.path.join(UUID_VAR_PATH, "provision_version")
|
fn = os.path.join(UUID_VAR_PATH, "provision_version")
|
||||||
with open(fn) as f:
|
with open(fn) as f:
|
||||||
version = f.read().strip()
|
version = tuple(map(int, f.read().strip().split(".")))
|
||||||
print("latest version provisioned:", version)
|
print("latest version provisioned:", version)
|
||||||
from version import PROVISION_VERSION
|
from version import PROVISION_VERSION
|
||||||
|
|
||||||
print("desired version:", PROVISION_VERSION)
|
print("desired version:", PROVISION_VERSION)
|
||||||
if version != PROVISION_VERSION:
|
if not (PROVISION_VERSION <= version < (PROVISION_VERSION[0] + 1,)):
|
||||||
print("You need to provision!")
|
print("You need to provision!")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -362,7 +362,7 @@ def main(options: argparse.Namespace) -> int:
|
||||||
version_file = os.path.join(UUID_VAR_PATH, "provision_version")
|
version_file = os.path.join(UUID_VAR_PATH, "provision_version")
|
||||||
print(f"writing to {version_file}\n")
|
print(f"writing to {version_file}\n")
|
||||||
with open(version_file, "w") as f:
|
with open(version_file, "w") as f:
|
||||||
f.write(PROVISION_VERSION + "\n")
|
f.write(".".join(map(str, PROVISION_VERSION)) + "\n")
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print(OKBLUE + "Zulip development environment setup succeeded!" + ENDC)
|
print(OKBLUE + "Zulip development environment setup succeeded!" + ENDC)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from distutils.version import LooseVersion
|
|
||||||
from typing import Iterable, List, Optional, Tuple
|
from typing import Iterable, List, Optional, Tuple
|
||||||
|
|
||||||
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
||||||
|
@ -12,10 +11,6 @@ from version import PROVISION_VERSION
|
||||||
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
|
||||||
def get_major_version(v: str) -> int:
|
|
||||||
return int(v.split(".")[0])
|
|
||||||
|
|
||||||
|
|
||||||
def get_version_file() -> str:
|
def get_version_file() -> str:
|
||||||
uuid_var_path = get_dev_uuid_var_path()
|
uuid_var_path = get_dev_uuid_var_path()
|
||||||
return os.path.join(uuid_var_path, "provision_version")
|
return os.path.join(uuid_var_path, "provision_version")
|
||||||
|
@ -30,7 +25,7 @@ properly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def preamble(version: str) -> str:
|
def preamble(version: Tuple[int, ...]) -> str:
|
||||||
text = PREAMBLE.format(version, PROVISION_VERSION)
|
text = PREAMBLE.format(version, PROVISION_VERSION)
|
||||||
text += "\n"
|
text += "\n"
|
||||||
return text
|
return text
|
||||||
|
@ -64,22 +59,17 @@ def get_provisioning_status() -> Tuple[bool, Optional[str]]:
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
with open(version_file) as f:
|
with open(version_file) as f:
|
||||||
version = f.read().strip()
|
version = tuple(map(int, f.read().strip().split(".")))
|
||||||
|
|
||||||
# Normal path for people that provision--we're all good!
|
|
||||||
if version == PROVISION_VERSION:
|
|
||||||
return True, None
|
|
||||||
|
|
||||||
# We may be more provisioned than the branch we just moved to. As
|
# We may be more provisioned than the branch we just moved to. As
|
||||||
# long as the major version hasn't changed, then we should be ok.
|
# long as the major version hasn't changed, then we should be ok.
|
||||||
if LooseVersion(version) > LooseVersion(PROVISION_VERSION):
|
if version < PROVISION_VERSION:
|
||||||
if get_major_version(version) == get_major_version(PROVISION_VERSION):
|
return False, preamble(version) + NEED_TO_UPGRADE
|
||||||
|
elif version < (PROVISION_VERSION[0] + 1,):
|
||||||
return True, None
|
return True, None
|
||||||
else:
|
else:
|
||||||
return False, preamble(version) + NEED_TO_DOWNGRADE
|
return False, preamble(version) + NEED_TO_DOWNGRADE
|
||||||
|
|
||||||
return False, preamble(version) + NEED_TO_UPGRADE
|
|
||||||
|
|
||||||
|
|
||||||
def assert_provisioning_status_ok(skip_provision_check: bool) -> None:
|
def assert_provisioning_status_ok(skip_provision_check: bool) -> None:
|
||||||
if not skip_provision_check:
|
if not skip_provision_check:
|
||||||
|
|
|
@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 133
|
||||||
# historical commits sharing the same major version, in which case a
|
# historical commits sharing the same major version, in which case a
|
||||||
# minor version bump suffices.
|
# minor version bump suffices.
|
||||||
|
|
||||||
PROVISION_VERSION = "195.0"
|
PROVISION_VERSION = (195, 0)
|
||||||
|
|
Loading…
Reference in New Issue