mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 00:21:23 +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:
parent
4bc3a086f2
commit
fcbc2eaa47
23
bench/app.py
23
bench/app.py
@ -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):
|
||||||
@ -663,6 +672,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:
|
||||||
|
@ -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,21 +223,28 @@ 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)
|
||||||
if not branch:
|
is_repo = is_git_repo(app_dir)
|
||||||
branch = (
|
if is_repo:
|
||||||
subprocess.check_output("git rev-parse --abbrev-ref HEAD", shell=True, cwd=app_dir)
|
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")
|
.decode("utf-8")
|
||||||
.rstrip()
|
.rstrip()
|
||||||
)
|
)
|
||||||
|
|
||||||
commit_hash = (
|
|
||||||
subprocess.check_output(f"git rev-parse {branch}", shell=True, cwd=app_dir)
|
|
||||||
.decode("utf-8")
|
|
||||||
.rstrip()
|
|
||||||
)
|
|
||||||
|
|
||||||
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,
|
||||||
|
Loading…
Reference in New Issue
Block a user