Skip to content

Commit

Permalink
perf: Using github API
Browse files Browse the repository at this point in the history
  • Loading branch information
Aradhya-Tripathi committed Mar 2, 2022
1 parent de315f2 commit b0ae3ae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
21 changes: 15 additions & 6 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,26 @@ def uninstall(self):
self.bench.run(f"{self.bench.python} -m pip uninstall -y {self.repo}")

def _get_dependencies(self):
from bench.utils.app import get_required_deps_url
from bench.utils.app import get_required_deps

required_url = get_required_deps_url(git_url=self.url, repo_name=self.repo, branch=self.tag)
try:
f = requests.get(required_url).text
lines = [x for x in f.split("\n") if x.strip().startswith("required_apps")]
required_apps = eval(lines[0].strip("required_apps").strip().lstrip("=").strip())
return required_apps
required_deps = get_required_deps(
self.org, self.repo, self.tag or self.branch
)
lines = [
x
for x in required_deps.split("\n")
if x.strip().startswith("required_apps")
]
required_apps = eval(
lines[0].strip("required_apps").strip().lstrip("=").strip()
)
except Exception:
return []

return required_apps


def make_resolution_plan(app: App, bench: "Bench"):
"""
decide what apps and versions to install and in what order
Expand Down
16 changes: 9 additions & 7 deletions bench/utils/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ def get_current_branch(app, bench_path="."):
repo_dir = get_repo_dir(app, bench_path=bench_path)
return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)

def get_required_deps_url(git_url, repo_name, branch, deps="hooks.py"):
git_url = (
git_url.replace(".git", "").replace("github.com", "raw.github.com")
)
branch = branch if branch else "develop"
git_url += f"/{branch}/{repo_name}/{deps}"
return git_url
def get_required_deps(org, name, branch, deps="hooks.py"):
import requests
import base64

url = f"https://api.github.com/repos/{org}/{name}/contents/{name}/{deps}"
params = {"branch": branch or "develop"}
res = requests.get(url=url, params=params).json()
return base64.decodebytes(res["content"].encode()).decode()


def get_remote(app, bench_path="."):
repo_dir = get_repo_dir(app, bench_path=bench_path)
Expand Down

0 comments on commit b0ae3ae

Please sign in to comment.