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

fix: fixed org, branch for apps mounted on disk (#1293)

* fix: fixed org, branch for apps mounted on disk

* fix: DRY-er code

* fix: fixed loading apps when use_ssh is true

* fix: removed flaky tests to test dependencies

* fix: removed exception if app not found in frappe or erpnext org

* fix: remote server

* test: Updated tests

fix: tests

* fix: raise when org is not found

* fix: setup requirements

* fix: falling back to original method of mounted app initialization if git repo isn't found
This commit is contained in:
Aradhya Tripathi 2022-04-19 22:31:51 +05:30 committed by GitHub
parent eb7e006bc4
commit c8ef8224d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 34 deletions

View File

@ -14,6 +14,7 @@ from urllib.parse import urlparse
# imports - third party imports # imports - third party imports
import click import click
from git import Repo
# imports - module imports # imports - module imports
import bench import bench
@ -75,10 +76,10 @@ class AppMeta:
if ( if (
not self.to_clone not self.to_clone
and hasattr(self, "bench") and hasattr(self, "bench")
and os.path.exists(os.path.join(self.bench.name, "apps", self.name)) and os.path.exists(self.mount_path)
): ):
self.from_apps = True self.from_apps = True
self._setup_details_from_installed_apps() self._setup_details_from_mounted_disk()
# fetch meta for repo on mounted disk # fetch meta for repo on mounted disk
elif os.path.exists(self.mount_path): elif os.path.exists(self.mount_path):
@ -88,8 +89,6 @@ class AppMeta:
# fetch meta for repo from remote git server - traditional get-app url # fetch meta for repo from remote git server - traditional get-app url
elif is_git_url(self.name): elif is_git_url(self.name):
self.is_url = True self.is_url = True
if self.name.startswith("git@") or self.name.startswith("ssh://"):
self.use_ssh = True
self._setup_details_from_git_url() self._setup_details_from_git_url()
# fetch meta from new styled name tags & first party apps on github # fetch meta from new styled name tags & first party apps on github
@ -97,39 +96,38 @@ class AppMeta:
self._setup_details_from_name_tag() self._setup_details_from_name_tag()
def _setup_details_from_mounted_disk(self): def _setup_details_from_mounted_disk(self):
self.org, self.repo, self.tag = os.path.split(self.mount_path)[-2:] + (self.branch,) # If app is a git repo
self.git_repo = Repo(self.mount_path)
try:
self._setup_details_from_git_url(self.git_repo.remotes[0].url)
if not (self.branch or self.tag):
self.tag = self.branch = self.git_repo.active_branch.name
except IndexError:
self.org, self.repo, self.tag = os.path.split(self.mount_path)[-2:] + (self.branch,)
def _setup_details_from_name_tag(self): def _setup_details_from_name_tag(self):
self.org, self.repo, self.tag = fetch_details_from_tag(self.name) self.org, self.repo, self.tag = fetch_details_from_tag(self.name)
self.tag = self.tag or self.branch self.tag = self.tag or self.branch
def _setup_details_from_installed_apps(self): def _setup_details_from_git_url(self, url=None):
self.org, self.repo, self.tag = os.path.split( return self.__setup_details_from_git(url)
os.path.join(self.bench.name, "apps", self.name)
)[-2:] + (self.branch,)
def _setup_details_from_git_url(self): def __setup_details_from_git(self, url=None):
return self.__setup_details_from_git() name = url if url else self.name
if name.startswith("git@") or name.startswith("ssh://"):
def __setup_details_from_git(self): self.use_ssh = True
if self.use_ssh: _first_part, _second_part = name.split(":")
_first_part, _second_part = self.name.split(":")
self.remote_server = _first_part.split("@")[-1] self.remote_server = _first_part.split("@")[-1]
self.org, _repo = _second_part.rsplit("/", 1) self.org, _repo = _second_part.rsplit("/", 1)
else: else:
self.remote_server, self.org, _repo = self.name.rsplit("/", 2) protocal = "https://" if "https://" in name else "http://"
self.remote_server, self.org, _repo = name.replace(protocal, "").rsplit("/", 2)
self.tag = self.branch self.tag = self.branch
self.repo = _repo.split(".")[0] self.repo = _repo.split(".")[0]
@property @property
def url(self): def url(self):
if self.from_apps:
return os.path.abspath(os.path.join("apps", self.name))
if self.on_disk:
return self.mount_path
if self.is_url: if self.is_url:
return self.name return self.name

View File

@ -412,7 +412,8 @@ class BenchSetup(Base):
print(f"Installing {len(apps)} applications...") print(f"Installing {len(apps)} applications...")
for app in apps: for app in apps:
App(app, bench=self.bench, to_clone=False).install( path_to_app = os.path.join(self.bench.name, "apps", app)
App(path_to_app, bench=self.bench, to_clone=False).install(
skip_assets=True, restart_bench=False, ignore_resolution=True skip_assets=True, restart_bench=False, ignore_resolution=True
) )

View File

@ -38,7 +38,8 @@ class TestBenchInit(TestBenchBase):
def test_init(self, bench_name="test-bench", **kwargs): def test_init(self, bench_name="test-bench", **kwargs):
self.init_bench(bench_name, **kwargs) self.init_bench(bench_name, **kwargs)
app = App("file:///tmp/frappe") app = App("file:///tmp/frappe")
self.assertEqual(app.url, "/tmp/frappe") self.assertEqual(app.mount_path, "/tmp/frappe")
self.assertEqual(app.url, "https://github.com/frappe/frappe.git")
self.assert_folders(bench_name) self.assert_folders(bench_name)
self.assert_virtual_env(bench_name) self.assert_virtual_env(bench_name)
self.assert_config(bench_name) self.assert_config(bench_name)

View File

@ -73,12 +73,3 @@ class TestUtils(unittest.TestCase):
self.assertEqual("11.0", fake_bench.apps.states["frappe"]["version"]) self.assertEqual("11.0", fake_bench.apps.states["frappe"]["version"])
shutil.rmtree(bench_dir) shutil.rmtree(bench_dir)
def test_get_dependencies(self):
git_url = "https://github.com/frappe/healthcare"
branch = "develop"
fake_app = App(git_url, branch=branch)
self.assertIn("erpnext", fake_app._get_dependencies())
git_url = git_url.replace("healthcare", "erpnext")
fake_app = App(git_url)
self.assertTrue(len(fake_app._get_dependencies()) == 0)

View File

@ -434,7 +434,7 @@ def find_org(org_repo):
if res.ok: if res.ok:
return org, org_repo return org, org_repo
raise InvalidRemoteException(f"{org_repo} Not foung in frappe or erpnext") raise InvalidRemoteException(f"{org_repo} not found in frappe or erpnext")
def fetch_details_from_tag(_tag: str) -> Tuple[str, str, str]: def fetch_details_from_tag(_tag: str) -> Tuple[str, str, str]: