From 35504f81b3340b544da87316046086a0134ae5ff Mon Sep 17 00:00:00 2001 From: Aradhya Date: Fri, 6 May 2022 22:31:42 +0530 Subject: [PATCH] feat: Added app_name attribute to App class --- bench/app.py | 13 ++++++++++++- bench/bench.py | 2 +- bench/utils/app.py | 12 ++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bench/app.py b/bench/app.py index bb23f70c7..f00f8accd 100755 --- a/bench/app.py +++ b/bench/app.py @@ -11,6 +11,7 @@ from collections import OrderedDict from datetime import date from urllib.parse import urlparse +import os # imports - third party imports import click @@ -27,6 +28,7 @@ is_valid_frappe_branch, log, run_frappe_cmd, + is_frappe_app, ) from bench.utils.bench import ( build_assets, @@ -66,6 +68,8 @@ class Healthcare(AppConfig): self.from_apps = False self.is_url = False self.branch = branch + self.app_name = None + self.git_repo = None self.mount_path = os.path.abspath( os.path.join(urlparse(self.name).netloc, urlparse(self.name).path) ) @@ -94,6 +98,13 @@ def setup_details(self): else: self._setup_details_from_name_tag() + if self.git_repo: + self.app_name = os.path.basename( + os.path.normpath(self.git_repo.working_tree_dir) + ) + else: + self.app_name = self.repo + def _setup_details_from_mounted_disk(self): # If app is a git repo self.git_repo = Repo(self.mount_path) @@ -186,7 +197,7 @@ def install( from bench.utils.app import get_app_name verbose = bench.cli.verbose or verbose - app_name = get_app_name(self.bench.name, self.repo) + app_name = get_app_name(self.bench.name, self.app_name) if not resolved and self.repo != "frappe" and not ignore_resolution: click.secho( f"Ignoring dependencies of {self.name}. To install dependencies use --resolve-deps", diff --git a/bench/bench.py b/bench/bench.py index 9d8d23dee..c07fd4f43 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -413,7 +413,7 @@ def requirements(self, apps=None): for app in apps: path_to_app = os.path.join(self.bench.name, "apps", app) - App(path_to_app, bench=self.bench, to_clone=False).install( + app = App(path_to_app, bench=self.bench, to_clone=False).install( skip_assets=True, restart_bench=False, ignore_resolution=True ) diff --git a/bench/utils/app.py b/bench/utils/app.py index d07422e1b..158fdf964 100644 --- a/bench/utils/app.py +++ b/bench/utils/app.py @@ -210,25 +210,25 @@ def get_remote(app, bench_path="."): return contents.splitlines()[0].split()[0] -def get_app_name(bench_path, repo_name): +def get_app_name(bench_path, folder_name): app_name = None apps_path = os.path.join(os.path.abspath(bench_path), "apps") - config_path = os.path.join(apps_path, repo_name, "setup.cfg") + config_path = os.path.join(apps_path, folder_name, "setup.cfg") if os.path.exists(config_path): config = read_configuration(config_path) app_name = config.get("metadata", {}).get("name") if not app_name: # retrieve app name from setup.py as fallback - app_path = os.path.join(apps_path, repo_name, "setup.py") + app_path = os.path.join(apps_path, folder_name, "setup.py") with open(app_path, "rb") as f: app_name = re.search(r'name\s*=\s*[\'"](.*)[\'"]', f.read().decode("utf-8")).group(1) - if app_name and repo_name != app_name: - os.rename(os.path.join(apps_path, repo_name), os.path.join(apps_path, app_name)) + if app_name and folder_name != app_name: + os.rename(os.path.join(apps_path, folder_name), os.path.join(apps_path, app_name)) return app_name - return repo_name + return folder_name def check_existing_dir(bench_path, repo_name): cloned_path = os.path.join(bench_path, "apps", repo_name)