Skip to content

Commit

Permalink
feat: add required and order of install
Browse files Browse the repository at this point in the history
  • Loading branch information
saxenabhishek committed Mar 11, 2022
1 parent af3c871 commit 9ac091b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
50 changes: 30 additions & 20 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class App(AppMeta):
def __init__(self, name: str, branch: str = None, bench: "Bench" = None, *args, **kwargs):
self.bench = bench
self.required_by = None
self.local_resolution = []
super().__init__(name, branch, *args, **kwargs)

@step(title="Fetching App {repo}", success="App {repo} Fetched")
Expand Down Expand Up @@ -194,6 +195,7 @@ def install(self, skip_assets=False, verbose=False, resolved=False, restart_benc
verbose=verbose,
skip_assets=skip_assets,
restart_bench=restart_bench,
resolution = self.local_resolution
)

@step(title="Cloning and installing {repo}", success="App {repo} Installed")
Expand All @@ -217,6 +219,11 @@ def _get_dependencies(self):

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"):
"""
Expand All @@ -234,6 +241,7 @@ def make_resolution_plan(app: App, bench: "Bench"):
continue
resolution[dep_app.repo] = dep_app
resolution.update(make_resolution_plan(dep_app, bench))
app.local_resolution = [repo_name for repo_name, _ in reversed(resolution.items())]
return resolution


Expand Down Expand Up @@ -424,31 +432,33 @@ def install_resolved_deps(
.decode("utf-8")
.rstrip()
)
try:
if app.tag is None:
current_remote = (
subprocess.check_output(f"git config branch.{installed_branch}.remote", shell=True, cwd=path_to_app)
.decode("utf-8")
.rstrip()
)


if app.tag is None:
current_remote = (
subprocess.check_output(f"git config branch.{installed_branch}.remote", shell=True, cwd=path_to_app)
.decode("utf-8")
.rstrip()
)

default_branch = (
subprocess.check_output(
f"git symbolic-ref refs/remotes/{current_remote}/HEAD", shell=True, cwd=path_to_app
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]
.strip()
)
.decode("utf-8")
.rsplit("/")[-1]
.strip()
)
is_compatible = default_branch == installed_branch
else:
is_compatible = installed_branch == app.tag
is_compatible = default_branch == installed_branch
else:
is_compatible = installed_branch == app.tag
except:
is_compatible = False

click.secho(
f"{'C' if is_compatible else 'Inc'}ompatible version of {repo_name} is already installed",
fg="yellow",
)
app.update_app_state()
continue
app.install_resolved_apps(skip_assets=skip_assets, verbose=verbose)

Expand Down Expand Up @@ -480,6 +490,7 @@ def install_app(
no_cache=False,
restart_bench=True,
skip_assets=False,
resolution=[]
):
import bench.cli as bench_cli
from bench.bench import Bench
Expand All @@ -505,8 +516,7 @@ def install_app(
if os.path.exists(os.path.join(app_path, "package.json")):
bench.run("yarn install", cwd=app_path)

bench.apps.sync()
bench.apps.update_apps_states(app, branch=tag)
bench.apps.sync(app, required=resolution, branch=tag)

if not skip_assets:
build_assets(bench_path=bench_path, app=app)
Expand Down
10 changes: 6 additions & 4 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def uninstall(self, app):
self.validate_app_uninstall(app)
self.apps.remove(App(app, bench=self, to_clone=False))
self.apps.sync()
self.apps.update_apps_states()
# self.build() - removed because it seems unnecessary
self.reload()

Expand Down Expand Up @@ -171,7 +170,7 @@ def set_states(self):
except FileNotFoundError:
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 = []
for app in self.states:
if app not in self.apps:
Expand Down Expand Up @@ -199,16 +198,19 @@ def update_apps_states(self, app_name: Union[str, None] = None, branch: Union[st
"commit_hash":commit_hash,
"branch": branch
},
"required":required,
"order of install":len(self.states) + 1,
"version": version,
}

with open(self.states_path, "w") as f:
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()
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):
is_installed = lambda app: app in installed_packages
Expand Down

0 comments on commit 9ac091b

Please sign in to comment.