21
21
# imports - module imports
22
22
import bench
23
23
from bench .exceptions import NotInBenchDirectoryError
24
- from bench .utils import (UNSET_ARG ,fetch_details_from_tag ,
25
- get_available_folder_name ,get_bench_cache_path ,
26
- is_bench_directory ,is_git_url ,
27
- is_valid_frappe_branch ,log ,run_frappe_cmd )
24
+ from bench .utils import (
25
+ UNSET_ARG ,
26
+ fetch_details_from_tag ,
27
+ get_available_folder_name ,
28
+ get_bench_cache_path ,
29
+ is_bench_directory ,
30
+ is_git_url ,
31
+ is_valid_frappe_branch ,
32
+ log ,
33
+ run_frappe_cmd ,
34
+ )
28
35
from bench .utils .bench import build_assets ,install_python_dev_dependencies
29
36
from bench .utils .render import step
30
37
@@ -225,6 +232,7 @@ def install(
225
232
resolved = False ,
226
233
restart_bench = True ,
227
234
ignore_resolution = False ,
235
+ using_cached = False
228
236
):
229
237
import bench .cli
230
238
from bench .utils .app import get_app_name
@@ -245,6 +253,7 @@ def install(
245
253
skip_assets = skip_assets ,
246
254
restart_bench = restart_bench ,
247
255
resolution = self .local_resolution ,
256
+ using_cached = using_cached ,
248
257
)
249
258
250
259
@step (title = "Cloning and installing {repo}" ,success = "App {repo} Installed" )
@@ -332,22 +341,12 @@ def get_cached(self) -> bool:
332
341
if app_path .is_dir ():
333
342
shutil .rmtree (app_path )
334
343
335
- click .secho (f"{ self .app_name } being installed from cache" ,fg = "yellow" )
344
+ click .secho (f"Getting { self .app_name } from cache" ,fg = "yellow" )
336
345
with tarfile .open (cache_path ,mode )as tar :
337
346
tar .extractall (app_path .parent )
338
347
339
348
return True
340
349
341
- def install_cached (self )-> None :
342
- """
343
- TODO:
344
- - check if cache is being set
345
- - check if app is being set from cache
346
- - complete install_cached
347
- - check if app is being installed correctly from cache
348
- """
349
- raise NotImplementedError ("TODO: complete this function" )
350
-
351
350
def set_cache (self ,compress_artifacts = False )-> bool :
352
351
if not self .commit_hash :
353
352
return False
@@ -359,6 +358,11 @@ def set_cache(self, compress_artifacts=False) -> bool:
359
358
cwd = os .getcwd ()
360
359
cache_path = self .get_app_cache_path (compress_artifacts )
361
360
mode = "w:gz" if compress_artifacts else "w"
361
+
362
+ message = "Caching get-app artifacts"
363
+ if compress_artifacts :
364
+ message += " (compressed)"
365
+ click .secho (message )
362
366
363
367
os .chdir (app_path .parent )
364
368
with tarfile .open (cache_path ,mode )as tar :
@@ -456,7 +460,7 @@ def get_app(
456
460
bench_setup = False
457
461
restart_bench = not init_bench
458
462
frappe_path ,frappe_branch = None ,None
459
-
463
+
460
464
if resolve_deps :
461
465
resolution = make_resolution_plan (app ,bench )
462
466
click .secho ("Following apps will be installed" ,fg = "bright_blue" )
@@ -508,7 +512,7 @@ def get_app(
508
512
return
509
513
510
514
if app .get_cached ():
511
- app .install_cached ( )
515
+ app .install ( verbose = verbose , skip_assets = skip_assets , restart_bench = restart_bench , using_cached = True )
512
516
return
513
517
514
518
dir_already_exists ,cloned_path = check_existing_dir (bench_path ,repo_name )
@@ -645,6 +649,7 @@ def install_app(
645
649
restart_bench = True ,
646
650
skip_assets = False ,
647
651
resolution = UNSET_ARG ,
652
+ using_cached = False ,
648
653
):
649
654
import bench .cli as bench_cli
650
655
from bench .bench import Bench
@@ -672,14 +677,14 @@ def install_app(
672
677
if conf .get ("developer_mode" ):
673
678
install_python_dev_dependencies (apps = app ,bench_path = bench_path ,verbose = verbose )
674
679
675
- if os .path .exists (os .path .join (app_path ,"package.json" )):
680
+ if not using_cached and os .path .exists (os .path .join (app_path ,"package.json" )):
676
681
yarn_install = "yarn install --verbose" if verbose else "yarn install"
677
682
bench .run (yarn_install ,cwd = app_path )
678
683
679
684
bench .apps .sync (app_name = app ,required = resolution ,branch = tag ,app_dir = app_path )
680
685
681
686
if not skip_assets :
682
- build_assets (bench_path = bench_path ,app = app )
687
+ build_assets (bench_path = bench_path ,app = app , using_cached = using_cached )
683
688
684
689
if restart_bench :
685
690
# Avoiding exceptions here as production might not be set-up