2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-06 23:44:03 +00:00

Merge pull request #1349 from gavindsouza/frappe-cmd-cache-bye

fix: Remove frappe cmd caching in .bench.cmd
This commit is contained in:
gavin 2022-08-02 14:38:37 +05:30 committed by GitHub
commit 18a954b88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 50 deletions

View File

@ -1,7 +1,6 @@
# imports - standard imports # imports - standard imports
import atexit import atexit
from contextlib import contextmanager from contextlib import contextmanager
import json
from logging import Logger from logging import Logger
import os import os
import pwd import pwd
@ -16,11 +15,10 @@ from bench.bench import Bench
from bench.commands import bench_command from bench.commands import bench_command
from bench.config.common_site_config import get_config from bench.config.common_site_config import get_config
from bench.utils import ( from bench.utils import (
bench_cache_file,
check_latest_version, check_latest_version,
drop_privileges, drop_privileges,
find_parent_bench, find_parent_bench,
generate_command_cache, get_env_frappe_commands,
get_cmd_output, get_cmd_output,
is_bench_directory, is_bench_directory,
is_dist_editable, 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:]) 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(): def get_frappe_commands():
if not is_bench_directory(): if not is_bench_directory():
return set() return set()
return set(generate_command_cache()) return set(get_env_frappe_commands())
def get_frappe_help(bench_path="."): def get_frappe_help(bench_path="."):

View File

@ -74,11 +74,9 @@ bench_command.add_command(switch_to_develop)
from bench.commands.utils import ( from bench.commands.utils import (
backup_all_sites, backup_all_sites,
bench_src, bench_src,
clear_command_cache,
disable_production, disable_production,
download_translations, download_translations,
find_benches, find_benches,
generate_command_cache,
migrate_env, migrate_env,
renew_lets_encrypt, renew_lets_encrypt,
restart, restart,
@ -110,8 +108,6 @@ bench_command.add_command(disable_production)
bench_command.add_command(bench_src) bench_command.add_command(bench_src)
bench_command.add_command(find_benches) bench_command.add_command(find_benches)
bench_command.add_command(migrate_env) 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 from bench.commands.setup import setup

View File

@ -176,17 +176,3 @@ def migrate_env(python, backup=True):
from bench.utils.bench import migrate_env from bench.utils.bench import migrate_env
migrate_env(python=python, backup=backup) 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)

View File

@ -22,7 +22,6 @@ from bench.exceptions import (
) )
logger = logging.getLogger(PROJECT_NAME) logger = logging.getLogger(PROJECT_NAME)
bench_cache_file = ".bench.cmd"
paths_in_app = ("hooks.py", "modules.txt", "patches.txt") paths_in_app = ("hooks.py", "modules.txt", "patches.txt")
paths_in_bench = ("apps", "sites", "config", "logs", "config/pids") paths_in_bench = ("apps", "sites", "config", "logs", "config/pids")
sudoers_file = "/etc/sudoers.d/frappe" sudoers_file = "/etc/sudoers.d/frappe"
@ -380,7 +379,7 @@ def find_parent_bench(path: str) -> str:
return find_parent_bench(parent_dir) 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 """Caches all available commands (even custom apps) via Frappe
Default caching behaviour: generated the first time any command (for a specific bench directory) 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) python = get_env_cmd("python*", bench_path=bench_path)
sites_path = os.path.join(bench_path, "sites") sites_path = os.path.join(bench_path, "sites")
if os.path.exists(bench_cache_file):
os.remove(bench_cache_file)
try: try:
output = get_cmd_output( return json.loads(
f"{python} -m frappe.utils.bench_helper get-frappe-commands", cwd=sites_path 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: except subprocess.CalledProcessError as e:
if hasattr(e, "stderr"): if hasattr(e, "stderr"):
@ -407,17 +402,6 @@ def generate_command_cache(bench_path=".") -> List:
return [] 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): def find_org(org_repo):
import requests import requests