diff --git a/bench/app.py b/bench/app.py index 45a9c3d82..8584ffef6 100755 --- a/bench/app.py +++ b/bench/app.py @@ -21,10 +21,17 @@ # imports - module imports import bench from bench.exceptions import NotInBenchDirectoryError -from bench.utils import (UNSET_ARG, fetch_details_from_tag, - get_available_folder_name, get_bench_cache_path, - is_bench_directory, is_git_url, - is_valid_frappe_branch, log, run_frappe_cmd) +from bench.utils import ( + UNSET_ARG, + fetch_details_from_tag, + get_available_folder_name, + get_bench_cache_path, + is_bench_directory, + is_git_url, + is_valid_frappe_branch, + log, + run_frappe_cmd, +) from bench.utils.bench import build_assets, install_python_dev_dependencies from bench.utils.render import step @@ -225,6 +232,7 @@ def install( resolved=False, restart_bench=True, ignore_resolution=False, + using_cached=False ): import bench.cli from bench.utils.app import get_app_name @@ -245,6 +253,7 @@ def install( skip_assets=skip_assets, restart_bench=restart_bench, resolution=self.local_resolution, + using_cached=using_cached, ) @step(title="Cloning and installing {repo}", success="App {repo} Installed") @@ -332,22 +341,12 @@ def get_cached(self) -> bool: if app_path.is_dir(): shutil.rmtree(app_path) - click.secho(f"{self.app_name} being installed from cache", fg="yellow") + click.secho(f"Getting {self.app_name} from cache", fg="yellow") with tarfile.open(cache_path, mode) as tar: tar.extractall(app_path.parent) return True - def install_cached(self) -> None: - """ - TODO: - - check if cache is being set - - check if app is being set from cache - - complete install_cached - - check if app is being installed correctly from cache - """ - raise NotImplementedError("TODO: complete this function") - def set_cache(self, compress_artifacts=False) -> bool: if not self.commit_hash: return False @@ -359,6 +358,11 @@ def set_cache(self, compress_artifacts=False) -> bool: cwd = os.getcwd() cache_path = self.get_app_cache_path(compress_artifacts) mode = "w:gz" if compress_artifacts else "w" + + message = "Caching get-app artifacts" + if compress_artifacts: + message += " (compressed)" + click.secho(message) os.chdir(app_path.parent) with tarfile.open(cache_path, mode) as tar: @@ -456,7 +460,7 @@ def get_app( bench_setup = False restart_bench = not init_bench frappe_path, frappe_branch = None, None - + if resolve_deps: resolution = make_resolution_plan(app, bench) click.secho("Following apps will be installed", fg="bright_blue") @@ -508,7 +512,7 @@ def get_app( return if app.get_cached(): - app.install_cached() + app.install(verbose=verbose, skip_assets=skip_assets, restart_bench=restart_bench, using_cached=True) return dir_already_exists, cloned_path = check_existing_dir(bench_path, repo_name) @@ -645,6 +649,7 @@ def install_app( restart_bench=True, skip_assets=False, resolution=UNSET_ARG, + using_cached=False, ): import bench.cli as bench_cli from bench.bench import Bench @@ -672,14 +677,14 @@ def install_app( if conf.get("developer_mode"): install_python_dev_dependencies(apps=app, bench_path=bench_path, verbose=verbose) - if os.path.exists(os.path.join(app_path, "package.json")): + if not using_cached and os.path.exists(os.path.join(app_path, "package.json")): yarn_install = "yarn install --verbose" if verbose else "yarn install" bench.run(yarn_install, cwd=app_path) bench.apps.sync(app_name=app, required=resolution, branch=tag, app_dir=app_path) if not skip_assets: - build_assets(bench_path=bench_path, app=app) + build_assets(bench_path=bench_path, app=app, using_cached=using_cached) if restart_bench: # Avoiding exceptions here as production might not be set-up diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 44a1c457a..743318f0c 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -349,10 +349,14 @@ def restart_process_manager(bench_path=".", web_workers=False): exec_cmd(f"overmind restart {worker}", cwd=bench_path) -def build_assets(bench_path=".", app=None): +def build_assets(bench_path=".", app=None, using_cached=False): command = "bench build" if app: command += f" --app {app}" + + if using_cached: + command += " --using-cached" + exec_cmd(command, cwd=bench_path, env={"BENCH_DEVELOPER": "1"})