From 57bac189ddc6e28f96a8715b7837037124ffeba0 Mon Sep 17 00:00:00 2001 From: phot0n Date: Fri, 10 Dec 2021 11:56:42 +0530 Subject: [PATCH] chore: rename is_git_url_parsable function and remove walrus operator --- bench/app.py | 9 +++++++-- bench/utils/__init__.py | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bench/app.py b/bench/app.py index e27a5a504..7d677a879 100755 --- a/bench/app.py +++ b/bench/app.py @@ -17,10 +17,10 @@ import bench from bench.exceptions import NotInBenchDirectoryError from bench.utils import ( + check_or_get_parsed_git_obj_from_url, fetch_details_from_tag, get_available_folder_name, is_bench_directory, - is_git_url_parsable, log, run_frappe_cmd, ) @@ -67,6 +67,11 @@ class Healthcare(AppConfig): self.setup_details() def setup_details(self): + # NOTE: ideally it should be used in if-else code block but in order to minimize + # same function calls we're using this over here and since we're currently + # supporting python v3.7, walrus operator (:=) can't be used :( + parsed_git_obj = check_or_get_parsed_git_obj_from_url(self.name) + # fetch meta from installed apps if ( not self.to_clone @@ -82,7 +87,7 @@ def setup_details(self): self._setup_details_from_mounted_disk() # fetch meta for repo from remote git server - traditional get-app url - elif parsed_git_obj := is_git_url_parsable(self.name): + elif parsed_git_obj: self.tag = self.branch self.org = parsed_git_obj.owner self.repo = parsed_git_obj.name diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 5b7e1555d..0469b1300 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -11,6 +11,7 @@ # imports - third party imports import click +import giturlparse # imports - module imports from bench import PROJECT_NAME, VERSION @@ -420,12 +421,11 @@ def fetch_details_from_tag(_tag: str) -> Tuple[str, str, str]: return org, repo, tag -def is_git_url_parsable(url: str) -> Any: - import giturlparse - +def check_or_get_parsed_git_obj_from_url(url: str) -> Any: try: parsed_obj = giturlparse.parse(url) except Exception: + # the git url is not parsable return False return parsed_obj