2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 00:37:51 +00:00

fix: Check if app is installed in env via initialize_apps

Consequence: Bench.apps only will have valid frappe apps that are installed in env
This commit is contained in:
Gavin D'souza 2021-11-17 23:51:28 +05:30
parent 67e5db6979
commit a192240cec

View File

@ -4,6 +4,7 @@ import sys
import logging import logging
from typing import MutableSequence, TYPE_CHECKING from typing import MutableSequence, TYPE_CHECKING
# imports - module imports
import bench import bench
from bench.exceptions import ValidationError from bench.exceptions import ValidationError
from bench.config.common_site_config import setup_config from bench.config.common_site_config import setup_config
@ -11,6 +12,7 @@ from bench.utils import (
paths_in_bench, paths_in_bench,
exec_cmd, exec_cmd,
is_frappe_app, is_frappe_app,
get_cmd_output,
get_git_version, get_git_version,
run_frappe_cmd, run_frappe_cmd,
) )
@ -138,11 +140,23 @@ class BenchApps(MutableSequence):
return f.write("\n".join(self.apps)) return f.write("\n".join(self.apps))
def initialize_apps(self): def initialize_apps(self):
cmd = f"{get_env_cmd('python', bench_path=self.bench.name)} -m pip freeze"
is_installed = lambda app: app in installed_packages
try:
installed_packages = get_cmd_output(cmd=cmd, cwd=self.bench.name)
except Exception:
self.apps = []
return
try: try:
self.apps = [ self.apps = [
x x
for x in os.listdir(os.path.join(self.bench.name, "apps")) for x in os.listdir(os.path.join(self.bench.name, "apps"))
if is_frappe_app(os.path.join(self.bench.name, "apps", x)) if (
is_frappe_app(os.path.join(self.bench.name, "apps", x))
and is_installed(x)
)
] ]
self.apps.sort() self.apps.sort()
except FileNotFoundError: except FileNotFoundError: