From 3b0bcb7616f8a97e788758cde4ac46c3a1360ee0 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Wed, 5 Jan 2022 16:04:20 +0530 Subject: [PATCH 01/15] fix: Update Click requirement --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e84b98c0..b9cc45c9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Click +Click>=7.0 GitPython~=2.1.15 honcho Jinja2~=2.11.3 From 5b1b84bc5f8938f48d4bc2c25e64b55c10ac0660 Mon Sep 17 00:00:00 2001 From: saxenabhishek Date: Mon, 31 Jan 2022 19:14:16 +0530 Subject: [PATCH 02/15] fix: use frappe13 in py 3.7 --- bench/tests/test_base.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bench/tests/test_base.py b/bench/tests/test_base.py index 75b1646c..4c5b6889 100644 --- a/bench/tests/test_base.py +++ b/bench/tests/test_base.py @@ -14,10 +14,14 @@ from bench.utils import paths_in_bench, exec_cmd from bench.utils.system import init from bench.bench import Bench -if sys.version_info.major == 2: - FRAPPE_BRANCH = "version-12" -else: - FRAPPE_BRANCH = "develop" +PYTHON_VER = sys.version_info + +FRAPPE_BRANCH = "version-12" +if PYTHON_VER.major == 3: + if PYTHON_VER.minor in [6, 7]: + FRAPPE_BRANCH = "version-13" + else: + FRAPPE_BRANCH = "develop" class TestBenchBase(unittest.TestCase): def setUp(self): From c66283dd08e7162fafbe99be8a331e405b6fe679 Mon Sep 17 00:00:00 2001 From: saxenabhishek Date: Sat, 5 Feb 2022 01:49:11 +0530 Subject: [PATCH 03/15] test: `test_switch_to_branch()` which is lower --- bench/tests/test_init.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 331de422..52c23282 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -151,15 +151,21 @@ class TestBenchInit(TestBenchBase): bench_path = os.path.join(self.benches_path, "test-bench") app_path = os.path.join(bench_path, "apps", "frappe") - successful_switch = not exec_cmd("bench switch-to-branch version-13 frappe --upgrade", cwd=bench_path) + # * chore: change to 14 when avalible + prevoius_branch = "version-13" + if FRAPPE_BRANCH != "develop": + # assuming we follow `version-#` + prevoius_branch = f"version-{int(FRAPPE_BRANCH.split('-')[1]) - 1}" + + successful_switch = not exec_cmd(f"bench switch-to-branch {prevoius_branch} frappe --upgrade", cwd=bench_path) app_branch_after_switch = str(git.Repo(path=app_path).active_branch) if successful_switch: - self.assertEqual("version-13", app_branch_after_switch) + self.assertEqual(prevoius_branch, app_branch_after_switch) - successful_switch = not exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path) + successful_switch = not exec_cmd(f"bench switch-to-branch {FRAPPE_BRANCH} frappe --upgrade", cwd=bench_path) app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch) if successful_switch: - self.assertEqual("develop", app_branch_after_second_switch) + self.assertEqual(FRAPPE_BRANCH, app_branch_after_second_switch) if __name__ == '__main__': From d7ad7fd780db99e4e0106d8411b3ee81562f1107 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 18 Feb 2022 11:26:02 +0530 Subject: [PATCH 04/15] chore: bump jinja https://jinja.palletsprojects.com/en/3.0.x/changes/ --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b9cc45c9..68e7c7d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ Click>=7.0 GitPython~=2.1.15 honcho -Jinja2~=2.11.3 +Jinja2~=3.0.3 python-crontab~=2.4.0 requests semantic-version~=2.8.2 From 28e681689fdbed84535c8e5826cf41cf29bdc128 Mon Sep 17 00:00:00 2001 From: DaizyModi <54097382+DaizyModi@users.noreply.github.com> Date: Fri, 18 Feb 2022 17:34:39 +0530 Subject: [PATCH 05/15] feat: Setup Requirements for specific apps (#1265) * feat: flag for Setup Requirements * chore: Moved __get_installed_app method in Bench * fix: improve help message * fix: allow muliple apps to be specified Co-authored-by: Sagar Vora Co-authored-by: gavin --- bench/app.py | 8 ++++++-- bench/bench.py | 38 ++++++++++++++++++++------------------ bench/commands/setup.py | 18 ++++++++++++------ bench/utils/bench.py | 22 ++++++++++++++-------- 4 files changed, 52 insertions(+), 34 deletions(-) diff --git a/bench/app.py b/bench/app.py index 0dc2fba7..259b6429 100755 --- a/bench/app.py +++ b/bench/app.py @@ -173,7 +173,7 @@ class App(AppMeta): shutil.move(active_app_path, archived_app_path) @step(title="Installing App {repo}", success="App {repo} Installed") - def install(self, skip_assets=False, verbose=False): + def install(self, skip_assets=False, verbose=False, restart_bench=True): import bench.cli from bench.utils.app import get_app_name @@ -190,7 +190,11 @@ class App(AppMeta): ) install_app( - app=app_name, bench_path=self.bench.name, verbose=verbose, skip_assets=skip_assets, + app=app_name, + bench_path=self.bench.name, + verbose=verbose, + skip_assets=skip_assets, + restart_bench=restart_bench ) @step(title="Uninstalling App {repo}", success="App {repo} Uninstalled") diff --git a/bench/bench.py b/bench/bench.py index db04fd34..9cce57b4 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -143,6 +143,14 @@ class Bench(Base, Validator): if systemd and conf.get("restart_systemd_on_update"): restart_systemd_processes(bench_path=self.name, web_workers=web) + def get_installed_apps(self) -> List: + """Returns list of installed apps on bench, not in excluded_apps.txt + """ + apps = [app for app in self.apps if app not in self.excluded_apps] + apps.remove("frappe") + apps.insert(0, "frappe") + return apps + class BenchApps(MutableSequence): def __init__(self, bench: Bench): @@ -317,35 +325,29 @@ class BenchSetup(Base): logger.log("backups were set up") - def __get_installed_apps(self) -> List: - """Returns list of installed apps on bench, not in excluded_apps.txt - """ - apps = [app for app in self.bench.apps if app not in self.bench.excluded_apps] - apps.remove("frappe") - apps.insert(0, "frappe") - return apps - @job(title="Setting Up Bench Dependencies", success="Bench Dependencies Set Up") - def requirements(self): - """Install and upgrade all installed apps on given Bench + def requirements(self, apps=None): + """Install and upgrade all installed apps on given Bench if apps not specified """ from bench.app import App - apps = self.__get_installed_apps() + if not apps: + apps = self.bench.get_installed_apps() self.pip() print(f"Installing {len(apps)} applications...") for app in apps: - App(app, bench=self.bench, to_clone=False).install() + App(app, bench=self.bench, to_clone=False).install( skip_assets=True, restart_bench=False) - def python(self): - """Install and upgrade Python dependencies for installed apps on given Bench + def python(self, apps=None): + """Install and upgrade Python dependencies for installed apps on given Bench if app not specified """ import bench.cli - apps = self.__get_installed_apps() + if not apps: + apps = self.bench.get_installed_apps() quiet_flag = "" if bench.cli.verbose else "--quiet" @@ -356,12 +358,12 @@ class BenchSetup(Base): log(f"\nInstalling python dependencies for {app}", level=3, no_log=True) self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {app_path}") - def node(self): - """Install and upgrade Node dependencies for all apps on given Bench + def node(self, apps=None): + """Install and upgrade Node dependencies for all apps on given Bench if app not specified """ from bench.utils.bench import update_node_packages - return update_node_packages(bench_path=self.bench.name) + return update_node_packages(bench_path=self.bench.name, apps=apps) class BenchTearDown: diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 006eba74..b8d4bee3 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -131,27 +131,33 @@ def setup_procfile(): def setup_socketio(): return -@click.command("requirements", help="Setup Python and Node dependencies") +@click.command("requirements") @click.option("--node", help="Update only Node packages", default=False, is_flag=True) @click.option("--python", help="Update only Python packages", default=False, is_flag=True) @click.option("--dev", help="Install optional python development dependencies", default=False, is_flag=True) -def setup_requirements(node=False, python=False, dev=False): +@click.argument("apps", nargs=-1) +def setup_requirements(node=False, python=False, dev=False, apps=None): + """ + Setup Python and Node dependencies. + + You can optionally specify one or more apps to specify dependencies for. + """ from bench.bench import Bench bench = Bench(".") if not (node or python or dev): - bench.setup.requirements() + bench.setup.requirements(apps=apps) elif not node and not dev: - bench.setup.python() + bench.setup.python(apps=apps) elif not python and not dev: - bench.setup.node() + bench.setup.node(apps=apps) else: from bench.utils.bench import install_python_dev_dependencies - install_python_dev_dependencies() + install_python_dev_dependencies(apps=apps) if node: click.secho("--dev flag only supports python dependencies. All node development dependencies are installed by default.", fg="yellow") diff --git a/bench/utils/bench.py b/bench/utils/bench.py index aba4b943..82a63bef 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -48,7 +48,7 @@ def get_venv_path(): return venv or log("virtualenv cannot be found", level=2) -def update_node_packages(bench_path="."): +def update_node_packages(bench_path=".", apps=None): print("Updating node packages...") from bench.utils.app import get_develop_version from distutils.version import LooseVersion @@ -58,9 +58,9 @@ def update_node_packages(bench_path="."): # After rollup was merged, frappe_version = 10.1 # if develop_verion is 11 and up, only then install yarn if v < LooseVersion("11.x.x-develop"): - update_npm_packages(bench_path) + update_npm_packages(bench_path, apps=apps) else: - update_yarn_packages(bench_path) + update_yarn_packages(bench_path, apps=apps) def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False): @@ -75,7 +75,7 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False): if isinstance(apps, str): apps = [apps] elif apps is None: - apps = [app for app in bench.apps if app not in bench.excluded_apps] + apps = bench.get_installed_apps() for app in apps: app_path = os.path.join(bench_path, "apps", app) @@ -86,11 +86,14 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False): bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade -r {dev_requirements_path}") -def update_yarn_packages(bench_path="."): +def update_yarn_packages(bench_path=".", apps=None): from bench.bench import Bench bench = Bench(bench_path) - apps = [app for app in bench.apps if app not in bench.excluded_apps] + + if not apps: + apps = bench.get_installed_apps() + apps_dir = os.path.join(bench.name, "apps") # TODO: Check for stuff like this early on only?? @@ -106,11 +109,14 @@ def update_yarn_packages(bench_path="."): bench.run("yarn install", cwd=app_path) -def update_npm_packages(bench_path="."): +def update_npm_packages(bench_path=".", apps=None): apps_dir = os.path.join(bench_path, "apps") package_json = {} - for app in os.listdir(apps_dir): + if not apps: + apps = os.listdir(apps_dir) + + for app in apps: package_json_path = os.path.join(apps_dir, app, "package.json") if os.path.exists(package_json_path): From 3c5944623a52b6f128e782d6664e03a683d3d0b6 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sat, 19 Feb 2022 09:50:20 +0530 Subject: [PATCH 06/15] fix: clearer docstrings --- bench/bench.py | 6 +++--- bench/commands/setup.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bench/bench.py b/bench/bench.py index 9cce57b4..f359be7c 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -327,7 +327,7 @@ class BenchSetup(Base): @job(title="Setting Up Bench Dependencies", success="Bench Dependencies Set Up") def requirements(self, apps=None): - """Install and upgrade all installed apps on given Bench if apps not specified + """Install and upgrade specified / all installed apps on given Bench """ from bench.app import App @@ -342,7 +342,7 @@ class BenchSetup(Base): App(app, bench=self.bench, to_clone=False).install( skip_assets=True, restart_bench=False) def python(self, apps=None): - """Install and upgrade Python dependencies for installed apps on given Bench if app not specified + """Install and upgrade Python dependencies for specified / all installed apps on given Bench """ import bench.cli @@ -359,7 +359,7 @@ class BenchSetup(Base): self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {app_path}") def node(self, apps=None): - """Install and upgrade Node dependencies for all apps on given Bench if app not specified + """Install and upgrade Node dependencies for specified / all apps on given Bench """ from bench.utils.bench import update_node_packages diff --git a/bench/commands/setup.py b/bench/commands/setup.py index b8d4bee3..a6526cda 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -140,7 +140,7 @@ def setup_requirements(node=False, python=False, dev=False, apps=None): """ Setup Python and Node dependencies. - You can optionally specify one or more apps to specify dependencies for. + You can optionally specify one or more apps to setup dependencies for. """ from bench.bench import Bench From 2fed369066a71e3631edba8f711e421499427803 Mon Sep 17 00:00:00 2001 From: Aradhya Date: Wed, 23 Feb 2022 14:23:06 +0530 Subject: [PATCH 07/15] fix: file-uri while app initialisation --- bench/app.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bench/app.py b/bench/app.py index 259b6429..5ce0f8fc 100755 --- a/bench/app.py +++ b/bench/app.py @@ -9,6 +9,7 @@ import subprocess import sys import typing from datetime import date +from urllib.parse import urlparse # imports - third party imports import click @@ -62,6 +63,9 @@ class AppMeta: self.from_apps = False self.is_url = False self.branch = branch + self.mount_path = os.path.abspath( + os.path.join(urlparse(self.name).netloc, urlparse(self.name).path) + ) self.setup_details() def setup_details(self): @@ -75,7 +79,7 @@ class AppMeta: self._setup_details_from_installed_apps() # fetch meta for repo on mounted disk - elif os.path.exists(self.name): + elif os.path.exists(self.mount_path): self.on_disk = True self._setup_details_from_mounted_disk() @@ -91,7 +95,9 @@ class AppMeta: self._setup_details_from_name_tag() def _setup_details_from_mounted_disk(self): - self.org, self.repo, self.tag = os.path.split(self.name)[-2:] + (self.branch,) + self.org, self.repo, self.tag = os.path.split(self.mount_path)[-2:] + ( + self.branch, + ) def _setup_details_from_name_tag(self): self.org, self.repo, self.tag = fetch_details_from_tag(self.name) @@ -122,7 +128,7 @@ class AppMeta: return os.path.abspath(os.path.join("apps", self.name)) if self.on_disk: - return os.path.abspath(self.name) + return self.mount_path if self.is_url: return self.name From 3dcd28f5690d0fcb1abe53ee26a059036241625b Mon Sep 17 00:00:00 2001 From: Aradhya Date: Wed, 23 Feb 2022 21:53:08 +0530 Subject: [PATCH 08/15] test: updated tests to check for correct parsing of file uris --- bench/tests/test_init.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 52c23282..80018b59 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -10,6 +10,7 @@ import git # imports - module imports from bench.utils import exec_cmd from bench.release import get_bumped_version +from bench.app import App from bench.tests.test_base import FRAPPE_BRANCH, TestBenchBase @@ -34,9 +35,10 @@ class TestBenchInit(TestBenchBase): def test_utils(self): self.assertEqual(subprocess.call("bench"), 0) - def test_init(self, bench_name="test-bench", **kwargs): self.init_bench(bench_name, **kwargs) + app = App("file:///tmp/frappe") + self.assertEqual(app.url, "/tmp/frappe") self.assert_folders(bench_name) self.assert_virtual_env(bench_name) self.assert_config(bench_name) From 25f49c2dbba998a7b11975a6f17034bdb050c3ab Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 17 Mar 2022 10:01:57 +0530 Subject: [PATCH 09/15] fix: Respect bench config during restart Fixes https://github.com/frappe/bench/issues/1261 --- bench/bench.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/bench.py b/bench/bench.py index f359be7c..655693e2 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -138,9 +138,9 @@ class Bench(Base, Validator): if conf.get("developer_mode"): restart_process_manager(bench_path=self.name, web_workers=web) - if supervisor and conf.get("restart_supervisor_on_update"): + if supervisor or 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"): + if systemd or conf.get("restart_systemd_on_update"): restart_systemd_processes(bench_path=self.name, web_workers=web) def get_installed_apps(self) -> List: From d38b63a483deb0186828e82e09c4c650eb672d54 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 17 Mar 2022 09:38:02 +0530 Subject: [PATCH 10/15] fix: mkdir -p to ignore `OSError`s Closes https://github.com/frappe/bench/issues/1279 --- bench/utils/bench.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 82a63bef..9f170ba1 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -174,8 +174,7 @@ def migrate_env(python, backup=False): from datetime import datetime parch = os.path.join(path, "archived", "envs") - if not os.path.exists(parch): - os.mkdir(parch) + os.makedirs(parch, exist_ok=True) source = os.path.join(path, "env") target = parch From d89f19e02ea8aba027f7205a6fe8fb2c93609ad7 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 17 Mar 2022 12:58:05 +0530 Subject: [PATCH 11/15] fix: Show better user messages when failed to update supervisord --- bench/config/supervisor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/config/supervisor.py b/bench/config/supervisor.py index 8db76c3a..765e9989 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -109,7 +109,9 @@ def update_supervisord_config(user=None, yes=False): supervisord_conf_changes += '\n' + action if not supervisord_conf_changes: - logger.log("supervisord.conf not updated") + logger.error("supervisord.conf not updated") + contents = "\n".join(f"{x}={y}" for x, y in updated_values.items()) + print(f"Update your {supervisord_conf} with the following values:\n[{section}]\n{contents}") return if not yes: From 7a4ade9192ca451cfce87280ea05a89caba51054 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 17 Mar 2022 13:03:04 +0530 Subject: [PATCH 12/15] fix: Try setting supervisord conditionally --- bench/commands/setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index a6526cda..99b06606 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -41,9 +41,12 @@ def reload_nginx(): @click.option("--yes", help="Yes to regeneration of supervisor config", is_flag=True, default=False) @click.option("--skip-redis", help="Skip redis configuration", is_flag=True, default=False) def setup_supervisor(user=None, yes=False, skip_redis=False): + from bench.utils import get_cmd_output from bench.config.supervisor import update_supervisord_config, generate_supervisor_config - update_supervisord_config(user=user, yes=yes) + if "Permission denied" in get_cmd_output("supervisorctl status"): + update_supervisord_config(user=user, yes=yes) + generate_supervisor_config(bench_path=".", user=user, yes=yes, skip_redis=skip_redis) From fc7c047c280c443fa85f33f90e572412f206dbff Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 17 Mar 2022 15:04:22 +0530 Subject: [PATCH 13/15] fix: Allow sudo restart for supervisor (backwards compatibility) --- bench/utils/bench.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 9f170ba1..28ca31f3 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -253,7 +253,13 @@ def restart_supervisor_processes(bench_path=".", web_workers=False): bench.run(cmd) else: - supervisor_status = get_cmd_output("supervisorctl status", cwd=bench_path) + sudo = "" + try: + supervisor_status = get_cmd_output("supervisorctl status", cwd=bench_path) + except Exception as e: + if e.returncode == 127: + sudo = "sudo " + supervisor_status = get_cmd_output("sudo supervisorctl status", cwd=bench_path) if web_workers and f"{bench_name}-web:" in supervisor_status: group = f"{bench_name}-web:\t" @@ -269,7 +275,7 @@ def restart_supervisor_processes(bench_path=".", web_workers=False): else: group = "frappe:" - bench.run(f"supervisorctl restart {group}") + bench.run(f"{sudo}supervisorctl restart {group}") def restart_systemd_processes(bench_path=".", web_workers=False): From af14bafe2137da799694a0ad3dd5a2b138c311e6 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 21 Mar 2022 13:37:16 +0530 Subject: [PATCH 14/15] fix(restart): Setup restarts vars with fallback --- bench/app.py | 4 ++-- bench/bench.py | 4 ++-- bench/commands/setup.py | 4 +++- bench/commands/utils.py | 3 +++ bench/utils/__init__.py | 2 +- bench/utils/bench.py | 6 ++++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/bench/app.py b/bench/app.py index 5ce0f8fc..f8c1ba22 100755 --- a/bench/app.py +++ b/bench/app.py @@ -320,6 +320,7 @@ def get_app( repo_name = app.repo branch = app.tag bench_setup = False + restart_bench = not init_bench if not is_bench_directory(bench_path): if not init_bench: @@ -343,7 +344,6 @@ def get_app( "color": None, }) - cloned_path = os.path.join(bench_path, "apps", repo_name) dir_already_exists = os.path.isdir(cloned_path) to_clone = not dir_already_exists @@ -368,7 +368,7 @@ def get_app( or overwrite or click.confirm("Do you want to reinstall the existing application?") ): - app.install(verbose=verbose, skip_assets=skip_assets) + app.install(verbose=verbose, skip_assets=skip_assets, restart_bench=restart_bench) def new_app(app, no_git=None, bench_path="."): diff --git a/bench/bench.py b/bench/bench.py index 655693e2..f359be7c 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -138,9 +138,9 @@ class Bench(Base, Validator): if conf.get("developer_mode"): restart_process_manager(bench_path=self.name, web_workers=web) - if supervisor or conf.get("restart_supervisor_on_update"): + if supervisor and conf.get("restart_supervisor_on_update"): restart_supervisor_processes(bench_path=self.name, web_workers=web) - if systemd or conf.get("restart_systemd_on_update"): + if systemd and conf.get("restart_systemd_on_update"): restart_systemd_processes(bench_path=self.name, web_workers=web) def get_installed_apps(self) -> List: diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 99b06606..42672aa1 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -6,7 +6,7 @@ import sys import click # imports - module imports -from bench.utils import exec_cmd, run_playbook +from bench.utils import exec_cmd, run_playbook, which @click.group(help="Setup command group for enabling setting up a Frappe environment") @@ -44,6 +44,8 @@ def setup_supervisor(user=None, yes=False, skip_redis=False): from bench.utils import get_cmd_output from bench.config.supervisor import update_supervisord_config, generate_supervisor_config + which("supervisorctl", raise_err=True) + if "Permission denied" in get_cmd_output("supervisorctl status"): update_supervisord_config(user=user, yes=yes) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index 20b5a796..b2d8a301 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -23,6 +23,9 @@ 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 + if not systemd and not web: + supervisor = True + Bench(".").reload(web, supervisor, systemd) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index f75fe263..dde12acc 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -133,7 +133,7 @@ def which(executable: str, raise_err: bool = False) -> str: exec_ = which(executable) if not exec_ and raise_err: - raise ValueError(f"{executable} not found.") + raise FileNotFoundError(f"{executable} not found in PATH") return exec_ diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 28ca31f3..e0be48b9 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -258,8 +258,10 @@ def restart_supervisor_processes(bench_path=".", web_workers=False): supervisor_status = get_cmd_output("supervisorctl status", cwd=bench_path) except Exception as e: if e.returncode == 127: - sudo = "sudo " - supervisor_status = get_cmd_output("sudo supervisorctl status", cwd=bench_path) + log("restart failed: Couldn't find supervisorctl in PATH", level=3) + return + sudo = "sudo " + supervisor_status = get_cmd_output("sudo supervisorctl status", cwd=bench_path) if web_workers and f"{bench_name}-web:" in supervisor_status: group = f"{bench_name}-web:\t" From ea947523b36211fbc73fc51c971f44794fd38d46 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Mon, 21 Mar 2022 13:38:04 +0530 Subject: [PATCH 15/15] fix(find): Handle OS' PermissionError --- bench/utils/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index dde12acc..9c8d98a4 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -314,7 +314,13 @@ def find_benches(directory: str = None) -> List: return benches = [] - for sub in os.listdir(directory): + + try: + sub_directories = os.listdir(directory) + except PermissionError: + return benches + + for sub in sub_directories: sub = os.path.join(directory, sub) if os.path.isdir(sub) and not os.path.islink(sub): if is_bench_directory(sub):