Skip to content

Commit

Permalink
refactor: moved resolve and install to get-app
Browse files Browse the repository at this point in the history
  • Loading branch information
Aradhya-Tripathi committed Feb 7, 2022
1 parent 549e8e2 commit 2363fe3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 46 deletions.
36 changes: 15 additions & 21 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _get_dependencies(self):

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
"""
Expand Down Expand Up @@ -332,6 +332,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
Expand All @@ -343,6 +344,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)
Expand Down Expand Up @@ -375,9 +377,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
Expand All @@ -403,35 +413,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:
Expand Down Expand Up @@ -510,7 +505,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
Expand Down
2 changes: 0 additions & 2 deletions bench/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def bench_command(bench_path="."):
new_app,
pip,
remove_app,
resolve_and_install,
)

bench_command.add_command(init)
Expand All @@ -49,7 +48,6 @@ def bench_command(bench_path="."):
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)


Expand Down
35 changes: 14 additions & 21 deletions bench/commands/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
14 changes: 12 additions & 2 deletions bench/utils/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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:
Expand Down

0 comments on commit 2363fe3

Please sign in to comment.