diff --git a/frappe/__init__.py b/frappe/__init__.py index e93b16a79c..b4b44925ef 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -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: diff --git a/frappe/tests/test_commands.py b/frappe/tests/test_commands.py index 7af66f6c62..bbf51de884 100644 --- a/frappe/tests/test_commands.py +++ b/frappe/tests/test_commands.py @@ -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) diff --git a/frappe/utils/change_log.py b/frappe/utils/change_log.py index 6850a9bbf9..55534614e6 100644 --- a/frappe/utils/change_log.py +++ b/frappe/utils/change_log.py @@ -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], diff --git a/frappe/utils/jinja.py b/frappe/utils/jinja.py index 0e5c03eff0..d92df18c70 100644 --- a/frappe/utils/jinja.py +++ b/frappe/utils/jinja.py @@ -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")