2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 17:24:41 +00:00

perf: Using github API

This commit is contained in:
Aradhya 2022-03-02 22:44:12 +05:30
parent de315f27ad
commit b0ae3ae359
2 changed files with 24 additions and 13 deletions

View File

@ -215,17 +215,26 @@ class App(AppMeta):
self.bench.run(f"{self.bench.python} -m pip uninstall -y {self.repo}") self.bench.run(f"{self.bench.python} -m pip uninstall -y {self.repo}")
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
required_url = get_required_deps_url(git_url=self.url, repo_name=self.repo, branch=self.tag)
try: try:
f = requests.get(required_url).text required_deps = get_required_deps(
lines = [x for x in f.split("\n") if x.strip().startswith("required_apps")] self.org, self.repo, self.tag or self.branch
required_apps = eval(lines[0].strip("required_apps").strip().lstrip("=").strip()) )
return required_apps 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: except Exception:
return [] return []
return required_apps
def make_resolution_plan(app: App, bench: "Bench"): def make_resolution_plan(app: App, bench: "Bench"):
""" """
decide what apps and versions to install and in what order decide what apps and versions to install and in what order

View File

@ -164,13 +164,15 @@ def get_current_branch(app, bench_path="."):
repo_dir = get_repo_dir(app, bench_path=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) 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"): def get_required_deps(org, name, branch, deps="hooks.py"):
git_url = ( import requests
git_url.replace(".git", "").replace("github.com", "raw.github.com") import base64
)
branch = branch if branch else "develop" url = f"https://api.github.com/repos/{org}/{name}/contents/{name}/{deps}"
git_url += f"/{branch}/{repo_name}/{deps}" params = {"branch": branch or "develop"}
return git_url res = requests.get(url=url, params=params).json()
return base64.decodebytes(res["content"].encode()).decode()
def get_remote(app, bench_path="."): def get_remote(app, bench_path="."):
repo_dir = get_repo_dir(app, bench_path=bench_path) repo_dir = get_repo_dir(app, bench_path=bench_path)