2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-11 15:51:03 +00:00

Merge pull request #894 from frappe/revert-888-faster-commands

Revert "perf: faster bench"
This commit is contained in:
gavin 2020-01-07 16:06:36 +05:30 committed by GitHub
commit bf88572864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 88 deletions

View File

@ -1,24 +1,13 @@
import json
import logging
import os
import pwd
import subprocess
import sys
import click import click
import os, sys, logging, json, pwd, subprocess
from bench.utils import is_root, PatchError, drop_privileges, get_env_cmd, get_cmd_output, get_frappe
from bench.app import get_apps from bench.app import get_apps
from bench.commands import bench_command
from bench.config.common_site_config import get_config from bench.config.common_site_config import get_config
from bench.utils import (PatchError, clear_command_cache, drop_privileges, from bench.commands import bench_command
frappe_commands_file, generate_command_cache,
get_cmd_output, get_env_cmd, get_frappe, is_root)
logger = logging.getLogger('bench') logger = logging.getLogger('bench')
from_command_line = False from_command_line = False
def cli(): def cli():
global from_command_line global from_command_line
from_command_line = True from_command_line = True
@ -101,19 +90,18 @@ def frappe_cmd(bench_path='.'):
os.execv(f, [f] + ['-m', 'frappe.utils.bench_helper', 'frappe'] + sys.argv[1:]) os.execv(f, [f] + ['-m', 'frappe.utils.bench_helper', 'frappe'] + sys.argv[1:])
def get_frappe_commands(bench_path='.'): def get_frappe_commands(bench_path='.'):
python = get_env_cmd('python', bench_path=bench_path)
sites_path = os.path.join(bench_path, 'sites') sites_path = os.path.join(bench_path, 'sites')
if not os.path.exists(sites_path): if not os.path.exists(sites_path):
return [] return []
try:
if os.path.exists(frappe_commands_file): output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path)
command_dump = open(frappe_commands_file, 'r').read() # output = output.decode('utf-8')
output = json.loads(command_dump) if command_dump else [] return json.loads(output)
except subprocess.CalledProcessError as e:
else: if hasattr(e, "stderr"):
output = generate_command_cache() print(e.stderr.decode('utf-8'))
return []
return output or []
def get_frappe_help(bench_path='.'): def get_frappe_help(bench_path='.'):
python = get_env_cmd('python', bench_path=bench_path) python = get_env_cmd('python', bench_path=bench_path)

View File

@ -47,8 +47,7 @@ bench_command.add_command(switch_to_develop)
from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root, from bench.commands.utils import (start, restart, set_nginx_port, set_ssl_certificate, set_ssl_certificate_key, set_url_root,
set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt, set_mariadb_host, set_default_site, download_translations, shell, backup_site, backup_all_sites, release, renew_lets_encrypt,
disable_production, bench_src, prepare_beta_release, set_redis_cache_host, set_redis_queue_host, set_redis_socketio_host, disable_production, bench_src, prepare_beta_release, set_redis_cache_host, set_redis_queue_host, set_redis_socketio_host)
generate_command_cache, clear_command_cache)
bench_command.add_command(start) bench_command.add_command(start)
bench_command.add_command(restart) bench_command.add_command(restart)
bench_command.add_command(set_nginx_port) bench_command.add_command(set_nginx_port)
@ -69,8 +68,6 @@ bench_command.add_command(renew_lets_encrypt)
bench_command.add_command(disable_production) bench_command.add_command(disable_production)
bench_command.add_command(bench_src) bench_command.add_command(bench_src)
bench_command.add_command(prepare_beta_release) bench_command.add_command(prepare_beta_release)
bench_command.add_command(generate_command_cache)
bench_command.add_command(clear_command_cache)
from bench.commands.setup import setup from bench.commands.setup import setup
bench_command.add_command(setup) bench_command.add_command(setup)

View File

