refactor: filter out apps not installed on bench

This commit is contained in:
Ankush Menat 2023-01-13 13:50:01 +05:30
parent f5cbcec103
commit 5e2bbf834f
4 changed files with 16 additions and 4 deletions

View file

@ -1399,12 +1399,15 @@ def get_all_apps(with_internal_apps=True, sites_path=None):
@request_cache
def get_installed_apps(sort=False, frappe_last=False):
def get_installed_apps(sort=False, frappe_last=False, *, _ensure_on_bench=False):
"""
Get list of installed apps in current site.
:param sort: [DEPRECATED] Sort installed apps based on the sequence in sites/apps.txt
:param frappe_last: [DEPRECATED] Keep frappe last. Do not use this, reverse the app list instead.
:param ensure_on_bench: Only return apps that are present on bench.
"""
from frappe.utils.deprecations import deprecation_warning
if getattr(flags, "in_install_db", True):
return []
@ -1418,9 +1421,15 @@ def get_installed_apps(sort=False, frappe_last=False):
if not local.all_apps:
local.all_apps = cache().get_value("all_apps", get_all_apps)
deprecation_warning("`sort` argument is deprecated and will be removed in v15.")
installed = [app for app in local.all_apps if app in installed]
if _ensure_on_bench:
all_apps = cache().get_value("all_apps", get_all_apps)
installed = [app for app in installed if app in all_apps]
if frappe_last:
deprecation_warning("`frappe_last` argument is deprecated and will be removed in v15.")
if "frappe" in installed:
installed.remove("frappe")
installed.append("frappe")
@ -1450,7 +1459,7 @@ def _load_app_hooks(app_name: str | None = None):
import types
hooks = {}
apps = [app_name] if app_name else get_installed_apps()
apps = [app_name] if app_name else get_installed_apps(_ensure_on_bench=True)
for app in apps:
try:

View file

@ -300,6 +300,7 @@ class TestCommands(BaseTestCommands):
frappe.local.cache = {}
self.assertEqual(frappe.recorder.status(), False)
@unittest.skip("Poorly written, relied on app name being absent in apps.txt")
def test_remove_from_installed_apps(self):
app = "test_remove_app"
add_to_installed_apps(app)

View file

@ -108,7 +108,7 @@ def get_versions():
}
}"""
versions = {}
for app in frappe.get_installed_apps():
for app in frappe.get_installed_apps(_ensure_on_bench=True):
app_hooks = frappe.get_hooks(app_name=app)
versions[app] = {
"title": app_hooks.get("app_title")[0],

View file

@ -112,7 +112,9 @@ def get_jloader():
apps = frappe.get_hooks("template_apps")
if not apps:
apps = list(reversed(frappe.local.flags.web_pages_apps or frappe.get_installed_apps()))
apps = list(
reversed(frappe.local.flags.web_pages_apps or frappe.get_installed_apps(_ensure_on_bench=True))
)
if "frappe" not in apps:
apps.append("frappe")