mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 17:24:41 +00:00
feat: add required and order of install
This commit is contained in:
parent
af3c871632
commit
9ac091b4d9
52
bench/app.py
52
bench/app.py
@ -149,6 +149,7 @@ class App(AppMeta):
|
|||||||
def __init__(self, name: str, branch: str = None, bench: "Bench" = None, *args, **kwargs):
|
def __init__(self, name: str, branch: str = None, bench: "Bench" = None, *args, **kwargs):
|
||||||
self.bench = bench
|
self.bench = bench
|
||||||
self.required_by = None
|
self.required_by = None
|
||||||
|
self.local_resolution = []
|
||||||
super().__init__(name, branch, *args, **kwargs)
|
super().__init__(name, branch, *args, **kwargs)
|
||||||
|
|
||||||
@step(title="Fetching App {repo}", success="App {repo} Fetched")
|
@step(title="Fetching App {repo}", success="App {repo} Fetched")
|
||||||
@ -194,6 +195,7 @@ class App(AppMeta):
|
|||||||
verbose=verbose,
|
verbose=verbose,
|
||||||
skip_assets=skip_assets,
|
skip_assets=skip_assets,
|
||||||
restart_bench=restart_bench,
|
restart_bench=restart_bench,
|
||||||
|
resolution = self.local_resolution
|
||||||
)
|
)
|
||||||
|
|
||||||
@step(title="Cloning and installing {repo}", success="App {repo} Installed")
|
@step(title="Cloning and installing {repo}", success="App {repo} Installed")
|
||||||
@ -217,6 +219,11 @@ class App(AppMeta):
|
|||||||
|
|
||||||
return required_apps
|
return required_apps
|
||||||
|
|
||||||
|
def update_app_state(self):
|
||||||
|
from bench.bench import Bench
|
||||||
|
bench = Bench(self.bench.name)
|
||||||
|
bench.apps.sync(self.name, self.tag, self.local_resolution)
|
||||||
|
|
||||||
|
|
||||||
def make_resolution_plan(app: App, bench: "Bench"):
|
def make_resolution_plan(app: App, bench: "Bench"):
|
||||||
"""
|
"""
|
||||||
@ -234,6 +241,7 @@ def make_resolution_plan(app: App, bench: "Bench"):
|
|||||||
continue
|
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))
|
||||||
|
app.local_resolution = [repo_name for repo_name, _ in reversed(resolution.items())]
|
||||||
return resolution
|
return resolution
|
||||||
|
|
||||||
|
|
||||||
@ -424,31 +432,33 @@ def install_resolved_deps(
|
|||||||
.decode("utf-8")
|
.decode("utf-8")
|
||||||
.rstrip()
|
.rstrip()
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
|
if app.tag is None:
|
||||||
if app.tag is None:
|
current_remote = (
|
||||||
current_remote = (
|
subprocess.check_output(f"git config branch.{installed_branch}.remote", shell=True, cwd=path_to_app)
|
||||||
subprocess.check_output(f"git config branch.{installed_branch}.remote", shell=True, cwd=path_to_app)
|
.decode("utf-8")
|
||||||
.decode("utf-8")
|
.rstrip()
|
||||||
.rstrip()
|
|
||||||
)
|
|
||||||
|
|
||||||
default_branch = (
|
|
||||||
subprocess.check_output(
|
|
||||||
f"git symbolic-ref refs/remotes/{current_remote}/HEAD", shell=True, cwd=path_to_app
|
|
||||||
)
|
)
|
||||||
.decode("utf-8")
|
|
||||||
.rsplit("/")[-1]
|
default_branch = (
|
||||||
.strip()
|
subprocess.check_output(
|
||||||
)
|
f"git symbolic-ref refs/remotes/{current_remote}/HEAD", shell=True, cwd=path_to_app
|
||||||
is_compatible = default_branch == installed_branch
|
)
|
||||||
else:
|
.decode("utf-8")
|
||||||
is_compatible = installed_branch == app.tag
|
.rsplit("/")[-1]
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
is_compatible = default_branch == installed_branch
|
||||||
|
else:
|
||||||
|
is_compatible = installed_branch == app.tag
|
||||||
|
except:
|
||||||
|
is_compatible = False
|
||||||
|
|
||||||
click.secho(
|
click.secho(
|
||||||
f"{'C' if is_compatible else 'Inc'}ompatible version of {repo_name} is already installed",
|
f"{'C' if is_compatible else 'Inc'}ompatible version of {repo_name} is already installed",
|
||||||
fg="yellow",
|
fg="yellow",
|
||||||
)
|
)
|
||||||
|
app.update_app_state()
|
||||||
continue
|
continue
|
||||||
app.install_resolved_apps(skip_assets=skip_assets, verbose=verbose)
|
app.install_resolved_apps(skip_assets=skip_assets, verbose=verbose)
|
||||||
|
|
||||||
@ -480,6 +490,7 @@ def install_app(
|
|||||||
no_cache=False,
|
no_cache=False,
|
||||||
restart_bench=True,
|
restart_bench=True,
|
||||||
skip_assets=False,
|
skip_assets=False,
|
||||||
|
resolution=[]
|
||||||
):
|
):
|
||||||
import bench.cli as bench_cli
|
import bench.cli as bench_cli
|
||||||
from bench.bench import Bench
|
from bench.bench import Bench
|
||||||
@ -505,8 +516,7 @@ def install_app(
|
|||||||
if os.path.exists(os.path.join(app_path, "package.json")):
|
if os.path.exists(os.path.join(app_path, "package.json")):
|
||||||
bench.run("yarn install", cwd=app_path)
|
bench.run("yarn install", cwd=app_path)
|
||||||
|
|
||||||
bench.apps.sync()
|
bench.apps.sync(app, required=resolution, branch=tag)
|
||||||
bench.apps.update_apps_states(app, branch=tag)
|
|
||||||
|
|
||||||
if not skip_assets:
|
if not skip_assets:
|
||||||
build_assets(bench_path=bench_path, app=app)
|
build_assets(bench_path=bench_path, app=app)
|
||||||
|
@ -125,7 +125,6 @@ class Bench(Base, Validator):
|
|||||||
self.validate_app_uninstall(app)
|
self.validate_app_uninstall(app)
|
||||||
self.apps.remove(App(app, bench=self, to_clone=False))
|
self.apps.remove(App(app, bench=self, to_clone=False))
|
||||||
self.apps.sync()
|
self.apps.sync()
|
||||||
self.apps.update_apps_states()
|
|
||||||
# self.build() - removed because it seems unnecessary
|
# self.build() - removed because it seems unnecessary
|
||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
@ -171,7 +170,7 @@ class BenchApps(MutableSequence):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.states = {}
|
self.states = {}
|
||||||
|
|
||||||
def update_apps_states(self, app_name: Union[str, None] = None, branch: Union[str, None] = None):
|
def update_apps_states(self, app_name: Union[str, None] = None, branch: Union[str, None] = None, required:List = []):
|
||||||
apps_to_remove = []
|
apps_to_remove = []
|
||||||
for app in self.states:
|
for app in self.states:
|
||||||
if app not in self.apps:
|
if app not in self.apps:
|
||||||
@ -199,16 +198,19 @@ class BenchApps(MutableSequence):
|
|||||||
"commit_hash":commit_hash,
|
"commit_hash":commit_hash,
|
||||||
"branch": branch
|
"branch": branch
|
||||||
},
|
},
|
||||||
|
"required":required,
|
||||||
|
"order of install":len(self.states) + 1,
|
||||||
"version": version,
|
"version": version,
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(self.states_path, "w") as f:
|
with open(self.states_path, "w") as f:
|
||||||
f.write(json.dumps(self.states, indent=4))
|
f.write(json.dumps(self.states, indent=4))
|
||||||
|
|
||||||
def sync(self):
|
def sync(self,app_name: Union[str, None] = None, branch: Union[str, None] = None, required:List = []):
|
||||||
self.initialize_apps()
|
self.initialize_apps()
|
||||||
with open(self.bench.apps_txt, "w") as f:
|
with open(self.bench.apps_txt, "w") as f:
|
||||||
return f.write("\n".join(self.apps))
|
f.write("\n".join(self.apps))
|
||||||
|
self.update_apps_states(app_name, branch, required)
|
||||||
|
|
||||||
def initialize_apps(self):
|
def initialize_apps(self):
|
||||||
is_installed = lambda app: app in installed_packages
|
is_installed = lambda app: app in installed_packages
|
||||||
|
Loading…
Reference in New Issue
Block a user