@ -5,7 +5,7 @@ from bench.config.common_site_config import get_config, update_config
from bench.app import pull_all_apps, is_version_upgrade, validate_branch from bench.app import pull_all_apps, is_version_upgrade, validate_branch
from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update, from bench.utils import (update_bench, validate_upgrade, pre_upgrade, post_upgrade, before_update,
update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets, update_requirements, update_node_packages, backup_all_sites, patch_sites, build_assets,
restart_supervisor_processes, restart_systemd_processes, is_bench_directory, clear_command_cache) restart_supervisor_processes, restart_systemd_processes, is_bench_directory)
from bench import patches from bench import patches
from six.moves import reload_module from six.moves import reload_module
@ -30,8 +30,6 @@ def update(pull=False, patch=False, build=False, bench=False, auto=False, restar
update_bench(bench_repo=True, requirements=True) update_bench(bench_repo=True, requirements=True)
sys.exit() sys.exit()
clear_command_cache(bench_path='.')
if not (pull or patch or build or bench or requirements): if not (pull or patch or build or bench or requirements):
pull, patch, build, bench, requirements = True, True, True, True, True pull, patch, build, bench, requirements = True, True, True, True, True

View File

@ -190,23 +190,3 @@ def bench_src():
"""Prints bench source folder path, which can be used as: cd `bench src` """ """Prints bench source folder path, which can be used as: cd `bench src` """
import bench import bench
print(os.path.dirname(bench.__path__[0])) print(os.path.dirname(bench.__path__[0]))
@click.command('generate-command-cache')
def generate_command_cache(bench_path='.'):
"""
Caches Frappe commands (speeds up bench commands execution)
Default caching behaviour: generated the first time any command is run
"""
from bench.utils import generate_command_cache
return generate_command_cache(bench_path=bench_path)
@click.command('clear-command-cache')
def clear_command_cache(bench_path='.'):
"""
Clears commands cached
Default invalidation behaviour: destroyed on each run of `bench update`
"""
from bench.utils import clear_command_cache
return clear_command_cache(bench_path=bench_path)

View File

@ -1,7 +1,7 @@
import os, sys, shutil, subprocess, logging, itertools, requests, json, platform, select, pwd, grp, multiprocessing, hashlib, glob, errno import os, sys, shutil, subprocess, logging, itertools, requests, json, platform, select, pwd, grp, multiprocessing, hashlib, glob
import semantic_version
from distutils.spawn import find_executable from distutils.spawn import find_executable
import bench import bench
import semantic_version
from bench import env from bench import env
from six import iteritems, PY2 from six import iteritems, PY2
@ -13,7 +13,7 @@ class CommandFailedError(Exception):
pass pass
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
frappe_commands_file = '.frappe-cmd'
folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids') folders_in_bench = ('apps', 'sites', 'config', 'logs', 'config/pids')
@ -69,7 +69,7 @@ def init(path, apps_path=None, no_procfile=False, no_backups=False,
try: try:
os.makedirs(os.path.join(path, dirname)) os.makedirs(os.path.join(path, dirname))
except OSError as e: except OSError as e:
if e.errno == errno.EEXIST: if e.errno == os.errno.EEXIST:
pass pass
setup_logging() setup_logging()
@ -188,7 +188,9 @@ def setup_env(bench_path='.', python = 'python3'):
pip = os.path.join('env', 'bin', 'pip') pip = os.path.join('env', 'bin', 'pip')
exec_cmd('virtualenv -q {} -p {}'.format('env', python), cwd=bench_path) exec_cmd('virtualenv -q {} -p {}'.format('env', python), cwd=bench_path)
exec_cmd('{} -q install --upgrade pip wheel six'.format(pip), cwd=bench_path) exec_cmd('{} -q install --upgrade pip'.format(pip), cwd=bench_path)
exec_cmd('{} -q install wheel'.format(pip), cwd=bench_path)
exec_cmd('{} -q install six'.format(pip), cwd=bench_path)
exec_cmd('{} -q install -e git+https://github.com/frappe/python-pdfkit.git#egg=pdfkit'.format(pip), cwd=bench_path) exec_cmd('{} -q install -e git+https://github.com/frappe/python-pdfkit.git#egg=pdfkit'.format(pip), cwd=bench_path)
def setup_socketio(bench_path='.'): def setup_socketio(bench_path='.'):
@ -712,7 +714,7 @@ def update_translations_p(args):
print('Download failed for', args[0], args[1]) print('Download failed for', args[0], args[1])
def download_translations_p(): def download_translations_p():
pool = multiprocessing.Pool(multiprocessing.cpu_count()) pool = multiprocessing.Pool(4)
langs = get_langs() langs = get_langs()
apps = ('frappe', 'erpnext') apps = ('frappe', 'erpnext')
@ -854,34 +856,3 @@ def run_playbook(playbook_name, extra_vars=None, tag=None):
args.extend(['-t', tag]) args.extend(['-t', tag])
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks')) subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))
def generate_command_cache(bench_path='.'):
"""
Caches Frappe commands (speeds up bench commands execution)
Default caching behaviour: generated the first time any command is run
"""
python = get_env_cmd('python', bench_path=bench_path)
sites_path = os.path.join(bench_path, 'sites')
if os.path.exists(frappe_commands_file):
os.remove(frappe_commands_file)
try:
output = get_cmd_output("{python} -m frappe.utils.bench_helper get-frappe-commands".format(python=python), cwd=sites_path)
json.dump(eval(output), open(frappe_commands_file, 'w'))
return output
except subprocess.CalledProcessError as e:
if hasattr(e, "stderr"):
print(e.stderr.decode('utf-8'))
def clear_command_cache(bench_path='.'):
"""
Clears commands cached
Default invalidation behaviour: destroyed on each run of `bench update`
"""
if os.path.exists(frappe_commands_file):
os.remove(frappe_commands_file)
else:
print("Bench command cache doesn't exist in this folder!")