From 814bcc63207d381638adb2487546d51cc7844cb7 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Dec 2021 14:17:11 +0530 Subject: [PATCH 1/7] refactor: Bench restart * Commonify reloading processes' logic * Add functionality to restart web workers in development * Use Bench.reload instead --- bench/app.py | 8 +------- bench/bench.py | 16 ++++++++++------ bench/commands/utils.py | 9 +-------- bench/utils/bench.py | 15 ++++----------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/bench/app.py b/bench/app.py index 650dd13b..6f35956f 100755 --- a/bench/app.py +++ b/bench/app.py @@ -26,10 +26,7 @@ from bench.utils import ( ) from bench.utils.bench import ( build_assets, - get_env_cmd, install_python_dev_dependencies, - restart_supervisor_processes, - restart_systemd_processes, ) from bench.utils.render import step @@ -417,10 +414,7 @@ def install_app( build_assets(bench_path=bench_path, app=app) if restart_bench: - if conf.get("restart_supervisor_on_update"): - restart_supervisor_processes(bench_path=bench_path) - if conf.get("restart_systemd_on_update"): - restart_systemd_processes(bench_path=bench_path) + bench.reload() def pull_apps(apps=None, bench_path=".", reset=False): diff --git a/bench/bench.py b/bench/bench.py index 157cfef8..db04fd34 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -131,14 +131,18 @@ class Bench(Base, Validator): run_frappe_cmd("build", bench_path=self.name) @step(title="Reloading Bench Processes", success="Bench Processes Reloaded") - def reload(self): + def reload(self, web=False, supervisor=True, systemd=True): + """If web is True, only web workers are restarted + """ conf = self.conf - if conf.get("restart_supervisor_on_update"): - restart_supervisor_processes(bench_path=self.name) - if conf.get("restart_systemd_on_update"): - restart_systemd_processes(bench_path=self.name) + if conf.get("developer_mode"): - restart_process_manager(bench_path=self.name) + restart_process_manager(bench_path=self.name, web_workers=web) + if supervisor and conf.get("restart_supervisor_on_update"): + restart_supervisor_processes(bench_path=self.name, web_workers=web) + if systemd and conf.get("restart_systemd_on_update"): + restart_systemd_processes(bench_path=self.name, web_workers=web) + class BenchApps(MutableSequence): def __init__(self, bench: Bench): diff --git a/bench/commands/utils.py b/bench/commands/utils.py index a5beb614..20b5a796 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -23,14 +23,7 @@ def start(no_dev, concurrency, procfile, no_prefix, man): @click.option('--systemd', is_flag=True, default=False) def restart(web, supervisor, systemd): from bench.bench import Bench - from bench.utils.bench import restart_supervisor_processes, restart_systemd_processes - - bench = Bench(".") - - if bench.conf.get('restart_supervisor_on_update') or supervisor: - restart_supervisor_processes(bench_path='.', web_workers=web) - if bench.conf.get('restart_systemd_on_update') or systemd: - restart_systemd_processes(bench_path='.', web_workers=web) + Bench(".").reload(web, supervisor, systemd) @click.command('set-nginx-port', help="Set NGINX port for site") diff --git a/bench/utils/bench.py b/bench/utils/bench.py index d2f67127..aba4b943 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -279,12 +279,13 @@ def restart_systemd_processes(bench_path=".", web_workers=False): ) -def restart_process_manager(bench_path="."): +def restart_process_manager(bench_path=".", web_workers=False): # only overmind has the restart feature, not sure other supported procmans do if which("overmind") and os.path.exists( os.path.join(bench_path, ".overmind.sock") ): - exec_cmd("overmind restart", cwd=bench_path) + worker = "web" if web_workers else "" + exec_cmd(f"overmind restart {worker}", cwd=bench_path) def build_assets(bench_path=".", app=None): @@ -352,10 +353,6 @@ def update( from bench.utils import clear_command_cache from bench.utils.app import is_version_upgrade - from bench.utils.bench import ( - restart_supervisor_processes, - restart_systemd_processes, - ) from bench.utils.system import backup_all_sites bench_path = os.path.abspath(".") @@ -414,11 +411,7 @@ def update( apps_dir = os.path.join(bench_path, "apps") compile_dir(apps_dir, quiet=1, rx=re.compile(".*node_modules.*")) - if restart_supervisor or conf.get("restart_supervisor_on_update"): - restart_supervisor_processes(bench_path=bench_path) - - if restart_systemd or conf.get("restart_systemd_on_update"): - restart_systemd_processes(bench_path=bench_path) + bench.reload(web=False, supervisor=restart_supervisor, systemd=restart_systemd) conf.update({"maintenance_mode": 0, "pause_scheduler": 0}) update_config(conf, bench_path=bench_path) From ec369a16a1d876104d3e876f6b5baa3487244f02 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 2 Dec 2021 14:22:34 +0530 Subject: [PATCH 2/7] fix: Clear Bench instance cache on every chdir --- bench/cli.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bench/cli.py b/bench/cli.py index b2eeac13..c34e90a7 100755 --- a/bench/cli.py +++ b/bench/cli.py @@ -51,6 +51,7 @@ def cli(): change_working_directory() logger = setup_logging() logger.info(command) + setup_clear_cache() bench_config = get_config(".") @@ -216,3 +217,14 @@ def change_working_directory(): if bench_path: os.chdir(bench_path) + + +def setup_clear_cache(): + from copy import copy + f = copy(os.chdir) + + def _chdir(*args, **kwargs): + Bench.cache_clear() + return f(*args, **kwargs) + + os.chdir = _chdir From 6b99d1d60b045caff85161c9ff91ca0160bb6686 Mon Sep 17 00:00:00 2001 From: phot0n Date: Wed, 1 Dec 2021 21:31:22 +0530 Subject: [PATCH 3/7] chore: change the default version to 13 of erpnext and frappe when installing using easyinstall --- install.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/install.py b/install.py index 16b99be1..54248b9c 100644 --- a/install.py +++ b/install.py @@ -251,16 +251,13 @@ def install_bench(args): if args.production: extra_vars.update(max_worker_connections=multiprocessing.cpu_count() * 1024) - frappe_branch = 'version-13' - erpnext_branch = 'version-13' + if args.version <= 10: + frappe_branch = "{0}.x.x".format(args.version) + erpnext_branch = "{0}.x.x".format(args.version) + else: + frappe_branch = "version-{0}".format(args.version) + erpnext_branch = "version-{0}".format(args.version) - if args.version: - if args.version <= 10: - frappe_branch = "{0}.x.x".format(args.version) - erpnext_branch = "{0}.x.x".format(args.version) - else: - frappe_branch = "version-{0}".format(args.version) - erpnext_branch = "version-{0}".format(args.version) # Allow override of frappe_branch and erpnext_branch, regardless of args.version (which always has a default set) if args.frappe_branch: frappe_branch = args.frappe_branch @@ -445,7 +442,7 @@ def parse_commandline_args(): parser.add_argument('--erpnext-branch', dest='erpnext_branch', action='store', help='Clone a particular branch of erpnext') parser.add_argument('--without-erpnext', dest='without_erpnext', action='store_true', default=False, help='Prevent fetching ERPNext') # direct provision to install versions - parser.add_argument('--version', dest='version', action='store', default='12', type=int, help='Clone particular version of frappe and erpnext') + parser.add_argument('--version', dest='version', action='store', default=13, type=int, help='Clone particular version of frappe and erpnext') # To enable testing of script using Travis, this should skip the prompt parser.add_argument('--run-travis', dest='run_travis', action='store_true', default=False, help=argparse.SUPPRESS) parser.add_argument('--without-bench-setup', dest='without_bench_setup', action='store_true', default=False, help=argparse.SUPPRESS) From aaf48566b71b784b5ba8f3e3347e4f82cb7d4827 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 9 Dec 2021 13:03:01 +0530 Subject: [PATCH 4/7] fix: PosixPath object has no attribute 'rstrip' --- bench/patches/v5/update_archived_sites.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/patches/v5/update_archived_sites.py b/bench/patches/v5/update_archived_sites.py index 0690e4e8..385a00ad 100644 --- a/bench/patches/v5/update_archived_sites.py +++ b/bench/patches/v5/update_archived_sites.py @@ -40,7 +40,7 @@ def execute(bench_path): os.makedirs(new_directory) for archived_site_path in old_directory.glob("*"): - shutil.move(archived_site_path, new_directory) + shutil.move(str(archived_site_path), str(new_directory)) click.secho(f"Archived sites are now stored under {new_directory}") From a648590be4334843f6e0f1a0f699dd55d2daca2e Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Fri, 17 Dec 2021 19:38:41 +0530 Subject: [PATCH 5/7] fix: replace shutil.move with Path.rename Co-authored-by: gavin --- bench/patches/v5/update_archived_sites.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/patches/v5/update_archived_sites.py b/bench/patches/v5/update_archived_sites.py index 385a00ad..15ebf2ac 100644 --- a/bench/patches/v5/update_archived_sites.py +++ b/bench/patches/v5/update_archived_sites.py @@ -40,7 +40,7 @@ def execute(bench_path): os.makedirs(new_directory) for archived_site_path in old_directory.glob("*"): - shutil.move(str(archived_site_path), str(new_directory)) + archived_site_path.rename(new_directory) click.secho(f"Archived sites are now stored under {new_directory}") From fd82585d5f00253fa9d620cd9db6bf4e6b45d11a Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Fri, 17 Dec 2021 19:39:51 +0530 Subject: [PATCH 6/7] chore: remove unnecessary shutil import --- bench/patches/v5/update_archived_sites.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bench/patches/v5/update_archived_sites.py b/bench/patches/v5/update_archived_sites.py index 15ebf2ac..139b65ef 100644 --- a/bench/patches/v5/update_archived_sites.py +++ b/bench/patches/v5/update_archived_sites.py @@ -9,7 +9,6 @@ patch and try again later. Corresponding changes in frappe/frappe via https://github.com/frappe/frappe/pull/15060 """ import os -import shutil from pathlib import Path import click From ad131f17c0e4d7735ad2bcd1cb382ece4ef9c7fb Mon Sep 17 00:00:00 2001 From: gavin Date: Thu, 23 Dec 2021 13:58:41 +0530 Subject: [PATCH 7/7] chore(docs): Add PyPI version badge to README * Add title attr for platform compatibility [ci skip] --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index faf2f726..de2f4365 100755 --- a/README.md +++ b/README.md @@ -12,7 +12,10 @@ Bench is a command-line utility that helps you to install, update, and manage mu - + + PyPI version + + @@ -278,4 +281,4 @@ The intermediate `staging` branch exists to mediate the `bench.VERSION` conflict ## License -This repository has been released under the [GNU GPLv3 License](LICENSE). \ No newline at end of file +This repository has been released under the [GNU GPLv3 License](LICENSE).