Skip to content

Commit

Permalink
fix: Initialize bench in get-app with --init-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed Nov 29, 2021
1 parent 877e812 commit a2ccc30
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions bench/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
FRAPPE_VERSION = None
current_path = None
updated_path = None
LOG_BUFFER = []


def set_frappe_version(bench_path="."):
Expand Down
16 changes: 13 additions & 3 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# imports - module imports
import bench
from bench.exceptions import NotInBenchDirectoryError
from bench.utils import (
fetch_details_from_tag,
get_available_folder_name,
Expand Down Expand Up @@ -271,6 +272,7 @@ def get_app(
skip_assets=False,
verbose=False,
overwrite=False,
init_bench=False,
):
"""bench get-app clones a Frappe App from remote (GitHub or any other git server),
and installs it on the current bench. This also resolves dependencies based on the
Expand All @@ -280,7 +282,8 @@ def get_app(
git_url parameter.
"""
from bench.bench import Bench
import bench as bench_cli
import bench as _bench
import bench.cli as bench_cli

bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench)
Expand All @@ -290,15 +293,22 @@ def get_app(
bench_setup = False

if not is_bench_directory(bench_path):
if not init_bench:
raise NotInBenchDirectoryError(
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."
)

from bench.utils.system import init

bench_path = get_available_folder_name(f"{app.repo}-bench", bench_path)
init(path=bench_path, frappe_branch=branch)
os.chdir(bench_path)
bench_setup = True

if bench_setup and bench_cli.cli.from_command_line and bench_cli.cli.dynamic_feed:
bench_cli.LOG_BUFFER.append({

if bench_setup and bench_cli.from_command_line and bench_cli.dynamic_feed:
_bench.LOG_BUFFER.append({
"message": f"Fetching App {repo_name}",
"prefix": click.style('⏼', fg='bright_yellow'),
"is_parent": True,
Expand Down
3 changes: 2 additions & 1 deletion bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from bench.utils import (
paths_in_bench,
exec_cmd,
is_bench_directory,
is_frappe_app,
get_cmd_output,
get_git_version,
Expand Down Expand Up @@ -54,7 +55,7 @@ class Bench(Base, Validator):
def __init__(self, path):
self.name = path
self.cwd = os.path.abspath(path)
self.exists = os.path.exists(self.name)
self.exists = is_bench_directory(self.name)

self.setup = BenchSetup(self)
self.teardown = BenchTearDown(self)
Expand Down
31 changes: 23 additions & 8 deletions bench/commands/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,31 @@ def drop(path):



@click.command(['get', 'get-app'], help='Clone an app from the internet or filesystem and set it up in your bench')
@click.argument('name', nargs=-1) # Dummy argument for backward compatibility
@click.argument('git-url')
@click.option('--branch', default=None, help="branch to checkout")
@click.option('--overwrite', is_flag=True, default=False)
@click.option('--skip-assets', is_flag=True, default=False, help="Do not build assets")
def get_app(git_url, branch, name=None, overwrite=False, skip_assets=False):
@click.command(
["get", "get-app"],
help="Clone an app from the internet or filesystem and set it up in your bench",
)
@click.argument("name", nargs=-1) # Dummy argument for backward compatibility
@click.argument("git-url")
@click.option("--branch", default=None, help="branch to checkout")
@click.option("--overwrite", is_flag=True, default=False)
@click.option("--skip-assets", is_flag=True, default=False, help="Do not build assets")
@click.option(
"--init-bench", is_flag=True, default=False, help="Initialize Bench if not in one"
)
def get_app(
git_url, branch, name=None, overwrite=False, skip_assets=False, init_bench=False
):
"clone an app from the internet and set it up in your bench"
from bench.app import get_app
get_app(git_url, branch=branch, skip_assets=skip_assets, overwrite=overwrite)

get_app(
git_url,
branch=branch,
skip_assets=skip_assets,
overwrite=overwrite,
init_bench=init_bench,
)


@click.command('new-app', help='Create a new Frappe application under apps folder')
Expand Down
4 changes: 4 additions & 0 deletions bench/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ class CannotUpdateReleaseBench(ValidationError):

class FeatureDoesNotExistError(CommandFailedError):
pass


class NotInBenchDirectoryError(Exception):
pass

0 comments on commit a2ccc30

Please sign in to comment.