mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
refactor: moved resolve and install to get-app
This commit is contained in:
parent
549e8e2a1d
commit
2363fe38d5
36
bench/app.py
36
bench/app.py
@ -222,7 +222,7 @@ class App(AppMeta):
|
|||||||
|
|
||||||
return info_file["required_apps"] if info_file else {}
|
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
|
decide what apps and versions to install and in what order
|
||||||
"""
|
"""
|
||||||
@ -332,6 +332,7 @@ def get_app(
|
|||||||
verbose=False,
|
verbose=False,
|
||||||
overwrite=False,
|
overwrite=False,
|
||||||
init_bench=False,
|
init_bench=False,
|
||||||
|
resolve=False,
|
||||||
):
|
):
|
||||||
"""bench get-app clones a Frappe App from remote (GitHub or any other git server),
|
"""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
|
and installs it on the current bench. This also resolves dependencies based on the
|
||||||
@ -343,6 +344,7 @@ def get_app(
|
|||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
import bench as _bench
|
import bench as _bench
|
||||||
import bench.cli as bench_cli
|
import bench.cli as bench_cli
|
||||||
|
from bench.utils.app import check_existing_dir
|
||||||
|
|
||||||
bench = Bench(bench_path)
|
bench = Bench(bench_path)
|
||||||
app = App(git_url, branch=branch, bench=bench)
|
app = App(git_url, branch=branch, bench=bench)
|
||||||
@ -375,9 +377,17 @@ def get_app(
|
|||||||
"color": None,
|
"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, cloned_path = check_existing_dir(bench_path, repo_name)
|
||||||
dir_already_exists = os.path.isdir(cloned_path)
|
|
||||||
to_clone = not dir_already_exists
|
to_clone = not dir_already_exists
|
||||||
|
|
||||||
# application directory already exists
|
# application directory already exists
|
||||||
@ -403,35 +413,20 @@ def get_app(
|
|||||||
app.install(verbose=verbose, skip_assets=skip_assets)
|
app.install(verbose=verbose, skip_assets=skip_assets)
|
||||||
|
|
||||||
def resolve_and_install(
|
def resolve_and_install(
|
||||||
git_url,
|
app: App,
|
||||||
branch=None,
|
bench: "Bench",
|
||||||
bench_path=".",
|
bench_path=".",
|
||||||
skip_assets=False,
|
skip_assets=False,
|
||||||
verbose=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
|
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)
|
resolution = make_resolution_plan(app, bench)
|
||||||
if "frappe" in resolution:
|
if "frappe" in resolution:
|
||||||
# Terminal dependency
|
# Terminal dependency
|
||||||
del resolution["frappe"]
|
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()):
|
for repo_name, app in reversed(resolution.items()):
|
||||||
existing_dir, cloned_path = check_existing_dir(bench_path, repo_name)
|
existing_dir, cloned_path = check_existing_dir(bench_path, repo_name)
|
||||||
if existing_dir:
|
if existing_dir:
|
||||||
@ -510,7 +505,6 @@ def install_app(
|
|||||||
if restart_bench:
|
if restart_bench:
|
||||||
bench.reload()
|
bench.reload()
|
||||||
|
|
||||||
|
|
||||||
def pull_apps(apps=None, bench_path=".", reset=False):
|
def pull_apps(apps=None, bench_path=".", reset=False):
|
||||||
"""Check all apps if there no local changes, pull"""
|
"""Check all apps if there no local changes, pull"""
|
||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
|
@ -39,7 +39,6 @@ from bench.commands.make import (
|
|||||||
new_app,
|
new_app,
|
||||||
pip,
|
pip,
|
||||||
remove_app,
|
remove_app,
|
||||||
resolve_and_install,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
bench_command.add_command(init)
|
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(remove_app)
|
||||||
bench_command.add_command(exclude_app_for_update)
|
bench_command.add_command(exclude_app_for_update)
|
||||||
bench_command.add_command(include_app_for_update)
|
bench_command.add_command(include_app_for_update)
|
||||||
bench_command.add_command(resolve_and_install)
|
|
||||||
bench_command.add_command(pip)
|
bench_command.add_command(pip)
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,8 +133,20 @@ def drop(path):
|
|||||||
@click.option(
|
@click.option(
|
||||||
"--init-bench", is_flag=True, default=False, help="Initialize Bench if not in one"
|
"--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(
|
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"
|
"clone an app from the internet and set it up in your bench"
|
||||||
from bench.app import get_app
|
from bench.app import get_app
|
||||||
@ -145,26 +157,7 @@ def get_app(
|
|||||||
skip_assets=skip_assets,
|
skip_assets=skip_assets,
|
||||||
overwrite=overwrite,
|
overwrite=overwrite,
|
||||||
init_bench=init_bench,
|
init_bench=init_bench,
|
||||||
)
|
resolve=resolve,
|
||||||
|
|
||||||
@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,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@click.command("new-app", help="Create a new Frappe application under apps folder")
|
@click.command("new-app", help="Create a new Frappe application under apps folder")
|
||||||
|
@ -76,7 +76,12 @@ def init(
|
|||||||
frappe_path = frappe_path or "https://github.com/frappe/frappe.git"
|
frappe_path = frappe_path or "https://github.com/frappe/frappe.git"
|
||||||
|
|
||||||
get_app(
|
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!
|
# fetch remote apps using config file - deprecate this!
|
||||||
@ -86,7 +91,12 @@ def init(
|
|||||||
# getting app on bench init using --install-app
|
# getting app on bench init using --install-app
|
||||||
if install_app:
|
if install_app:
|
||||||
get_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:
|
if not skip_assets:
|
||||||
|
Loading…
Reference in New Issue
Block a user