2
0
mirror of https://github.com/frappe/bench.git synced 2024-06-27 11:43:29 +00:00

refactor: moved resolve and install to get-app

This commit is contained in:
Aradhya 2022-01-28 21:20:14 +05:30 committed by saxenabhishek
parent fdab757f9b
commit 210146d222
4 changed files with 41 additions and 46 deletions

View File

@ -231,7 +231,7 @@ class App(AppMeta):
return info_file["required_apps"] if info_file else {}
def make_resolution_plan(app: App, bench):
def make_resolution_plan(app: App, bench: "Bench"):
"""
decide what apps and versions to install and in what order
"""
@ -341,6 +341,7 @@ def get_app(
verbose=False,
overwrite=False,
init_bench=False,
resolve=False,
):
"""bench get-app clones a Frappe App from remote (GitHub or any other git server),
and installs it on the current bench. This also resolves dependencies based on the
@ -352,6 +353,7 @@ def get_app(
from bench.bench import Bench
import bench as _bench
import bench.cli as bench_cli
from bench.utils.app import check_existing_dir
bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench)
@ -384,9 +386,17 @@ def get_app(
"color": None,
})
if resolve:
resolve_and_install(
app=app,
bench=bench,
bench_path=bench_path,
skip_assets=skip_assets,
verbose=verbose,
)
return
cloned_path = os.path.join(bench_path, "apps", repo_name)
dir_already_exists = os.path.isdir(cloned_path)
dir_already_exists, cloned_path = check_existing_dir(bench_path, repo_name)
to_clone = not dir_already_exists
# application directory already exists
@ -412,35 +422,20 @@ def get_app(
app.install(verbose=verbose, skip_assets=skip_assets)
def resolve_and_install(
git_url,
branch=None,
app: App,
bench: "Bench",
bench_path=".",
skip_assets=False,
verbose=False,
init_bench=False,
):
from bench.cli import Bench
from bench.utils.system import init
from bench.utils.app import check_existing_dir
bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench)
resolution = make_resolution_plan(app, bench)
if "frappe" in resolution:
# Terminal dependency
del resolution["frappe"]
if init_bench:
bench_path = get_available_folder_name(f"{app.repo}-bench", bench_path)
init(
path=bench_path,
frappe_branch=branch,
skip_assets=skip_assets,
verbose=verbose,
)
os.chdir(bench_path)
for repo_name, app in reversed(resolution.items()):
existing_dir, cloned_path = check_existing_dir(bench_path, repo_name)
if existing_dir:
@ -519,7 +514,6 @@ def install_app(
if restart_bench:
bench.reload()
def pull_apps(apps=None, bench_path=".", reset=False):
"""Check all apps if there no local changes, pull"""
from bench.bench import Bench

View File

@ -39,7 +39,6 @@ from bench.commands.make import (
new_app,
pip,
remove_app,
resolve_and_install,
)
bench_command.add_command(init)
@ -49,7 +48,6 @@ bench_command.add_command(new_app)
bench_command.add_command(remove_app)
bench_command.add_command(exclude_app_for_update)
bench_command.add_command(include_app_for_update)
bench_command.add_command(resolve_and_install)
bench_command.add_command(pip)

View File

@ -133,8 +133,20 @@ def drop(path):
@click.option(
"--init-bench", is_flag=True, default=False, help="Initialize Bench if not in one"
)
@click.option(
"--resolve/--no-resolve",
is_flag=True,
default=False,
help="Resolve dependencies before installing app",
)
def get_app(
git_url, branch, name=None, overwrite=False, skip_assets=False, init_bench=False
git_url,
branch,
name=None,
overwrite=False,
skip_assets=False,
init_bench=False,
resolve=False,
):
"clone an app from the internet and set it up in your bench"
from bench.app import get_app
@ -145,26 +157,7 @@ def get_app(
skip_assets=skip_assets,
overwrite=overwrite,
init_bench=init_bench,
)
@click.command("resolve-and-install", help="Resolve dependencies and install apps")
@click.argument("git-url")
@click.option("--branch", default=None)
@click.option("--skip-assets", is_flag=True, default=False, help="Do not build assets")
@click.option(
"--init-bench", is_flag=True, default=False, help="Initialize Bench if not in one"
)
@click.option("--skip-assets", is_flag=True, default=False, help="Do not build assets")
@click.option("--verbose", is_flag=True, default=False, help="Verbosity")
def resolve_and_install(git_url, branch, skip_assets, verbose, init_bench):
from bench.app import resolve_and_install
resolve_and_install(
git_url=git_url,
branch=branch,
skip_assets=skip_assets,
init_bench=init_bench,
verbose=verbose,
resolve=resolve,
)
@click.command("new-app", help="Create a new Frappe application under apps folder")

View File

@ -76,7 +76,12 @@ def init(
frappe_path = frappe_path or "https://github.com/frappe/frappe.git"
get_app(
frappe_path, branch=frappe_branch, bench_path=path, skip_assets=True, verbose=verbose
frappe_path,
branch=frappe_branch,
bench_path=path,
skip_assets=True,
verbose=verbose,
resolve=False,
)
# fetch remote apps using config file - deprecate this!
@ -86,7 +91,12 @@ def init(
# getting app on bench init using --install-app
if install_app:
get_app(
install_app, branch=frappe_branch, bench_path=path, skip_assets=True, verbose=verbose
install_app,
branch=frappe_branch,
bench_path=path,
skip_assets=True,
verbose=verbose,
resolve=False,
)
if not skip_assets: