Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/staging' into v5.x
Browse files Browse the repository at this point in the history
* upstream/staging:
  feat: add more flexibility to procfile render
  fix: apps init; apps might be an empty folder still
  chore(ci): drop py3.8, add 11, 12, 13
  refactor: change some exceptions to simple echo + exits
  fix: use `with` to read pyproject.toml
  Avoid continue loop

Signed-off-by: Akhil Narang <[email protected]>
  • Loading branch information
akhilnarang committed Nov 28, 2024
2 parents 67ee01b + 796b813 commit 96cc3fe
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})

Expand Down
13 changes: 8 additions & 5 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

# imports - module imports
import bench
from bench.exceptions import NotInBenchDirectoryError
from bench.utils import (
UNSET_ARG,
fetch_details_from_tag,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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("-", "_")
Expand Down
2 changes: 1 addition & 1 deletion bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def initialize_apps(self):
]
self.apps.remove("frappe")
self.apps.insert(0, "frappe")
except FileNotFoundError:
except (FileNotFoundError, ValueError):
self.apps = []

def __getitem__(self, key):
Expand Down
13 changes: 9 additions & 4 deletions bench/config/procfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
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")

Expand All @@ -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,
)
Expand Down
13 changes: 8 additions & 5 deletions bench/config/templates/Procfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions bench/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@ class CannotUpdateReleaseBench(ValidationError):
class FeatureDoesNotExistError(CommandFailedError):
pass


class NotInBenchDirectoryError(Exception):
pass


class VersionNotFound(Exception):
pass
3 changes: 3 additions & 0 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 96cc3fe

Please sign in to comment.