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

fix: import path for util

This commit is contained in:
Gavin D'souza 2021-11-12 18:33:23 +05:30
parent 89fdd1c5ac
commit ee6a967a20
8 changed files with 29 additions and 11 deletions

View File

@ -6,7 +6,7 @@ updated_path = None
def set_frappe_version(bench_path='.'): def set_frappe_version(bench_path='.'):
from .app import get_current_frappe_version from .utils.app import get_current_frappe_version
global FRAPPE_VERSION global FRAPPE_VERSION
if not FRAPPE_VERSION: if not FRAPPE_VERSION:
FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path) FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path)

View File

@ -6,20 +6,22 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
import typing
# imports - third party imports # imports - third party imports
import click import click
# imports - module imports # imports - module imports
import bench 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 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 from bench.utils.bench import get_env_cmd, build_assets, restart_supervisor_processes, restart_systemd_processes
logger = logging.getLogger(bench.PROJECT_NAME) logger = logging.getLogger(bench.PROJECT_NAME)
if typing.TYPE_CHECKING:
from bench.bench import Bench
class AppMeta: class AppMeta:
def __init__(self, name: str, branch : str = None): def __init__(self, name: str, branch : str = None):
""" """
@ -94,7 +96,7 @@ class AppMeta:
class App(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) super().__init__(name, branch)
self.bench = bench self.bench = bench
@ -114,6 +116,8 @@ class App(AppMeta):
) )
def install(self, skip_assets=False, verbose=False): 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) app_name = get_app_name(self.bench.name, self.repo)
# TODO: this should go inside install_app only tho - issue: default/resolved branch # 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='.'): def add_to_appstxt(app, bench_path='.'):
from bench.bench import Bench
apps = Bench(bench_path).apps apps = Bench(bench_path).apps
if app not in 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) return write_appstxt(apps, bench_path=bench_path)
def remove_from_appstxt(app, bench_path='.'): def remove_from_appstxt(app, bench_path='.'):
from bench.bench import Bench
apps = Bench(bench_path).apps apps = Bench(bench_path).apps
if app in 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 If the bench_path is not a bench directory, a new bench is created named using the
git_url parameter. git_url parameter.
""" """
from bench.bench import Bench
bench = Bench(bench_path) bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench) app = App(git_url, branch=branch, bench=bench)
git_url = app.url 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): 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 from bench.utils import get_env_cmd
install_text = f'Installing {app}' 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): def pull_apps(apps=None, bench_path='.', reset=False):
'''Check all apps if there no local changes, pull''' '''Check all apps if there no local changes, pull'''
from bench.bench import Bench
from bench.utils.app import get_remote, get_current_branch from bench.utils.app import get_remote, get_current_branch
bench = Bench(bench_path) bench = Bench(bench_path)

View File

@ -4,8 +4,9 @@ import subprocess
# imports - module imports # imports - module imports
from bench.bench import Bench 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 import set_git_remote_url
from bench.utils.app import get_remote
# imports - third party imports # imports - third party imports
import click import click

View File

@ -1,7 +1,7 @@
import click, os import click, os
from bench.config.procfile import setup_procfile from bench.config.procfile import setup_procfile
from bench.config.supervisor import generate_supervisor_config 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): def execute(bench_path):
frappe_branch = get_current_branch('frappe', bench_path) frappe_branch = get_current_branch('frappe', bench_path)

View File

@ -11,6 +11,7 @@ import unittest
# imports - module imports # imports - module imports
import bench import bench
import bench.utils import bench.utils
from bench.bench import Bench
if sys.version_info.major == 2: if sys.version_info.major == 2:
FRAPPE_BRANCH = "version-12" FRAPPE_BRANCH = "version-12"
@ -25,15 +26,16 @@ class TestBenchBase(unittest.TestCase):
def tearDown(self): def tearDown(self):
for bench_name in self.benches: for bench_name in self.benches:
bench_path = os.path.join(self.benches_path, bench_name) 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: ") 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) if bench.exists:
for site in sites: for site in bench.sites:
subprocess.call(["bench", "drop-site", site, "--force", "--no-backup", "--root-password", mariadb_password], cwd=bench_path) subprocess.call(["bench", "drop-site", site, "--force", "--no-backup", "--root-password", mariadb_password], cwd=bench_path)
shutil.rmtree(bench_path, ignore_errors=True) shutil.rmtree(bench_path, ignore_errors=True)
def assert_folders(self, bench_name): 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, folder)
self.assert_exists(bench_name, "apps", "frappe") self.assert_exists(bench_name, "apps", "frappe")

View File

@ -338,7 +338,7 @@ def generate_command_cache(bench_path='.'):
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
if hasattr(e, "stderr"): if hasattr(e, "stderr"):
print(e.stderr.decode('utf-8')) print(e.stderr)
return [] return []

View File

@ -5,6 +5,7 @@ import bench
import sys import sys
import subprocess import subprocess
from bench.exceptions import InvalidRemoteException, InvalidBranchException, CommandFailedError from bench.exceptions import InvalidRemoteException, InvalidBranchException, CommandFailedError
from bench.app import get_repo_dir
def is_version_upgrade(app='frappe', bench_path='.', branch=None): 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 git
import importlib import importlib
from bench.utils import update_requirements, update_node_packages, backup_all_sites, patch_sites, post_upgrade 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') apps_dir = os.path.join(bench_path, 'apps')
version_upgrade = (False,) version_upgrade = (False,)

View File

@ -10,6 +10,7 @@ import bench
# TODO: Fix this # TODO: Fix this
import bench.utils import bench.utils
from bench.utils import * from bench.utils import *
from bench.utils.bench import build_assets
def init(path, apps_path=None, no_procfile=False, no_backups=False, def init(path, apps_path=None, no_procfile=False, no_backups=False,