Skip to content

Commit

Permalink
fix: Remove frappe cmd caching in .bench.cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Aug 2, 2022
1 parent ec9d858 commit f773529
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 50 deletions.
13 changes: 2 additions & 11 deletions bench/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# imports - standard imports
import atexit
from contextlib import contextmanager
import json
from logging import Logger
import os
import pwd
Expand All @@ -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,
Expand Down Expand Up @@ -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="."):
Expand Down
4 changes: 0 additions & 4 deletions bench/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
14 changes: 0 additions & 14 deletions bench/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 5 additions & 21 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -384,7 +383,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)
"""
Expand All @@ -393,16 +392,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"):
Expand All @@ -411,17 +406,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

Expand Down

0 comments on commit f773529

Please sign in to comment.