2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-10 17:24:41 +00:00

fix: Initialize bench in get-app with --init-bench

This commit is contained in:
Gavin D'souza 2021-11-29 18:33:32 +05:30
parent 877e812fbb
commit a2ccc30bc3
5 changed files with 43 additions and 12 deletions

View File

@ -3,6 +3,7 @@ PROJECT_NAME = "frappe-bench"
FRAPPE_VERSION = None FRAPPE_VERSION = None
current_path = None current_path = None
updated_path = None updated_path = None
LOG_BUFFER = []
def set_frappe_version(bench_path="."): def set_frappe_version(bench_path="."):

View File

@ -15,6 +15,7 @@ import click
# imports - module imports # imports - module imports
import bench import bench
from bench.exceptions import NotInBenchDirectoryError
from bench.utils import ( from bench.utils import (
fetch_details_from_tag, fetch_details_from_tag,
get_available_folder_name, get_available_folder_name,
@ -271,6 +272,7 @@ def get_app(
skip_assets=False, skip_assets=False,
verbose=False, verbose=False,
overwrite=False, overwrite=False,
init_bench=False,
): ):
"""bench get-app clones a Frappe App from remote (GitHub or any other git server), """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 and installs it on the current bench. This also resolves dependencies based on the
@ -280,7 +282,8 @@ def get_app(
git_url parameter. git_url parameter.
""" """
from bench.bench import Bench from bench.bench import Bench
import bench as bench_cli import bench as _bench
import bench.cli as bench_cli
bench = Bench(bench_path) bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench) app = App(git_url, branch=branch, bench=bench)
@ -290,6 +293,12 @@ def get_app(
bench_setup = False bench_setup = False
if not is_bench_directory(bench_path): 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 from bench.utils.system import init
bench_path = get_available_folder_name(f"{app.repo}-bench", bench_path) bench_path = get_available_folder_name(f"{app.repo}-bench", bench_path)
@ -297,8 +306,9 @@ def get_app(
os.chdir(bench_path) os.chdir(bench_path)
bench_setup = True 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}", "message": f"Fetching App {repo_name}",
"prefix": click.style('', fg='bright_yellow'), "prefix": click.style('', fg='bright_yellow'),
"is_parent": True, "is_parent": True,

View File

@ -13,6 +13,7 @@ from bench.config.common_site_config import setup_config
from bench.utils import ( from bench.utils import (
paths_in_bench, paths_in_bench,
exec_cmd, exec_cmd,
is_bench_directory,
is_frappe_app, is_frappe_app,
get_cmd_output, get_cmd_output,
get_git_version, get_git_version,
@ -54,7 +55,7 @@ class Bench(Base, Validator):
def __init__(self, path): def __init__(self, path):
self.name = path self.name = path
self.cwd = os.path.abspath(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.setup = BenchSetup(self)
self.teardown = BenchTearDown(self) self.teardown = BenchTearDown(self)

View File

@ -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.command(
@click.argument('name', nargs=-1) # Dummy argument for backward compatibility ["get", "get-app"],
@click.argument('git-url') help="Clone an app from the internet or filesystem and set it up in your bench",
@click.option('--branch', default=None, help="branch to checkout") )
@click.option('--overwrite', is_flag=True, default=False) @click.argument("name", nargs=-1) # Dummy argument for backward compatibility
@click.option('--skip-assets', is_flag=True, default=False, help="Do not build assets") @click.argument("git-url")
def get_app(git_url, branch, name=None, overwrite=False, skip_assets=False): @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" "clone an app from the internet and set it up in your bench"
from bench.app import get_app 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') @click.command('new-app', help='Create a new Frappe application under apps folder')

View File

@ -26,3 +26,7 @@ class CannotUpdateReleaseBench(ValidationError):
class FeatureDoesNotExistError(CommandFailedError): class FeatureDoesNotExistError(CommandFailedError):
pass pass
class NotInBenchDirectoryError(Exception):
pass