mirror of
https://github.com/frappe/bench.git
synced 2025-01-04 22:55:25 +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:
commit
18a954b88c
13
bench/cli.py
13
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.bench import Bench
|
||||
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="."):
|
||||
|
@ -74,11 +74,9 @@ bench_command.add_command(switch_to_develop)
|
||||
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 @@ bench_command.add_command(disable_production)
|
||||
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
|
||||
|
||||
|
@ -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)
|
||||
|
@ -22,7 +22,6 @@ from bench.exceptions import (
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user