Skip to content

Commit

Permalink
fix: import path for util
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Nov 12, 2021
1 parent 89fdd1c commit ee6a967
Showing 8 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bench/__init__.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@


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)
18 changes: 15 additions & 3 deletions bench/app.py
Original file line number Diff line number Diff line change
@@ -6,20 +6,22 @@
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 @@ def get_ssh_url(self):


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 @@ def remove(self):
)

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,13 +137,17 @@ def uninstall(self):


def add_to_appstxt(app, bench_path='.'):
from bench.bench import Bench

apps = Bench(bench_path).apps

if app not in apps:
apps.append(app)
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)
3 changes: 2 additions & 1 deletion bench/commands/git.py
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@

# 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
2 changes: 1 addition & 1 deletion bench/patches/v3/celery_to_rq.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 6 additions & 4 deletions bench/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
# 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 @@ def setUp(self):
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")

2 changes: 1 addition & 1 deletion bench/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -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 []

2 changes: 2 additions & 0 deletions bench/utils/app.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
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,)
1 change: 1 addition & 0 deletions bench/utils/system.py
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
# 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,

0 comments on commit ee6a967

Please sign in to comment.