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

Merge branch 'staging' into v5.x

This commit is contained in:
Ankush Menat 2022-10-14 11:58:46 +05:30
commit 9da444da39
2 changed files with 42 additions and 14 deletions

View File

@ -1,5 +1,4 @@
# imports - standard imports # imports - standard imports
from functools import lru_cache
import json import json
import logging import logging
import os import os
@ -10,11 +9,12 @@ import sys
import typing import typing
from collections import OrderedDict from collections import OrderedDict
from datetime import date from datetime import date
from functools import lru_cache
from urllib.parse import urlparse from urllib.parse import urlparse
# imports - third party imports # imports - third party imports
import click import click
from git import Repo import git
# imports - module imports # imports - module imports
import bench import bench
@ -66,12 +66,21 @@ class AppMeta:
self.branch = branch self.branch = branch
self.app_name = None self.app_name = None
self.git_repo = 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( self.mount_path = os.path.abspath(
os.path.join(urlparse(self.name).netloc, urlparse(self.name).path) os.path.join(urlparse(self.name).netloc, urlparse(self.name).path)
) )
self.setup_details() self.setup_details()
def setup_details(self): 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 # fetch meta from installed apps
if self.bench and os.path.exists(os.path.join(self.bench.name, "apps", self.name)): 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) 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): def _setup_details_from_mounted_disk(self):
# If app is a git repo # If app is a git repo
self.git_repo = Repo(self.mount_path) self.git_repo = git.Repo(self.mount_path)
try: try:
self._setup_details_from_git_url(self.git_repo.remotes[0].url) self._setup_details_from_git_url(self.git_repo.remotes[0].url)
if not (self.branch or self.tag): if not (self.branch or self.tag):
@ -192,7 +201,10 @@ class App(AppMeta):
active_app_path = os.path.join("apps", self.name) active_app_path = os.path.join("apps", self.name)
if no_backup: if no_backup:
if not os.path.islink(active_app_path):
shutil.rmtree(active_app_path) shutil.rmtree(active_app_path)
else:
os.remove(active_app_path)
log(f"App deleted from {active_app_path}") log(f"App deleted from {active_app_path}")
else: else:
archived_path = os.path.join("archived", "apps") archived_path = os.path.join("archived", "apps")
@ -663,6 +675,14 @@ def get_repo_dir(app, bench_path="."):
return os.path.join(bench_path, "apps", app) 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="."): def install_apps_from_path(path, bench_path="."):
apps = get_apps_json(path) apps = get_apps_json(path)
for app in apps: 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.render import job, step
from bench.utils.app import get_current_version from bench.utils.app import get_current_version
from bench.app import is_git_repo
if TYPE_CHECKING: if TYPE_CHECKING:
@ -222,9 +223,13 @@ class BenchApps(MutableSequence):
version = get_current_version(app_name, self.bench.name) version = get_current_version(app_name, self.bench.name)
app_dir = os.path.join(self.apps_path, app_dir) app_dir = os.path.join(self.apps_path, app_dir)
is_repo = is_git_repo(app_dir)
if is_repo:
if not branch: if not branch:
branch = ( branch = (
subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True, cwd=app_dir) subprocess.check_output(
"git rev-parse --abbrev-ref HEAD", shell=True, cwd=app_dir
)
.decode("utf-8") .decode("utf-8")
.rstrip() .rstrip()
) )
@ -236,7 +241,10 @@ class BenchApps(MutableSequence):
) )
self.states[app_name] = { 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, "required": required,
"idx": len(self.states) + 1, "idx": len(self.states) + 1,
"version": version, "version": version,