From 4655f6e7857df3109d70a5c52bd42776255f80ea Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 18 Nov 2021 00:10:25 +0530 Subject: [PATCH] refactor(minor): Dependency resolving * Added a requirements method under BenchSetup * Resolve Frappe dependencies prior to other apps * Fixed issues with missing path in update_env_pip --- bench/bench.py | 4 ++++ bench/utils/bench.py | 35 ++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/bench/bench.py b/bench/bench.py index fc5f79ea..9064805f 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -285,6 +285,10 @@ class BenchSetup(Base): logger.log("backups were set up") + def requirements(self): + from bench.utils.bench import update_requirements + update_requirements(bench=self.bench) + class BenchTearDown: def __init__(self, bench): diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 3c0eeee4..690d9fea 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -6,6 +6,7 @@ import re import subprocess import sys from json.decoder import JSONDecodeError +import typing # imports - third party imports import click @@ -15,6 +16,10 @@ import bench from bench.utils import get_process_manager, which, log, exec_cmd, get_bench_name, get_cmd_output from bench.exceptions import PatchError, ValidationError + +if typing.TYPE_CHECKING: + from bench.bench import Bench + logger = logging.getLogger(bench.PROJECT_NAME) @@ -38,41 +43,46 @@ def get_venv_path(): def update_env_pip(bench_path): - env_py = get_env_cmd("python") + env_py = get_env_cmd("python", bench_path=bench_path) exec_cmd(f"{env_py} -m pip install -q -U pip") -def update_requirements(bench_path="."): +def update_requirements(bench: "Bench" = None, bench_path="."): from bench.app import install_app - from bench.bench import Bench - bench = Bench(bench_path) + if not bench: + from bench.bench import Bench + + bench = Bench(bench_path) + apps = [app for app in bench.apps if app not in bench.excluded_apps] + apps.remove("frappe") + apps.insert(0, "frappe") print("Updating env pip...") - - update_env_pip(bench_path) + update_env_pip(bench.name) print(f"Installing {len(apps)} applications...") - for app in apps: - install_app(app, bench_path=bench_path, skip_assets=True, restart_bench=False) + install_app(app, bench_path=bench.name, skip_assets=True, restart_bench=False) def update_python_packages(bench_path="."): from bench.bench import Bench bench = Bench(bench_path) - env_py = get_env_cmd("python") + env_py = get_env_cmd("python", bench_path=bench.name) + apps = [app for app in bench.apps if app not in bench.excluded_apps] + apps.remove("frappe") + apps.insert(0, "frappe") print("Updating Python libraries...") - update_env_pip(bench_path) for app in apps: - click.secho(f"\nInstalling python dependencies for {app}", fg="yellow") app_path = os.path.join(bench_path, "apps", app) + click.secho(f"\nInstalling python dependencies for {app}", fg="yellow") bench.run(f"{env_py} -m pip install -q -U -e {app_path}") @@ -410,8 +420,7 @@ To avoid seeing this warning, set shallow_clone to false in your common_site_con if requirements: print("Setting up requirements...") - update_requirements(bench_path=bench_path) - update_node_packages(bench_path=bench_path) + bench.setup.requirements() if patch: print("Patching sites...")