mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 09:02:10 +00:00
fix: update install_app with using_cached flag
This commit is contained in:
parent
7bcea6099d
commit
10bb5a4794
41
bench/app.py
41
bench/app.py
@ -21,10 +21,17 @@ import git
|
|||||||
# imports - module imports
|
# imports - module imports
|
||||||
import bench
|
import bench
|
||||||
from bench.exceptions import NotInBenchDirectoryError
|
from bench.exceptions import NotInBenchDirectoryError
|
||||||
from bench.utils import (UNSET_ARG, fetch_details_from_tag,
|
from bench.utils import (
|
||||||
get_available_folder_name, get_bench_cache_path,
|
UNSET_ARG,
|
||||||
is_bench_directory, is_git_url,
|
fetch_details_from_tag,
|
||||||
is_valid_frappe_branch, log, run_frappe_cmd)
|
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.bench import build_assets, install_python_dev_dependencies
|
||||||
from bench.utils.render import step
|
from bench.utils.render import step
|
||||||
|
|
||||||
@ -225,6 +232,7 @@ class App(AppMeta):
|
|||||||
resolved=False,
|
resolved=False,
|
||||||
restart_bench=True,
|
restart_bench=True,
|
||||||
ignore_resolution=False,
|
ignore_resolution=False,
|
||||||
|
using_cached=False
|
||||||
):
|
):
|
||||||
import bench.cli
|
import bench.cli
|
||||||
from bench.utils.app import get_app_name
|
from bench.utils.app import get_app_name
|
||||||
@ -245,6 +253,7 @@ class App(AppMeta):
|
|||||||
skip_assets=skip_assets,
|
skip_assets=skip_assets,
|
||||||
restart_bench=restart_bench,
|
restart_bench=restart_bench,
|
||||||
resolution=self.local_resolution,
|
resolution=self.local_resolution,
|
||||||
|
using_cached=using_cached,
|
||||||
)
|
)
|
||||||
|
|
||||||
@step(title="Cloning and installing {repo}", success="App {repo} Installed")
|
@step(title="Cloning and installing {repo}", success="App {repo} Installed")
|
||||||
@ -332,22 +341,12 @@ class App(AppMeta):
|
|||||||
if app_path.is_dir():
|
if app_path.is_dir():
|
||||||
shutil.rmtree(app_path)
|
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:
|
with tarfile.open(cache_path, mode) as tar:
|
||||||
tar.extractall(app_path.parent)
|
tar.extractall(app_path.parent)
|
||||||
|
|
||||||
return True
|
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:
|
def set_cache(self, compress_artifacts=False) -> bool:
|
||||||
if not self.commit_hash:
|
if not self.commit_hash:
|
||||||
return False
|
return False
|
||||||
@ -360,6 +359,11 @@ class App(AppMeta):
|
|||||||
cache_path = self.get_app_cache_path(compress_artifacts)
|
cache_path = self.get_app_cache_path(compress_artifacts)
|
||||||
mode = "w:gz" if compress_artifacts else "w"
|
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)
|
os.chdir(app_path.parent)
|
||||||
with tarfile.open(cache_path, mode) as tar:
|
with tarfile.open(cache_path, mode) as tar:
|
||||||
tar.add(app_path.name)
|
tar.add(app_path.name)
|
||||||
@ -508,7 +512,7 @@ def get_app(
|
|||||||
return
|
return
|
||||||
|
|
||||||
if app.get_cached():
|
if app.get_cached():
|
||||||
app.install_cached()
|
app.install(verbose=verbose, skip_assets=skip_assets, restart_bench=restart_bench, using_cached=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
dir_already_exists, cloned_path = check_existing_dir(bench_path, repo_name)
|
dir_already_exists, cloned_path = check_existing_dir(bench_path, repo_name)
|
||||||
@ -645,6 +649,7 @@ def install_app(
|
|||||||
restart_bench=True,
|
restart_bench=True,
|
||||||
skip_assets=False,
|
skip_assets=False,
|
||||||
resolution=UNSET_ARG,
|
resolution=UNSET_ARG,
|
||||||
|
using_cached=False,
|
||||||
):
|
):
|
||||||
import bench.cli as bench_cli
|
import bench.cli as bench_cli
|
||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
@ -672,14 +677,14 @@ def install_app(
|
|||||||
if conf.get("developer_mode"):
|
if conf.get("developer_mode"):
|
||||||
install_python_dev_dependencies(apps=app, bench_path=bench_path, verbose=verbose)
|
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"
|
yarn_install = "yarn install --verbose" if verbose else "yarn install"
|
||||||
bench.run(yarn_install, cwd=app_path)
|
bench.run(yarn_install, cwd=app_path)
|
||||||
|
|
||||||
bench.apps.sync(app_name=app, required=resolution, branch=tag, app_dir=app_path)
|
bench.apps.sync(app_name=app, required=resolution, branch=tag, app_dir=app_path)
|
||||||
|
|
||||||
if not skip_assets:
|
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:
|
if restart_bench:
|
||||||
# Avoiding exceptions here as production might not be set-up
|
# Avoiding exceptions here as production might not be set-up
|
||||||
|
@ -349,10 +349,14 @@ def restart_process_manager(bench_path=".", web_workers=False):
|
|||||||
exec_cmd(f"overmind restart {worker}", cwd=bench_path)
|
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"
|
command = "bench build"
|
||||||
if app:
|
if app:
|
||||||
command += f" --app {app}"
|
command += f" --app {app}"
|
||||||
|
|
||||||
|
if using_cached:
|
||||||
|
command += " --using-cached"
|
||||||
|
|
||||||
exec_cmd(command, cwd=bench_path, env={"BENCH_DEVELOPER": "1"})
|
exec_cmd(command, cwd=bench_path, env={"BENCH_DEVELOPER": "1"})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user