Skip to content

Commit

Permalink
chore: rename is_git_url_parsable function and remove walrus operator
Browse files Browse the repository at this point in the history
  • Loading branch information
phot0n committed Dec 10, 2021
1 parent c872181 commit 57bac18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

# imports - third party imports
import click
import giturlparse

# imports - module imports
from bench import PROJECT_NAME, VERSION
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 57bac18

Please sign in to comment.