diff --git a/bench/cli.py b/bench/cli.py index e2e462fad..18ba730d6 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -1,7 +1,6 @@ # imports - standard imports import atexit from contextlib import contextmanager -import json from logging import Logger import os import pwd @@ -16,11 +15,10 @@ from bench.commands import bench_command from bench.config.common_site_config import get_config from bench.utils import ( - bench_cache_file, check_latest_version, drop_privileges, find_parent_bench, - generate_command_cache, + get_env_frappe_commands, get_cmd_output, is_bench_directory, is_dist_editable, @@ -201,18 +199,11 @@ def frappe_cmd(bench_path="."): os.execv(f, [f] + ["-m", "frappe.utils.bench_helper", "frappe"] + sys.argv[1:]) -def get_cached_frappe_commands(): - if os.path.exists(bench_cache_file): - command_dump = open(bench_cache_file).read() or "[]" - return set(json.loads(command_dump)) - return set() - - def get_frappe_commands(): if not is_bench_directory(): return set() - return set(generate_command_cache()) + return set(get_env_frappe_commands()) def get_frappe_help(bench_path="."): diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index d26ffecde..5ef142121 100755 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -74,11 +74,9 @@ def bench_command(bench_path="."): from bench.commands.utils import ( backup_all_sites, bench_src, - clear_command_cache, disable_production, download_translations, find_benches, - generate_command_cache, migrate_env, renew_lets_encrypt, restart, @@ -110,8 +108,6 @@ def bench_command(bench_path="."): bench_command.add_command(bench_src) bench_command.add_command(find_benches) bench_command.add_command(migrate_env) -bench_command.add_command(generate_command_cache) -bench_command.add_command(clear_command_cache) from bench.commands.setup import setup diff --git a/bench/commands/utils.py b/bench/commands/utils.py index d606788d3..9882e8f01 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -176,17 +176,3 @@ def migrate_env(python, backup=True): from bench.utils.bench import migrate_env migrate_env(python=python, backup=backup) - - -@click.command("generate-command-cache", help="Caches Frappe Framework commands") -def generate_command_cache(bench_path="."): - from bench.utils import generate_command_cache - - return generate_command_cache(bench_path=bench_path) - - -@click.command("clear-command-cache", help="Clears Frappe Framework cached commands") -def clear_command_cache(bench_path="."): - from bench.utils import clear_command_cache - - return clear_command_cache(bench_path=bench_path) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 9a14920fc..35f1bd79a 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -22,7 +22,6 @@ ) logger = logging.getLogger(PROJECT_NAME) -bench_cache_file = ".bench.cmd" paths_in_app = ("hooks.py", "modules.txt", "patches.txt") paths_in_bench = ("apps", "sites", "config", "logs", "config/pids") sudoers_file = "/etc/sudoers.d/frappe" @@ -380,7 +379,7 @@ def find_parent_bench(path: str) -> str: return find_parent_bench(parent_dir) -def generate_command_cache(bench_path=".") -> List: +def get_env_frappe_commands(bench_path=".") -> List: """Caches all available commands (even custom apps) via Frappe Default caching behaviour: generated the first time any command (for a specific bench directory) """ @@ -389,16 +388,12 @@ def generate_command_cache(bench_path=".") -> List: python = get_env_cmd("python*", bench_path=bench_path) sites_path = os.path.join(bench_path, "sites") - if os.path.exists(bench_cache_file): - os.remove(bench_cache_file) - try: - output = get_cmd_output( - f"{python} -m frappe.utils.bench_helper get-frappe-commands", cwd=sites_path + return json.loads( + get_cmd_output( + f"{python} -m frappe.utils.bench_helper get-frappe-commands", cwd=sites_path + ) ) - with open(bench_cache_file, "w") as f: - json.dump(eval(output), f) - return json.loads(output) except subprocess.CalledProcessError as e: if hasattr(e, "stderr"): @@ -407,17 +402,6 @@ def generate_command_cache(bench_path=".") -> List: return [] -def clear_command_cache(bench_path="."): - """Clears commands cached - Default invalidation behaviour: destroyed on each run of `bench update` - """ - - if os.path.exists(bench_cache_file): - os.remove(bench_cache_file) - else: - print("Bench command cache doesn't exist in this folder!") - - def find_org(org_repo): import requests