2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-16 10:05:21 +00:00

perf: Remove Jinja and PackageLoader from the import tree

This commit is contained in:
Aditya Hase 2021-02-20 13:52:39 +05:30
parent df773d4f9f
commit ad90d9485f
No known key found for this signature in database
GPG Key ID: 0A55F0FCA0234972
8 changed files with 23 additions and 22 deletions

View File

@ -1,6 +1,7 @@
"""Module for setting up system and respective bench configurations""" """Module for setting up system and respective bench configurations"""
# imports - third party imports # imports - third party imports
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('bench.config')) def env():
from jinja2 import Environment, PackageLoader
return Environment(loader=PackageLoader('bench.config'))

View File

@ -48,7 +48,7 @@ def setup_letsencrypt(site, custom_domain, bench_path, interactive):
def create_config(site, custom_domain): def create_config(site, custom_domain):
config = bench.config.env.get_template('letsencrypt.cfg').render(domain=custom_domain or site) config = bench.config.env().get_template('letsencrypt.cfg').render(domain=custom_domain or site)
config_path = '/etc/letsencrypt/configs/{site}.cfg'.format(site=custom_domain or site) config_path = '/etc/letsencrypt/configs/{site}.cfg'.format(site=custom_domain or site)
create_dir_if_missing(config_path) create_dir_if_missing(config_path)

View File

