From 877bf09afa651960a293f47f3d8335f6d0d7e143 Mon Sep 17 00:00:00 2001 From: Jitendra Mishra Date: Mon, 23 Sep 2024 09:04:47 +0530 Subject: [PATCH 1/6] Avoid continue loop --- bench/utils/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index aee8f4e8..595db994 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -43,6 +43,9 @@ def is_bench_directory(directory=os.path.curdir): for folder in paths_in_bench: path = os.path.abspath(os.path.join(directory, folder)) is_bench = is_bench and os.path.exists(path) + # Once is_bench becomes false, it will always be false, even if other path exists. + if not is_bench: + break return is_bench From f3110e5456a33204509b4b8a9555f60b392767f9 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 25 Nov 2024 13:40:27 +0530 Subject: [PATCH 2/6] fix: use `with` to read pyproject.toml Also fix variable name Signed-off-by: Akhil Narang --- bench/utils/bench.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 8a455d5f..b96417f8 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -114,10 +114,11 @@ def _generate_dev_deps_pattern(pyproject_path): from tomllib import loads requirements_pattern = "" - pyroject_config = loads(open(pyproject_path).read()) + with open(pyproject_path) as f: + pyproject_config = loads(f.read()) with contextlib.suppress(KeyError): - for pkg, version in pyroject_config["tool"]["bench"]["dev-dependencies"].items(): + for pkg, version in pyproject_config["tool"]["bench"]["dev-dependencies"].items(): op = "==" if "=" not in version else "" requirements_pattern += f"{pkg}{op}{version} " return requirements_pattern From 326bcab224e340946ea8eaac1ad8eff54840cc9f Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 25 Nov 2024 13:48:42 +0530 Subject: [PATCH 3/6] refactor: change some exceptions to simple echo + exits The traceback doesn't help in any meaningful way, just makes it harder to decipher the error Signed-off-by: Akhil Narang --- bench/app.py | 13 ++++++++----- bench/exceptions.py | 5 ----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/bench/app.py b/bench/app.py index e99eca95..b86ba8fc 100755 --- a/bench/app.py +++ b/bench/app.py @@ -23,7 +23,6 @@ import semantic_version as sv # imports - module imports import bench -from bench.exceptions import NotInBenchDirectoryError from bench.utils import ( UNSET_ARG, fetch_details_from_tag, @@ -706,10 +705,12 @@ def get_app( if not is_bench_directory(bench_path): if not init_bench: - raise NotInBenchDirectoryError( + click.secho( f"{os.path.realpath(bench_path)} is not a valid bench directory. " - "Run with --init-bench if you'd like to create a Bench too." + "Run with --init-bench if you'd like to create a Bench too.", + fg="red", ) + sys.exit(1) from bench.utils.system import init @@ -851,9 +852,11 @@ def install_resolved_deps( def new_app(app, no_git=None, bench_path="."): if bench.FRAPPE_VERSION in (0, None): - raise NotInBenchDirectoryError( - f"{os.path.realpath(bench_path)} is not a valid bench directory." + click.secho( + f"{os.path.realpath(bench_path)} is not a valid bench directory.", + fg="red", ) + sys.exit(1) # For backwards compatibility app = app.lower().replace(" ", "_").replace("-", "_") diff --git a/bench/exceptions.py b/bench/exceptions.py index 0465167c..ad8d7f3e 100644 --- a/bench/exceptions.py +++ b/bench/exceptions.py @@ -33,10 +33,5 @@ class CannotUpdateReleaseBench(ValidationError): class FeatureDoesNotExistError(CommandFailedError): pass - -class NotInBenchDirectoryError(Exception): - pass - - class VersionNotFound(Exception): pass From 9e42db506097894737f8c8163420001faad84278 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Mon, 25 Nov 2024 13:56:25 +0530 Subject: [PATCH 4/6] chore(ci): drop py3.8, add 11, 12, 13 Signed-off-by: Akhil Narang --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c9dac49..17c3d9ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.8', '3.9', '3.10' ] + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] name: Base (${{ matrix.python-version }}) From 0bb5ffeb693d17a164bb6d9d924a170f089cd8ee Mon Sep 17 00:00:00 2001 From: David Date: Tue, 26 Nov 2024 13:44:12 +0100 Subject: [PATCH 5/6] fix: apps init; apps might be an empty folder still --- bench/bench.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/bench.py b/bench/bench.py index dd2afc98..1b2ca261 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -283,7 +283,7 @@ class BenchApps(MutableSequence): ] self.apps.remove("frappe") self.apps.insert(0, "frappe") - except FileNotFoundError: + except (FileNotFoundError, ValueError): self.apps = [] def __getitem__(self, key): From ac08ec6dee895dbcf9ede1a99d7ce83908262f0e Mon Sep 17 00:00:00 2001 From: David Date: Tue, 26 Nov 2024 12:54:30 +0100 Subject: [PATCH 6/6] feat: add more flexibility to procfile render --- bench/config/procfile.py | 13 +++++++++---- bench/config/templates/Procfile | 13 ++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bench/config/procfile.py b/bench/config/procfile.py index 7feaab72..5b881a3e 100755 --- a/bench/config/procfile.py +++ b/bench/config/procfile.py @@ -4,12 +4,14 @@ import platform import click import bench -from bench.app import use_rq from bench.bench import Bench from bench.utils import which -def setup_procfile(bench_path, yes=False, skip_redis=False): +def setup_procfile(bench_path, yes=False, skip_redis=False, skip_web=False, skip_watch=None, skip_socketio=False, skip_schedule=False, with_coverage=False): + if skip_watch is None: + # backwards compatibilty; may be eventually removed + skip_watch = os.environ.get("CI") config = Bench(bench_path).conf procfile_path = os.path.join(bench_path, "Procfile") @@ -25,10 +27,13 @@ def setup_procfile(bench_path, yes=False, skip_redis=False): .get_template("Procfile") .render( node=which("node") or which("nodejs"), - use_rq=use_rq(bench_path), webserver_port=config.get("webserver_port"), - CI=os.environ.get("CI"), skip_redis=skip_redis, + skip_web=skip_web, + skip_watch=skip_watch, + skip_socketio=skip_socketio, + skip_schedule=skip_schedule, + with_coverage=with_coverage, workers=config.get("workers", {}), is_mac=is_mac, ) diff --git a/bench/config/templates/Procfile b/bench/config/templates/Procfile index 1f2440fb..199b8b2b 100644 --- a/bench/config/templates/Procfile +++ b/bench/config/templates/Procfile @@ -2,15 +2,18 @@ redis_cache: redis-server config/redis_cache.conf redis_queue: redis-server config/redis_queue.conf {% endif %} -web: bench serve {% if webserver_port -%} --port {{ webserver_port }} {%- endif %} - +{% if not skip_web %} +web: bench serve {% if with_coverage -%} --with-coverage {%- endif %} {% if webserver_port -%} --port {{ webserver_port }} {%- endif %} +{% endif %} +{% if not skip_socketio %} socketio: {{ node }} apps/frappe/socketio.js - -{% if not CI %} +{% endif %} +{% if not skip_watch %} watch: bench watch {% endif %} - +{% if not skip_schedule %} schedule: bench schedule +{% endif %} worker: {{ 'OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES NO_PROXY=*' if is_mac else '' }} bench worker 1>> logs/worker.log 2>> logs/worker.error.log {% for worker_name, worker_details in workers.items() %} worker_{{ worker_name }}: {{ 'OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES NO_PROXY=*' if is_mac else '' }} bench worker --queue {{ worker_name }} 1>> logs/worker.log 2>> logs/worker.error.log