2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 00:06:36 +00:00

fix: force use PYPI packaged bench

This commit is contained in:
Gavin D'souza 2020-02-25 12:45:49 +05:30
parent 92d2fbdc13
commit 15b01e9451
4 changed files with 49 additions and 53 deletions

View File

@ -1,13 +1,7 @@
from bench.utils import install_checker
from jinja2 import Environment, PackageLoader
__version__ = "4.1.0"
env = Environment(loader=PackageLoader('bench.config'))
FRAPPE_VERSION = None
def set_frappe_version(bench_path='.'):
from .app import get_current_frappe_version
global FRAPPE_VERSION
if not FRAPPE_VERSION:
FRAPPE_VERSION = get_current_frappe_version(bench_path=bench_path)
install_checker()

View File

@ -151,12 +151,6 @@ def new_app(app, bench_path='.'):
app = app.lower().replace(" ", "_").replace("-", "_")
logger.info('creating new app {}'.format(app))
apps = os.path.abspath(os.path.join(bench_path, 'apps'))
bench.set_frappe_version(bench_path=bench_path)
if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --make_app {apps} {app}".format(frappe=get_frappe(bench_path=bench_path),
apps=apps, app=app))
else:
run_frappe_cmd('make-app', apps, app, bench_path=bench_path)
install_app(app, bench_path=bench_path)

View File

@ -17,7 +17,6 @@ def bench_command(bench_path='.'):
import bench
from bench.utils import setup_logging
bench.set_frappe_version(bench_path=bench_path)
setup_logging(bench_path=bench_path)

View File

@ -8,7 +8,6 @@ from six import iteritems
from six.moves.urllib.parse import urlparse
import bench
from bench import env
class PatchError(Exception):
@ -110,15 +109,11 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False, no_auto_upda
if apps_path:
install_apps_from_path(apps_path, bench_path=path)
bench.set_frappe_version(bench_path=path)
if bench.FRAPPE_VERSION > 5:
if not skip_assets:
update_node_packages(bench_path=path)
build_assets(bench_path=path)
set_all_patches_executed(bench_path=path)
if not skip_assets:
build_assets(bench_path=path)
if not skip_redis_config_generation:
redis.generate_config(path)
@ -217,22 +212,12 @@ def setup_socketio(bench_path='.'):
babel-cli babel-preset-es2015 babel-preset-es2016 babel-preset-es2017 babel-preset-babili", cwd=bench_path)
def patch_sites(bench_path='.'):
bench.set_frappe_version(bench_path=bench_path)
try:
if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --latest all".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites'))
else:
run_frappe_cmd('--site', 'all', 'migrate', bench_path=bench_path)
except subprocess.CalledProcessError:
raise PatchError
def build_assets(bench_path='.', app=None):
bench.set_frappe_version(bench_path=bench_path)
if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --build".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites'))
else:
command = 'bench build'
if app:
command += ' --app {}'.format(app)
@ -255,11 +240,6 @@ def setup_auto_update(bench_path='.'):
def setup_backups(bench_path='.'):
logger.info('setting up backups')
bench_dir = get_bench_dir(bench_path=bench_path)
bench.set_frappe_version(bench_path=bench_path)
if bench.FRAPPE_VERSION == 4:
backup_command = "cd {sites_dir} && {frappe} --backup all".format(frappe=get_frappe(bench_path=bench_path),)
else:
backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0])
add_to_crontab('0 */6 * * * {backup_command} >> {logfile} 2>&1'.format(backup_command=backup_command,
@ -302,6 +282,8 @@ def update_bench(bench_repo=True, requirements=True):
logger.info("Bench Updated!")
def setup_sudoers(user):
from bench import env
if not os.path.exists('/etc/sudoers.d'):
os.makedirs('/etc/sudoers.d')
@ -557,12 +539,6 @@ def install_requirements(req_file, user=False):
exec_cmd("{python} -m pip install {user_flag} -q -U -r {req_file}".format(python=python, user_flag=user_flag, req_file=req_file))
def backup_site(site, bench_path='.'):
bench.set_frappe_version(bench_path=bench_path)
if bench.FRAPPE_VERSION == 4:
exec_cmd("{frappe} --backup {site}".format(frappe=get_frappe(bench_path=bench_path), site=site),
cwd=os.path.join(bench_path, 'sites'))
else:
run_frappe_cmd('--site', site, 'backup', bench_path=bench_path)
def backup_all_sites(bench_path='.'):
@ -1043,3 +1019,36 @@ def migrate_env(python, backup=False):
except:
log.debug('Migration Error')
raise
def is_dist_editable(dist):
"""Is distribution an editable install?"""
for path_item in sys.path:
egg_link = os.path.join(path_item, dist + '.egg-link')
if os.path.isfile(egg_link):
return True
return False
def install_checker():
development_mode = os.path.exists(os.path.expanduser("~/.bench.dev"))
bench_editable = is_dist_editable(dist="bench")
if development_mode and bench_editable:
log("bench is setup for development mode")
if development_mode and not bench_editable:
log("Clone bench's git repository from https://github.com/frappe/bench to develop using bench")
if not development_mode and not bench_editable:
"""Ideal scenario for bench users"""
if not development_mode and bench_editable:
log("Installing bench in editable mode is not recommended for production", level=3)
import click
# breaking change!!!
if click.confirm("Do you wish to uninstall editable install and install bench from PYPI?"):
log("Uninstalling bench")
os.system("pip uninstall bench -y")
log("Uninstalled bench", level=2)
log("Installing bench via PYPI")
os.system("pip install frappe-bench")
log("Installed bench via PYPI", level=2)