diff --git a/bench/app.py b/bench/app.py index e36cc73f..4aaed5bf 100755 --- a/bench/app.py +++ b/bench/app.py @@ -35,7 +35,7 @@ if typing.TYPE_CHECKING: class AppMeta: - def __init__(self, name: str, branch: str = None): + def __init__(self, name: str, branch: str = None, to_clone: bool = True): """ name (str): This could look something like 1. https://github.com/frappe/healthcare.git @@ -53,14 +53,21 @@ class AppMeta: """ self.name = name self.remote_server = "github.com" + self.to_clone = to_clone self.on_disk = False self.use_ssh = False + self.from_apps = False self.branch = branch self.setup_details() def setup_details(self): + # fetch meta from installed apps + if not self.to_clone and hasattr(self, "bench") and os.path.exists(os.path.join(self.bench.name, "apps", self.name)): + self.from_apps = True + self._setup_details_from_installed_apps() + # fetch meta for repo on mounted disk - if os.path.exists(self.name): + elif os.path.exists(self.name): self.on_disk = True self._setup_details_from_mounted_disk() @@ -72,11 +79,16 @@ class AppMeta: else: self._setup_details_from_name_tag() + def _setup_details_from_mounted_disk(self): + self.org, self.repo, self.tag = os.path.split(self.name)[-2:] + (self.branch,) + def _setup_details_from_name_tag(self): self.org, self.repo, self.tag = fetch_details_from_tag(self.name) - def _setup_details_from_mounted_disk(self): - self.org, self.repo, self.tag = os.path.split(self.name)[-2:] + (self.branch,) + def _setup_details_from_installed_apps(self): + self.org, self.repo, self.tag = os.path.split( + os.path.join(self.bench.name, "apps", self.name) + )[-2:] + (self.branch,) def _setup_details_from_git_url(self): return self.__setup_details_from_git() @@ -92,6 +104,9 @@ class AppMeta: @property def url(self): + if self.from_apps: + return os.path.abspath(os.path.join("apps", self.name)) + if self.on_disk: return os.path.abspath(self.name) @@ -108,9 +123,9 @@ class AppMeta: class App(AppMeta): - def __init__(self, name: str, branch: str = None, bench: "Bench" = None): - super().__init__(name, branch) + def __init__(self, name: str, branch: str = None, bench: "Bench" = None, *args, **kwargs): self.bench = bench + super().__init__(name, branch, *args, **kwargs) def get(self): branch = f"--branch {self.tag}" if self.tag else "" diff --git a/bench/bench.py b/bench/bench.py index 8add1744..35861bac 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -114,9 +114,9 @@ class Bench(Base, Validator): from bench.app import App self.validate_app_uninstall(app) - self.apps.remove(App(app, bench=self)) + self.apps.remove(App(app, bench=self, to_clone=False)) self.apps.sync() - self.build() + # self.build() - removed because it seems unnecessary self.reload() def build(self): diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 525c6079..6ea4cc1a 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -397,7 +397,7 @@ def fetch_details_from_tag(_tag): try: org, repo = org_repo - except ValueError: + except Exception: org, repo = find_org(org_repo) return org, repo, tag