diff --git a/bench/__init__.py b/bench/__init__.py index ab9281b2..e2f6fd6d 100644 --- a/bench/__init__.py +++ b/bench/__init__.py @@ -6,7 +6,7 @@ updated_path = None def set_frappe_version(bench_path='.'): - from .app import get_current_frappe_version + from .utils.app import get_current_frappe_version global FRAPPE_VERSION if not FRAPPE_VERSION: FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path) \ No newline at end of file diff --git a/bench/app.py b/bench/app.py index a4b318d8..b1a0f1e3 100755 --- a/bench/app.py +++ b/bench/app.py @@ -6,20 +6,22 @@ import re import shutil import subprocess import sys +import typing # imports - third party imports import click # imports - module imports import bench -from bench.bench import Bench from bench.utils import exec_cmd, is_bench_directory, run_frappe_cmd, is_git_url, fetch_details_from_tag -from bench.utils.app import get_app_name from bench.utils.bench import get_env_cmd, build_assets, restart_supervisor_processes, restart_systemd_processes logger = logging.getLogger(bench.PROJECT_NAME) +if typing.TYPE_CHECKING: + from bench.bench import Bench + class AppMeta: def __init__(self, name: str, branch : str = None): """ @@ -94,7 +96,7 @@ class AppMeta: class App(AppMeta): - def __init__(self, name: str, branch : str = None, bench : Bench = None): + def __init__(self, name: str, branch : str = None, bench : "Bench" = None): super().__init__(name, branch) self.bench = bench @@ -114,6 +116,8 @@ class App(AppMeta): ) def install(self, skip_assets=False, verbose=False): + from bench.utils.app import get_app_name + app_name = get_app_name(self.bench.name, self.repo) # TODO: this should go inside install_app only tho - issue: default/resolved branch @@ -133,6 +137,8 @@ class App(AppMeta): def add_to_appstxt(app, bench_path='.'): + from bench.bench import Bench + apps = Bench(bench_path).apps if app not in apps: @@ -140,6 +146,8 @@ def add_to_appstxt(app, bench_path='.'): return write_appstxt(apps, bench_path=bench_path) def remove_from_appstxt(app, bench_path='.'): + from bench.bench import Bench + apps = Bench(bench_path).apps if app in apps: @@ -211,6 +219,8 @@ def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=Fal If the bench_path is not a bench directory, a new bench is created named using the git_url parameter. """ + from bench.bench import Bench + bench = Bench(bench_path) app = App(git_url, branch=branch, bench=bench) git_url = app.url @@ -255,6 +265,7 @@ def new_app(app, bench_path='.'): def install_app(app, bench_path=".", verbose=False, no_cache=False, restart_bench=True, skip_assets=False): + from bench.bench import Bench from bench.utils import get_env_cmd install_text = f'Installing {app}' @@ -291,6 +302,7 @@ def install_app(app, bench_path=".", verbose=False, no_cache=False, restart_benc def pull_apps(apps=None, bench_path='.', reset=False): '''Check all apps if there no local changes, pull''' + from bench.bench import Bench from bench.utils.app import get_remote, get_current_branch bench = Bench(bench_path) diff --git a/bench/commands/git.py b/bench/commands/git.py index 19aa4d36..a0a26ccb 100644 --- a/bench/commands/git.py +++ b/bench/commands/git.py @@ -4,8 +4,9 @@ import subprocess # imports - module imports from bench.bench import Bench -from bench.app import get_repo_dir, get_remote +from bench.app import get_repo_dir from bench.utils import set_git_remote_url +from bench.utils.app import get_remote # imports - third party imports import click diff --git a/bench/patches/v3/celery_to_rq.py b/bench/patches/v3/celery_to_rq.py index 035730a6..29b2af2e 100644 --- a/bench/patches/v3/celery_to_rq.py +++ b/bench/patches/v3/celery_to_rq.py @@ -1,7 +1,7 @@ import click, os from bench.config.procfile import setup_procfile from bench.config.supervisor import generate_supervisor_config -from bench.app import get_current_frappe_version, get_current_branch +from bench.utils.app import get_current_frappe_version, get_current_branch def execute(bench_path): frappe_branch = get_current_branch('frappe', bench_path) diff --git a/bench/tests/test_base.py b/bench/tests/test_base.py index 298d081c..ad884ba5 100644 --- a/bench/tests/test_base.py +++ b/bench/tests/test_base.py @@ -11,6 +11,7 @@ import unittest # imports - module imports import bench import bench.utils +from bench.bench import Bench if sys.version_info.major == 2: FRAPPE_BRANCH = "version-12" @@ -25,15 +26,16 @@ class TestBenchBase(unittest.TestCase): def tearDown(self): for bench_name in self.benches: bench_path = os.path.join(self.benches_path, bench_name) + bench = Bench(bench_path) mariadb_password = "travis" if os.environ.get("CI") else getpass.getpass(prompt="Enter MariaDB root Password: ") - if os.path.exists(bench_path): - sites = bench.utils.get_sites(bench_path=bench_path) - for site in sites: + + if bench.exists: + for site in bench.sites: subprocess.call(["bench", "drop-site", site, "--force", "--no-backup", "--root-password", mariadb_password], cwd=bench_path) shutil.rmtree(bench_path, ignore_errors=True) def assert_folders(self, bench_name): - for folder in bench.utils.folders_in_bench: + for folder in bench.utils.paths_in_bench: self.assert_exists(bench_name, folder) self.assert_exists(bench_name, "apps", "frappe") diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 95b6c68b..b52640b1 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -338,7 +338,7 @@ def generate_command_cache(bench_path='.'): except subprocess.CalledProcessError as e: if hasattr(e, "stderr"): - print(e.stderr.decode('utf-8')) + print(e.stderr) return [] diff --git a/bench/utils/app.py b/bench/utils/app.py index 63bdf786..64d6bf9b 100644 --- a/bench/utils/app.py +++ b/bench/utils/app.py @@ -5,6 +5,7 @@ import bench import sys import subprocess from bench.exceptions import InvalidRemoteException, InvalidBranchException, CommandFailedError +from bench.app import get_repo_dir def is_version_upgrade(app='frappe', bench_path='.', branch=None): @@ -26,6 +27,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad import git import importlib from bench.utils import update_requirements, update_node_packages, backup_all_sites, patch_sites, post_upgrade + from bench.utils.bench import build_assets apps_dir = os.path.join(bench_path, 'apps') version_upgrade = (False,) diff --git a/bench/utils/system.py b/bench/utils/system.py index 8f64431b..16840513 100644 --- a/bench/utils/system.py +++ b/bench/utils/system.py @@ -10,6 +10,7 @@ import bench # TODO: Fix this import bench.utils from bench.utils import * +from bench.utils.bench import build_assets def init(path, apps_path=None, no_procfile=False, no_backups=False,