2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-08 00:04:38 +00:00

fix: no-git support for dependency resolver (#1368)

* feat: introducing support for no-git

refactor: lint

* feat: added support for validating git repos

* refactor: removed formatting changes
This commit is contained in:
Aradhya Tripathi 2022-09-08 11:27:34 +05:30 committed by GitHub
parent 4bc3a086f2
commit fcbc2eaa47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 13 deletions

View File

@ -1,5 +1,4 @@
# imports - standard imports
from functools import lru_cache
import json
import logging
import os
@ -10,11 +9,12 @@ import sys
import typing
from collections import OrderedDict
from datetime import date
from functools import lru_cache
from urllib.parse import urlparse
# imports - third party imports
import click
from git import Repo
import git
# imports - module imports
import bench
@ -66,12 +66,21 @@ class AppMeta:
self.branch = branch
self.app_name = None
self.git_repo = None
self.is_repo = (
is_git_repo(app_path=get_repo_dir(self.name))
if os.path.exists(get_repo_dir(self.name))
else True
)
self.mount_path = os.path.abspath(
os.path.join(urlparse(self.name).netloc, urlparse(self.name).path)
)
self.setup_details()
def setup_details(self):
# support for --no-git
if not self.is_repo:
self.repo = self.app_name = self.name
return
# fetch meta from installed apps
if self.bench and os.path.exists(os.path.join(self.bench.name, "apps", self.name)):
self.mount_path = os.path.join(self.bench.name, "apps", self.name)
@ -99,7 +108,7 @@ class AppMeta:
def _setup_details_from_mounted_disk(self):
# If app is a git repo
self.git_repo = Repo(self.mount_path)
self.git_repo = git.Repo(self.mount_path)
try:
self._setup_details_from_git_url(self.git_repo.remotes[0].url)
if not (self.branch or self.tag):
@ -663,6 +672,14 @@ def get_repo_dir(app, bench_path="."):
return os.path.join(bench_path, "apps", app)
def is_git_repo(app_path):
try:
git.Repo(app_path, search_parent_directories=False)
return True
except git.exc.InvalidGitRepositoryError:
return False
def install_apps_from_path(path, bench_path="."):
apps = get_apps_json(path)
for app in apps:

View File

@ -34,6 +34,7 @@ from bench.utils.bench import (
)
from bench.utils.render import job, step
from bench.utils.app import get_current_version
from bench.app import is_git_repo
if TYPE_CHECKING:
@ -222,21 +223,28 @@ class BenchApps(MutableSequence):
version = get_current_version(app_name, self.bench.name)
app_dir = os.path.join(self.apps_path, app_dir)
if not branch:
branch = (
subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True, cwd=app_dir)
is_repo = is_git_repo(app_dir)
if is_repo:
if not branch:
branch = (
subprocess.check_output(
"git rev-parse --abbrev-ref HEAD", shell=True, cwd=app_dir
)
.decode("utf-8")
.rstrip()
)
commit_hash = (
subprocess.check_output(f"git rev-parse {branch}", shell=True, cwd=app_dir)
.decode("utf-8")
.rstrip()
)
commit_hash = (
subprocess.check_output(f"git rev-parse {branch}", shell=True, cwd=app_dir)
.decode("utf-8")
.rstrip()
)
self.states[app_name] = {
"resolution": {"commit_hash": commit_hash, "branch": branch},
"is_repo": is_repo,
"resolution": "not a repo"
if not is_repo
else {"commit_hash": commit_hash, "branch": branch},
"required": required,
"idx": len(self.states) + 1,
"version": version,