@ -20,7 +20,7 @@ def make_nginx_conf(bench_path, yes=False):
if not click.confirm('nginx.conf already exists and this will overwrite it. Do you want to continue?'): if not click.confirm('nginx.conf already exists and this will overwrite it. Do you want to continue?'):
return return
template = bench.config.env.get_template('nginx.conf') template = bench.config.env().get_template('nginx.conf')
bench_path = os.path.abspath(bench_path) bench_path = os.path.abspath(bench_path)
sites_path = os.path.join(bench_path, "sites") sites_path = os.path.join(bench_path, "sites")
@ -59,7 +59,7 @@ def make_bench_manager_nginx_conf(bench_path, yes=False, port=23624, domain=None
from bench.config.site_config import get_site_config from bench.config.site_config import get_site_config
from bench.config.common_site_config import get_config from bench.config.common_site_config import get_config
template = bench.config.env.get_template('bench_manager_nginx.conf') template = bench.config.env().get_template('bench_manager_nginx.conf')
bench_path = os.path.abspath(bench_path) bench_path = os.path.abspath(bench_path)
sites_path = os.path.join(bench_path, "sites") sites_path = os.path.join(bench_path, "sites")

View File

@ -18,7 +18,7 @@ def setup_procfile(bench_path, yes=False, skip_redis=False):
click.confirm('A Procfile already exists and this will overwrite it. Do you want to continue?', click.confirm('A Procfile already exists and this will overwrite it. Do you want to continue?',
abort=True) abort=True)
procfile = bench.config.env.get_template('Procfile').render( procfile = bench.config.env().get_template('Procfile').render(
node=find_executable("node") or find_executable("nodejs"), node=find_executable("node") or find_executable("nodejs"),
use_rq=use_rq(bench_path), use_rq=use_rq(bench_path),
webserver_port=config.get('webserver_port'), webserver_port=config.get('webserver_port'),

View File

@ -52,7 +52,7 @@ def generate_config(bench_path):
os.makedirs(pid_path) os.makedirs(pid_path)
def write_redis_config(template_name, context, bench_path): def write_redis_config(template_name, context, bench_path):
template = bench.config.env.get_template(template_name) template = bench.config.env().get_template(template_name)
if "pid_path" not in context: if "pid_path" not in context:
context["pid_path"] = os.path.abspath(os.path.join(bench_path, "config", "pids")) context["pid_path"] = os.path.abspath(os.path.join(bench_path, "config", "pids"))

View File

@ -22,7 +22,7 @@ def generate_supervisor_config(bench_path, user=None, yes=False):
if not user: if not user:
user = getpass.getuser() user = getpass.getuser()
template = bench.config.env.get_template('supervisor.conf') template = bench.config.env().get_template('supervisor.conf')
config = get_config(bench_path=bench_path) config = get_config(bench_path=bench_path)
bench_dir = os.path.abspath(bench_path) bench_dir = os.path.abspath(bench_path)

View File

@ -85,7 +85,7 @@ def setup_systemd_directory(bench_path):
def setup_main_config(bench_info, bench_path): def setup_main_config(bench_info, bench_path):
# Main config # Main config
bench_template = bench.config.env.get_template('systemd/frappe-bench.target') bench_template = bench.config.env().get_template('systemd/frappe-bench.target')
bench_config = bench_template.render(**bench_info) bench_config = bench_template.render(**bench_info)
bench_config_path = os.path.join(bench_path, 'config', 'systemd' , bench_info.get("bench_name") + '.target') bench_config_path = os.path.join(bench_path, 'config', 'systemd' , bench_info.get("bench_name") + '.target')
@ -94,11 +94,11 @@ def setup_main_config(bench_info, bench_path):
def setup_workers_config(bench_info, bench_path): def setup_workers_config(bench_info, bench_path):
# Worker Group # Worker Group
bench_workers_target_template = bench.config.env.get_template('systemd/frappe-bench-workers.target') bench_workers_target_template = bench.config.env().get_template('systemd/frappe-bench-workers.target')
bench_default_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-default-worker.service') bench_default_worker_template = bench.config.env().get_template('systemd/frappe-bench-frappe-default-worker.service')
bench_short_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-short-worker.service') bench_short_worker_template = bench.config.env().get_template('systemd/frappe-bench-frappe-short-worker.service')
bench_long_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-long-worker.service') bench_long_worker_template = bench.config.env().get_template('systemd/frappe-bench-frappe-long-worker.service')
bench_schedule_worker_template = bench.config.env.get_template('systemd/frappe-bench-frappe-schedule.service') bench_schedule_worker_template = bench.config.env().get_template('systemd/frappe-bench-frappe-schedule.service')
bench_workers_target_config = bench_workers_target_template.render(**bench_info) bench_workers_target_config = bench_workers_target_template.render(**bench_info)
bench_default_worker_config = bench_default_worker_template.render(**bench_info) bench_default_worker_config = bench_default_worker_template.render(**bench_info)
@ -129,9 +129,9 @@ def setup_workers_config(bench_info, bench_path):
def setup_web_config(bench_info, bench_path): def setup_web_config(bench_info, bench_path):
# Web Group # Web Group
bench_web_target_template = bench.config.env.get_template('systemd/frappe-bench-web.target') bench_web_target_template = bench.config.env().get_template('systemd/frappe-bench-web.target')
bench_web_service_template = bench.config.env.get_template('systemd/frappe-bench-frappe-web.service') bench_web_service_template = bench.config.env().get_template('systemd/frappe-bench-frappe-web.service')
bench_node_socketio_template = bench.config.env.get_template('systemd/frappe-bench-node-socketio.service') bench_node_socketio_template = bench.config.env().get_template('systemd/frappe-bench-node-socketio.service')
bench_web_target_config = bench_web_target_template.render(**bench_info) bench_web_target_config = bench_web_target_template.render(**bench_info)
bench_web_service_config = bench_web_service_template.render(**bench_info) bench_web_service_config = bench_web_service_template.render(**bench_info)
@ -152,10 +152,10 @@ def setup_web_config(bench_info, bench_path):
def setup_redis_config(bench_info, bench_path): def setup_redis_config(bench_info, bench_path):
# Redis Group # Redis Group
bench_redis_target_template = bench.config.env.get_template('systemd/frappe-bench-redis.target') bench_redis_target_template = bench.config.env().get_template('systemd/frappe-bench-redis.target')
bench_redis_cache_template = bench.config.env.get_template('systemd/frappe-bench-redis-cache.service') bench_redis_cache_template = bench.config.env().get_template('systemd/frappe-bench-redis-cache.service')
bench_redis_queue_template = bench.config.env.get_template('systemd/frappe-bench-redis-queue.service') bench_redis_queue_template = bench.config.env().get_template('systemd/frappe-bench-redis-queue.service')
bench_redis_socketio_template = bench.config.env.get_template('systemd/frappe-bench-redis-socketio.service') bench_redis_socketio_template = bench.config.env().get_template('systemd/frappe-bench-redis-socketio.service')
bench_redis_target_config = bench_redis_target_template.render(**bench_info) bench_redis_target_config = bench_redis_target_template.render(**bench_info)
bench_redis_cache_config = bench_redis_cache_template.render(**bench_info) bench_redis_cache_config = bench_redis_cache_template.render(**bench_info)

View File

@ -423,7 +423,7 @@ def setup_sudoers(user):
if set_permissions: if set_permissions:
os.chmod('/etc/sudoers', 0o440) os.chmod('/etc/sudoers', 0o440)
template = bench.config.env.get_template('frappe_sudoers') template = bench.config.env().get_template('frappe_sudoers')
frappe_sudoers = template.render(**{ frappe_sudoers = template.render(**{
'user': user, 'user': user,
'service': find_executable('service'), 'service': find_executable('service'),