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:
parent
92d2fbdc13
commit
15b01e9451
@ -1,13 +1,7 @@
|
|||||||
|
from bench.utils import install_checker
|
||||||
from jinja2 import Environment, PackageLoader
|
from jinja2 import Environment, PackageLoader
|
||||||
|
|
||||||
__version__ = "4.1.0"
|
__version__ = "4.1.0"
|
||||||
|
|
||||||
env = Environment(loader=PackageLoader('bench.config'))
|
env = Environment(loader=PackageLoader('bench.config'))
|
||||||
|
install_checker()
|
||||||
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)
|
|
@ -151,13 +151,7 @@ def new_app(app, bench_path='.'):
|
|||||||
app = app.lower().replace(" ", "_").replace("-", "_")
|
app = app.lower().replace(" ", "_").replace("-", "_")
|
||||||
logger.info('creating new app {}'.format(app))
|
logger.info('creating new app {}'.format(app))
|
||||||
apps = os.path.abspath(os.path.join(bench_path, 'apps'))
|
apps = os.path.abspath(os.path.join(bench_path, 'apps'))
|
||||||
bench.set_frappe_version(bench_path=bench_path)
|
run_frappe_cmd('make-app', apps, app, 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)
|
install_app(app, bench_path=bench_path)
|
||||||
|
|
||||||
def install_app(app, bench_path=".", verbose=False, no_cache=False):
|
def install_app(app, bench_path=".", verbose=False, no_cache=False):
|
||||||
|
@ -17,7 +17,6 @@ def bench_command(bench_path='.'):
|
|||||||
import bench
|
import bench
|
||||||
from bench.utils import setup_logging
|
from bench.utils import setup_logging
|
||||||
|
|
||||||
bench.set_frappe_version(bench_path=bench_path)
|
|
||||||
setup_logging(bench_path=bench_path)
|
setup_logging(bench_path=bench_path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ from six import iteritems
|
|||||||
from six.moves.urllib.parse import urlparse
|
from six.moves.urllib.parse import urlparse
|
||||||
|
|
||||||
import bench
|
import bench
|
||||||
from bench import env
|
|
||||||
|
|
||||||
|
|
||||||
class PatchError(Exception):
|
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:
|
if apps_path:
|
||||||
install_apps_from_path(apps_path, bench_path=path)
|
install_apps_from_path(apps_path, bench_path=path)
|
||||||
|
|
||||||
|
if not skip_assets:
|
||||||
bench.set_frappe_version(bench_path=path)
|
update_node_packages(bench_path=path)
|
||||||
if bench.FRAPPE_VERSION > 5:
|
build_assets(bench_path=path)
|
||||||
if not skip_assets:
|
|
||||||
update_node_packages(bench_path=path)
|
|
||||||
|
|
||||||
set_all_patches_executed(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:
|
if not skip_redis_config_generation:
|
||||||
redis.generate_config(path)
|
redis.generate_config(path)
|
||||||
@ -217,26 +212,16 @@ def setup_socketio(bench_path='.'):
|
|||||||
babel-cli babel-preset-es2015 babel-preset-es2016 babel-preset-es2017 babel-preset-babili", cwd=bench_path)
|
babel-cli babel-preset-es2015 babel-preset-es2016 babel-preset-es2017 babel-preset-babili", cwd=bench_path)
|
||||||
|
|
||||||
def patch_sites(bench_path='.'):
|
def patch_sites(bench_path='.'):
|
||||||
bench.set_frappe_version(bench_path=bench_path)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if bench.FRAPPE_VERSION == 4:
|
run_frappe_cmd('--site', 'all', 'migrate', bench_path=bench_path)
|
||||||
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:
|
except subprocess.CalledProcessError:
|
||||||
raise PatchError
|
raise PatchError
|
||||||
|
|
||||||
def build_assets(bench_path='.', app=None):
|
def build_assets(bench_path='.', app=None):
|
||||||
bench.set_frappe_version(bench_path=bench_path)
|
command = 'bench build'
|
||||||
|
if app:
|
||||||
if bench.FRAPPE_VERSION == 4:
|
command += ' --app {}'.format(app)
|
||||||
exec_cmd("{frappe} --build".format(frappe=get_frappe(bench_path=bench_path)), cwd=os.path.join(bench_path, 'sites'))
|
exec_cmd(command, cwd=bench_path)
|
||||||
else:
|
|
||||||
command = 'bench build'
|
|
||||||
if app:
|
|
||||||
command += ' --app {}'.format(app)
|
|
||||||
exec_cmd(command, cwd=bench_path)
|
|
||||||
|
|
||||||
def get_sites(bench_path='.'):
|
def get_sites(bench_path='.'):
|
||||||
sites_path = os.path.join(bench_path, 'sites')
|
sites_path = os.path.join(bench_path, 'sites')
|
||||||
@ -255,12 +240,7 @@ def setup_auto_update(bench_path='.'):
|
|||||||
def setup_backups(bench_path='.'):
|
def setup_backups(bench_path='.'):
|
||||||
logger.info('setting up backups')
|
logger.info('setting up backups')
|
||||||
bench_dir = get_bench_dir(bench_path=bench_path)
|
bench_dir = get_bench_dir(bench_path=bench_path)
|
||||||
bench.set_frappe_version(bench_path=bench_path)
|
backup_command = "cd {bench_dir} && {bench} --site all backup".format(bench_dir=bench_dir, bench=sys.argv[0])
|
||||||
|
|
||||||
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,
|
add_to_crontab('0 */6 * * * {backup_command} >> {logfile} 2>&1'.format(backup_command=backup_command,
|
||||||
logfile=os.path.join(get_bench_dir(bench_path=bench_path), 'logs', 'backup.log')))
|
logfile=os.path.join(get_bench_dir(bench_path=bench_path), 'logs', 'backup.log')))
|
||||||
@ -302,6 +282,8 @@ def update_bench(bench_repo=True, requirements=True):
|
|||||||
logger.info("Bench Updated!")
|
logger.info("Bench Updated!")
|
||||||
|
|
||||||
def setup_sudoers(user):
|
def setup_sudoers(user):
|
||||||
|
from bench import env
|
||||||
|
|
||||||
if not os.path.exists('/etc/sudoers.d'):
|
if not os.path.exists('/etc/sudoers.d'):
|
||||||
os.makedirs('/etc/sudoers.d')
|
os.makedirs('/etc/sudoers.d')
|
||||||
|
|
||||||
@ -557,13 +539,7 @@ 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))
|
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='.'):
|
def backup_site(site, bench_path='.'):
|
||||||
bench.set_frappe_version(bench_path=bench_path)
|
run_frappe_cmd('--site', site, 'backup', 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='.'):
|
def backup_all_sites(bench_path='.'):
|
||||||
for site in get_sites(bench_path=bench_path):
|
for site in get_sites(bench_path=bench_path):
|
||||||
@ -1042,4 +1018,37 @@ def migrate_env(python, backup=False):
|
|||||||
log.debug('Migration Successful to {}'.format(python))
|
log.debug('Migration Successful to {}'.format(python))
|
||||||
except:
|
except:
|
||||||
log.debug('Migration Error')
|
log.debug('Migration Error')
|
||||||
raise
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user