@@ -59,6 +59,7 @@ def is_frappe_app(directory: str) -> bool:
5959
6060 return bool (is_frappe_app )
6161
62+
6263def get_bench_cache_path (sub_dir : Optional [str ]) -> Path :
6364 relative_path = "~/.cache/bench"
6465 if sub_dir and not sub_dir .startswith ("/" ):
@@ -69,6 +70,7 @@ def get_bench_cache_path(sub_dir: Optional[str]) -> Path:
6970 cache_path .mkdir (parents = True , exist_ok = True )
7071 return cache_path
7172
73+
7274@lru_cache (maxsize = None )
7375def is_valid_frappe_branch (frappe_path : str , frappe_branch : str ):
7476 """Check if a branch exists in a repo. Throws InvalidRemoteException if branch is not found
@@ -424,7 +426,7 @@ def get_env_frappe_commands(bench_path=".") -> List:
424426 return []
425427
426428
427- def find_org (org_repo , using_cached : bool = False ):
429+ def find_org (org_repo , using_cached : bool = False ):
428430 import requests
429431
430432 org_repo = org_repo [0 ]
@@ -439,10 +441,14 @@ def find_org(org_repo, using_cached: bool=False):
439441 if using_cached :
440442 return "" , org_repo
441443
442- raise InvalidRemoteException (f"{ org_repo } not found under frappe or erpnext GitHub accounts" )
444+ raise InvalidRemoteException (
445+ f"{ org_repo } not found under frappe or erpnext GitHub accounts"
446+ )
443447
444448
445- def fetch_details_from_tag (_tag : str , using_cached : bool = False ) -> Tuple [str , str , str ]:
449+ def fetch_details_from_tag (
450+ _tag : str , using_cached : bool = False
451+ ) -> Tuple [str , str , str ]:
446452 if not _tag :
447453 raise Exception ("Tag is not provided" )
448454
@@ -585,14 +591,17 @@ def get_cmd_from_sysargv():
585591def get_app_cache_extract_filter (
586592 count_threshold : int = 10_000 ,
587593 size_threshold : int = 1_000_000_000 ,
588- ): # -> Callable[[TarInfo, str], TarInfo | None]
594+ ): # -> Callable[[TarInfo, str], TarInfo | None]
589595 state = dict (count = 0 , size = 0 )
590596
591597 AbsoluteLinkError = Exception
592- def data_filter (m : TarInfo , _ :str ) -> TarInfo :
598+
599+ def data_filter (m : TarInfo , _ : str ) -> TarInfo :
593600 return m
594601
595- if (sys .version_info .major == 3 and sys .version_info .minor > 7 ) or sys .version_info .major > 3 :
602+ if (
603+ sys .version_info .major == 3 and sys .version_info .minor > 7
604+ ) or sys .version_info .major > 3 :
596605 from tarfile import data_filter , AbsoluteLinkError
597606
598607 def filter_function (member : TarInfo , dest_path : str ) -> Optional [TarInfo ]:
@@ -613,9 +622,17 @@ def filter_function(member: TarInfo, dest_path: str) -> Optional[TarInfo]:
613622
614623 return filter_function
615624
625+
616626def get_file_md5 (p : Path ) -> "str" :
617627 with open (p .as_posix (), "rb" ) as f :
618- file_md5 = hashlib .md5 ()
628+ try :
629+ file_md5 = hashlib .md5 (usedforsecurity = False )
630+
631+ # Will throw if < 3.9, can be removed once support
632+ # is dropped
633+ except TypeError :
634+ file_md5 = hashlib .md5 ()
635+
619636 while chunk := f .read (2 ** 16 ):
620637 file_md5 .update (chunk )
621638 return file_md5 .hexdigest ()
0 commit comments