Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
clean-venv-cache: Remove.
Anders Kaseorg7702f53d9047
diff --git a/scripts/lib/clean_unused_caches.py b/scripts/lib/clean_unused_caches.pyindex be0b2efccba..8b9a2bbea48 100755--- a/scripts/lib/clean_unused_caches.py+++ b/scripts/lib/clean_unused_caches.py@@ -6,13 +6,13 @@ import sysZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))sys.path.append(ZULIP_PATH)-from scripts.lib import clean_emoji_cache, clean_venv_cache+from scripts.lib import clean_emoji_cachefrom scripts.lib.zulip_tools import parse_cache_script_argsdef main(args: argparse.Namespace) -> None:os.chdir(ZULIP_PATH)- clean_venv_cache.main(args)+ shutil.rmtree("/srv/zulip-venv-cache", ignore_errors=True) # Replaced as of 10.0shutil.rmtree("/srv/zulip-npm-cache", ignore_errors=True) # Replaced as of 7.0clean_emoji_cache.main(args)diff --git a/scripts/lib/clean_venv_cache.py b/scripts/lib/clean_venv_cache.pydeleted file mode 100755index 672351ad2d5..00000000000--- a/scripts/lib/clean_venv_cache.py+++ /dev/null@@ -1,63 +0,0 @@-#!/usr/bin/env python3--# TODO: After switching from pip to uv, we no longer create-# /srv/zulip-venv-cache or symlink zulip-py3-venv, so this script can be-# replaced with shutil.rmtree("/srv/zulip-venv-cache").--import argparse-import glob-import os-import sys--ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))-sys.path.append(ZULIP_PATH)-from scripts.lib.hash_reqs import expand_reqs, hash_deps-from scripts.lib.zulip_tools import (- get_environment,- get_recent_deployments,- parse_cache_script_args,- purge_unused_caches,-)--ENV = get_environment()-VENV_CACHE_DIR = "/srv/zulip-venv-cache"---def get_caches_in_use(threshold_days: int) -> set[str]:- setups_to_check = {ZULIP_PATH}- caches_in_use = set()-- def add_current_venv_cache(venv_name: str) -> None:- CACHE_SYMLINK = os.path.join(os.path.dirname(ZULIP_PATH), venv_name)- CURRENT_CACHE = os.path.dirname(os.path.realpath(CACHE_SYMLINK))- caches_in_use.add(CURRENT_CACHE)-- if ENV == "prod":- setups_to_check |= get_recent_deployments(threshold_days)- if ENV == "dev":- add_current_venv_cache("zulip-py3-venv")-- for path in setups_to_check:- reqs_dir = os.path.join(path, "requirements")- # If the target directory doesn't contain a requirements- # directory, skip it to avoid throwing an exception trying to- # list its requirements subdirectory.- if not os.path.exists(reqs_dir):- continue- requirements_files = glob.glob(os.path.join(reqs_dir, "*.txt"))- for requirements_file in requirements_files:- deps = expand_reqs(requirements_file)- hash_val = hash_deps(deps)- caches_in_use.add(os.path.join(VENV_CACHE_DIR, hash_val))-- return caches_in_use---def main(args: argparse.Namespace) -> None:- caches_in_use = get_caches_in_use(args.threshold_days)- purge_unused_caches(VENV_CACHE_DIR, caches_in_use, "venv cache", args)---if __name__ == "__main__":- args = parse_cache_script_args("This script cleans unused Zulip venv caches.")- main(args)diff --git a/scripts/lib/hash_reqs.py b/scripts/lib/hash_reqs.pydeleted file mode 100755index 7e01f5e64fd..00000000000--- a/scripts/lib/hash_reqs.py+++ /dev/null@@ -1,68 +0,0 @@-#!/usr/bin/env python3-import argparse-import hashlib-import os-import subprocess-import sys-from collections.abc import Iterable---def expand_reqs_helper(fpath: str) -> list[str]:- result: list[str] = []-- with open(fpath) as f:- for line in f:- if line.strip().startswith(("#", "--hash")):- continue- dep = line.split(" \\", 1)[0].strip()- if dep:- result.append(dep)- return result---def expand_reqs(fpath: str) -> list[str]:- """- Returns a sorted list of unique dependencies specified by the requirements file `fpath`.- Removes comments from the output and recursively visits files specified inside `fpath`.- `fpath` can be either an absolute path or a relative path.- """- absfpath = os.path.abspath(fpath)- output = expand_reqs_helper(absfpath)- return sorted(set(output))---def python_version() -> str:- """- Returns the Python version as string 'Python major.minor.patchlevel'- """- return subprocess.check_output(["/usr/bin/python3", "-VV"], text=True)---def hash_deps(deps: Iterable[str]) -> str:- deps_str = "\n".join(deps) + "\n" + python_version()- return hashlib.sha1(deps_str.encode()).hexdigest()---def main() -> int:- description = (- "Finds the SHA1 hash of list of dependencies in a requirements file"- " after recursively visiting all files specified in it."- )- parser = argparse.ArgumentParser(description=description)- parser.add_argument("fpath", metavar="FILE", help="Path to requirements file")- parser.add_argument(- "--print", dest="print_reqs", action="store_true", help="Print all dependencies"- )- args = parser.parse_args()-- deps = expand_reqs(args.fpath)- hash = hash_deps(deps)- print(hash)- if args.print_reqs:- for dep in deps:- print(dep)- return 0---if __name__ == "__main__":- sys.exit(main())