Skip to content

Commit

Permalink
feat: Added app_name attribute to App class
Browse files Browse the repository at this point in the history
  • Loading branch information
Aradhya-Tripathi committed May 6, 2022
1 parent b8aa008 commit 35504f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 12 additions & 1 deletion bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +28,7 @@
is_valid_frappe_branch,
log,
run_frappe_cmd,
is_frappe_app,
)
from bench.utils.bench import (
build_assets,
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
12 changes: 6 additions & 6 deletions bench/utils/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 35504f8

Please sign in to comment.