mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
refactor: using hooks.py instead of toml files to read dependencies
This commit is contained in:
parent
f2fe56962f
commit
4feb07684a
35
bench/app.py
35
bench/app.py
@ -1,5 +1,4 @@
|
|||||||
# imports - standard imports
|
# imports - standard imports
|
||||||
from collections import OrderedDict
|
|
||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@ -9,6 +8,7 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import typing
|
import typing
|
||||||
|
from collections import OrderedDict
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
@ -219,15 +219,15 @@ class App(AppMeta):
|
|||||||
|
|
||||||
def _get_dependencies(self):
|
def _get_dependencies(self):
|
||||||
from bench.utils.app import get_required_deps_url
|
from bench.utils.app import get_required_deps_url
|
||||||
import toml
|
|
||||||
|
|
||||||
info_file = None
|
required_url = get_required_deps_url(git_url=self.url, repo_name=self.repo, branch=self.tag)
|
||||||
required_url = get_required_deps_url(self.url, self.tag)
|
|
||||||
print(required_url)
|
|
||||||
try:
|
try:
|
||||||
info_file = toml.loads(requests.get(required_url).text)
|
f = requests.get(required_url).text
|
||||||
except Exception:
|
lines = [x for x in f.split("\n") if x.strip().startswith("required_apps")]
|
||||||
click.echo("\nNo toml file found \n", err=True)
|
required_apps = eval(lines[0].strip("required_apps").strip().lstrip("=").strip())
|
||||||
|
return required_apps
|
||||||
|
except Exception as e:
|
||||||
|
return []
|
||||||
|
|
||||||
return info_file["required_apps"] if info_file else {}
|
return info_file["required_apps"] if info_file else {}
|
||||||
|
|
||||||
@ -237,16 +237,17 @@ def make_resolution_plan(app: App, bench: "Bench"):
|
|||||||
"""
|
"""
|
||||||
resolution = OrderedDict()
|
resolution = OrderedDict()
|
||||||
resolution[app.repo] = app
|
resolution[app.repo] = app
|
||||||
for app_name, branch in app._get_dependencies().items():
|
|
||||||
dep_app = App(app_name, branch=branch, bench=bench)
|
for app_name in app._get_dependencies():
|
||||||
|
dep_app = App(app_name, bench=bench)
|
||||||
|
if dep_app.repo in resolution:
|
||||||
|
click.secho(f"{dep_app.repo} is already resolved skipping", fg="yellow")
|
||||||
|
continue
|
||||||
resolution[dep_app.repo] = dep_app
|
resolution[dep_app.repo] = dep_app
|
||||||
resolution.update(make_resolution_plan(dep_app, bench))
|
resolution.update(make_resolution_plan(dep_app, bench))
|
||||||
if app_name in resolution:
|
|
||||||
print("Resolve this conflict!")
|
|
||||||
return resolution
|
return resolution
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_to_appstxt(app, bench_path="."):
|
def add_to_appstxt(app, bench_path="."):
|
||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
|
|
||||||
@ -341,7 +342,7 @@ def get_app(
|
|||||||
verbose=False,
|
verbose=False,
|
||||||
overwrite=False,
|
overwrite=False,
|
||||||
init_bench=False,
|
init_bench=False,
|
||||||
resolve=False,
|
resolve_deps=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
|
||||||
@ -350,9 +351,9 @@ def get_app(
|
|||||||
If the bench_path is not a bench directory, a new bench is created named using the
|
If the bench_path is not a bench directory, a new bench is created named using the
|
||||||
git_url parameter.
|
git_url parameter.
|
||||||
"""
|
"""
|
||||||
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.bench import Bench
|
||||||
from bench.utils.app import check_existing_dir
|
from bench.utils.app import check_existing_dir
|
||||||
|
|
||||||
bench = Bench(bench_path)
|
bench = Bench(bench_path)
|
||||||
@ -363,7 +364,7 @@ def get_app(
|
|||||||
bench_setup = False
|
bench_setup = False
|
||||||
frappe_path, frappe_branch = None, None
|
frappe_path, frappe_branch = None, None
|
||||||
|
|
||||||
if resolve:
|
if resolve_deps:
|
||||||
resolution = make_resolution_plan(app, bench)
|
resolution = make_resolution_plan(app, bench)
|
||||||
if "frappe" in resolution:
|
if "frappe" in resolution:
|
||||||
# Todo: Make frappe a terminal dependency for all frappe apps.
|
# Todo: Make frappe a terminal dependency for all frappe apps.
|
||||||
@ -395,7 +396,7 @@ def get_app(
|
|||||||
"color": None,
|
"color": None,
|
||||||
})
|
})
|
||||||
|
|
||||||
if resolve:
|
if resolve_deps:
|
||||||
install_resolved_deps(
|
install_resolved_deps(
|
||||||
resolution,
|
resolution,
|
||||||
bench_path=bench_path,
|
bench_path=bench_path,
|
||||||
|
Loading…
Reference in New Issue
Block a user