mirror of
https://github.com/frappe/bench.git
synced 2025-01-24 07:28:25 +00:00
refactor: Bench verbosity
It's off by default. If you want it enabled, pass --verbose or -v following `bench`. The verbosity only changes how pip installs work. Other stuff is immaterial at this point. Eg: bench -v setup requirements
This commit is contained in:
parent
6081690d7b
commit
1b2bb87ab7
16
bench/app.py
16
bench/app.py
@ -165,9 +165,11 @@ 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=True):
|
||||
def install(self, skip_assets=False, verbose=False):
|
||||
import bench.cli
|
||||
from bench.utils.app import get_app_name
|
||||
|
||||
verbose = bench.cli.verbose or verbose
|
||||
app_name = get_app_name(self.bench.name, self.repo)
|
||||
|
||||
# TODO: this should go inside install_app only tho - issue: default/resolved branch
|
||||
@ -240,12 +242,14 @@ def remove_from_excluded_apps_txt(app, bench_path="."):
|
||||
return write_excluded_apps_txt(apps, bench_path=bench_path)
|
||||
|
||||
|
||||
def setup_app_dependencies(repo_name, bench_path=".", branch=None, verbose=True):
|
||||
def setup_app_dependencies(repo_name, bench_path=".", branch=None, verbose=False):
|
||||
# branch kwarg is somewhat of a hack here; since we're assuming the same branches for all apps
|
||||
# for eg: if you're installing erpnext@develop, you'll want frappe@develop and healthcare@develop too
|
||||
import glob
|
||||
import bench.cli
|
||||
from bench.bench import Bench
|
||||
|
||||
verbose = bench.cli.verbose or verbose
|
||||
apps_path = os.path.join(os.path.abspath(bench_path), "apps")
|
||||
files = glob.glob(os.path.join(apps_path, repo_name, "**", "hooks.py"))
|
||||
|
||||
@ -346,6 +350,7 @@ def install_app(
|
||||
restart_bench=True,
|
||||
skip_assets=False,
|
||||
):
|
||||
import bench.cli as bench_cli
|
||||
from bench.bench import Bench
|
||||
|
||||
install_text = f"Installing {app}"
|
||||
@ -354,14 +359,17 @@ def install_app(
|
||||
|
||||
bench = Bench(bench_path)
|
||||
conf = bench.conf
|
||||
|
||||
verbose = bench_cli.verbose or verbose
|
||||
quiet_flag = "" if verbose else "--quiet"
|
||||
app_path = os.path.realpath(os.path.join(bench_path, "apps", app))
|
||||
cache_flag = "--no-cache-dir" if no_cache else ""
|
||||
|
||||
app_path = os.path.realpath(os.path.join(bench_path, "apps", app))
|
||||
|
||||
bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade -e {app_path} {cache_flag}")
|
||||
|
||||
if conf.get("developer_mode"):
|
||||
install_python_dev_dependencies(apps=app)
|
||||
install_python_dev_dependencies(apps=app, bench_path=bench_path, verbose=verbose)
|
||||
|
||||
if os.path.exists(os.path.join(app_path, "package.json")):
|
||||
bench.run("yarn install", cwd=app_path)
|
||||
|
@ -16,6 +16,7 @@ from bench.utils import (
|
||||
is_frappe_app,
|
||||
get_cmd_output,
|
||||
get_git_version,
|
||||
log,
|
||||
run_frappe_cmd,
|
||||
)
|
||||
from bench.utils.bench import (
|
||||
@ -233,16 +234,19 @@ class BenchSetup(Base):
|
||||
- upgrade env pip
|
||||
- install frappe python dependencies
|
||||
"""
|
||||
import bench.cli
|
||||
|
||||
frappe = os.path.join(self.bench.name, "apps", "frappe")
|
||||
virtualenv = get_venv_path()
|
||||
quiet_flag = "" if bench.cli.verbose else "--quiet"
|
||||
|
||||
if not os.path.exists(self.bench.python):
|
||||
self.run(f"{virtualenv} env -p {python}")
|
||||
self.run(f"{virtualenv} {quiet_flag} env -p {python}")
|
||||
|
||||
self.pip()
|
||||
|
||||
if os.path.exists(frappe):
|
||||
self.run(f"{self.bench.python} -m pip install --upgrade -e {frappe}")
|
||||
self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade -e {frappe}")
|
||||
|
||||
@step(title="Setting Up Bench Config", success="Bench Config Set Up")
|
||||
def config(self, redis=True, procfile=True):
|
||||
@ -262,10 +266,16 @@ class BenchSetup(Base):
|
||||
|
||||
setup_procfile(self.bench.name, skip_redis=not redis)
|
||||
|
||||
def pip(self):
|
||||
@step(title="Updating pip", success="Updated pip")
|
||||
def pip(self, verbose=False):
|
||||
"""Updates env pip; assumes that env is setup
|
||||
"""
|
||||
return self.run(f"{self.bench.python} -m pip install --upgrade pip")
|
||||
import bench.cli
|
||||
|
||||
verbose = bench.cli.verbose or verbose
|
||||
quiet_flag = "" if verbose else "--quiet"
|
||||
|
||||
return self.run(f"{self.bench.python} -m pip install {quiet_flag} --upgrade pip")
|
||||
|
||||
def logging(self):
|
||||
from bench.utils import setup_logging
|
||||
@ -302,10 +312,50 @@ 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
|
||||
|
||||
@step(title="Setting Up Bench Dependencies", success="Bench Dependencies Set Up")
|
||||
def requirements(self):
|
||||
from bench.utils.bench import update_requirements
|
||||
update_requirements(bench=self.bench)
|
||||
"""Install and upgrade all installed apps on given Bench
|
||||
"""
|
||||
from bench.app import App
|
||||
|
||||
apps = self.__get_installed_apps()
|
||||
|
||||
self.pip()
|
||||
|
||||
print(f"Installing {len(apps)} applications...")
|
||||
for app in apps:
|
||||
App(app, bench=self.bench, to_clone=False).install()
|
||||
|
||||
def python(self):
|
||||
"""Install and upgrade Python dependencies for installed apps on given Bench
|
||||
"""
|
||||
import bench.cli
|
||||
|
||||
apps = self.__get_installed_apps()
|
||||
|
||||
quiet_flag = "" if bench.cli.verbose else "--quiet"
|
||||
|
||||
self.pip()
|
||||
|
||||
for app in apps:
|
||||
app_path = os.path.join(self.bench.name, "apps", app)
|
||||
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
|
||||
"""
|
||||
from bench.utils.bench import update_node_packages
|
||||
|
||||
return update_node_packages(bench_path=self.bench.name)
|
||||
|
||||
|
||||
class BenchTearDown:
|
||||
|
@ -30,6 +30,7 @@ from bench.utils.bench import get_env_cmd
|
||||
|
||||
# these variables are used to show dynamic outputs on the terminal
|
||||
dynamic_feed = False
|
||||
verbose = False
|
||||
bench.LOG_BUFFER = []
|
||||
|
||||
# set when commands are executed via the CLI
|
||||
@ -88,7 +89,7 @@ def cli():
|
||||
print(get_frappe_help())
|
||||
return
|
||||
|
||||
if sys.argv[1] in ["--site", "--verbose", "--force", "--profile"]:
|
||||
if sys.argv[1] in ["--site", "--force", "--profile"]:
|
||||
frappe_cmd()
|
||||
|
||||
if sys.argv[1] in get_cached_frappe_commands():
|
||||
|
@ -6,6 +6,7 @@ from bench.utils.cli import (
|
||||
MultiCommandGroup,
|
||||
print_bench_version,
|
||||
use_experimental_feature,
|
||||
setup_verbosity,
|
||||
)
|
||||
|
||||
|
||||
@ -18,7 +19,10 @@ from bench.utils.cli import (
|
||||
expose_value=False,
|
||||
)
|
||||
@click.option(
|
||||
"--use-feature", is_eager=True, callback=use_experimental_feature, expose_value=False
|
||||
"--use-feature", is_eager=True, callback=use_experimental_feature, expose_value=False,
|
||||
)
|
||||
@click.option(
|
||||
"-v", "--verbose", is_flag=True, callback=setup_verbosity, expose_value=False,
|
||||
)
|
||||
def bench_command(bench_path="."):
|
||||
import bench
|
||||
|
@ -136,17 +136,18 @@ def setup_socketio():
|
||||
@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):
|
||||
from bench.bench import Bench
|
||||
|
||||
bench = Bench(".")
|
||||
|
||||
if not (node or python or dev):
|
||||
from bench.utils.bench import update_requirements
|
||||
update_requirements()
|
||||
bench.setup.requirements()
|
||||
|
||||
elif not node and not dev:
|
||||
from bench.utils.bench import update_python_packages
|
||||
update_python_packages()
|
||||
bench.setup.python()
|
||||
|
||||
elif not python and not dev:
|
||||
from bench.utils.bench import update_node_packages
|
||||
update_node_packages()
|
||||
bench.setup.node()
|
||||
|
||||
else:
|
||||
from bench.utils.bench import install_python_dev_dependencies
|
||||
|
@ -63,7 +63,7 @@ def log(message, level=0, no_log=False):
|
||||
|
||||
if bench.cli.from_command_line and bench.cli.dynamic_feed:
|
||||
bench.LOG_BUFFER.append(
|
||||
{"prefix": prefix, "message": message, "color": color,}
|
||||
{"prefix": prefix, "message": message, "color": color}
|
||||
)
|
||||
|
||||
if no_log:
|
||||
|
@ -30,10 +30,10 @@ def is_version_upgrade(app="frappe", bench_path=".", branch=None):
|
||||
|
||||
def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrade=True):
|
||||
import git
|
||||
from bench.bench import Bench
|
||||
from bench.utils import log, exec_cmd
|
||||
from bench.utils.bench import (
|
||||
build_assets,
|
||||
update_requirements,
|
||||
patch_sites,
|
||||
post_upgrade,
|
||||
)
|
||||
@ -47,8 +47,6 @@ def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrad
|
||||
apps = [
|
||||
name for name in os.listdir(apps_dir) if os.path.isdir(os.path.join(apps_dir, name))
|
||||
]
|
||||
if branch == "v4.x.x":
|
||||
apps.append("shopping_cart")
|
||||
|
||||
for app in apps:
|
||||
app_dir = os.path.join(apps_dir, app)
|
||||
@ -93,7 +91,7 @@ def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrad
|
||||
)
|
||||
|
||||
if version_upgrade[0] and upgrade:
|
||||
update_requirements()
|
||||
Bench(bench_path).setup.requirements()
|
||||
backup_all_sites()
|
||||
patch_sites()
|
||||
build_assets()
|
||||
|
@ -48,49 +48,6 @@ def get_venv_path():
|
||||
return venv or log("virtualenv cannot be found", level=2)
|
||||
|
||||
|
||||
def update_env_pip(bench_path):
|
||||
env_py = get_env_cmd("python", bench_path=bench_path)
|
||||
exec_cmd(f"{env_py} -m pip install -q -U pip")
|
||||
|
||||
|
||||
def update_requirements(bench: "Bench" = None, bench_path="."):
|
||||
from bench.app import install_app
|
||||
|
||||
if not bench:
|
||||
from bench.bench import Bench
|
||||
|
||||
bench = Bench(bench_path)
|
||||
|
||||
apps = [app for app in bench.apps if app not in bench.excluded_apps]
|
||||
apps.remove("frappe")
|
||||
apps.insert(0, "frappe")
|
||||
|
||||
print("Updating env pip...")
|
||||
update_env_pip(bench.name)
|
||||
|
||||
print(f"Installing {len(apps)} applications...")
|
||||
for app in apps:
|
||||
install_app(app, bench_path=bench.name, skip_assets=True, restart_bench=False)
|
||||
|
||||
|
||||
def update_python_packages(bench_path="."):
|
||||
from bench.bench import Bench
|
||||
|
||||
bench = Bench(bench_path)
|
||||
|
||||
apps = [app for app in bench.apps if app not in bench.excluded_apps]
|
||||
apps.remove("frappe")
|
||||
apps.insert(0, "frappe")
|
||||
|
||||
print("Updating Python libraries...")
|
||||
bench.setup.pip()
|
||||
|
||||
for app in apps:
|
||||
app_path = os.path.join(bench_path, "apps", app)
|
||||
click.secho(f"\nInstalling python dependencies for {app}", fg="yellow")
|
||||
bench.run(f"{bench.python} -m pip install --upgrade -e {app_path}")
|
||||
|
||||
|
||||
def update_node_packages(bench_path="."):
|
||||
print("Updating node packages...")
|
||||
from bench.utils.app import get_develop_version
|
||||
@ -106,9 +63,13 @@ def update_node_packages(bench_path="."):
|
||||
update_yarn_packages(bench_path)
|
||||
|
||||
|
||||
def install_python_dev_dependencies(bench_path=".", apps=None):
|
||||
def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False):
|
||||
import bench.cli
|
||||
from bench.bench import Bench
|
||||
|
||||
verbose = bench.cli.verbose or verbose
|
||||
quiet_flag = "" if verbose else "--quiet"
|
||||
|
||||
bench = Bench(bench_path)
|
||||
|
||||
if isinstance(apps, str):
|
||||
@ -118,10 +79,11 @@ def install_python_dev_dependencies(bench_path=".", apps=None):
|
||||
|
||||
for app in apps:
|
||||
app_path = os.path.join(bench_path, "apps", app)
|
||||
|
||||
dev_requirements_path = os.path.join(app_path, "dev-requirements.txt")
|
||||
|
||||
if os.path.exists(dev_requirements_path):
|
||||
bench.run(f"{bench.python} -m pip install -r {dev_requirements_path}")
|
||||
bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade -r {dev_requirements_path}")
|
||||
|
||||
|
||||
def update_yarn_packages(bench_path="."):
|
||||
|
@ -39,6 +39,15 @@ def use_experimental_feature(ctx, param, value):
|
||||
if value == "dynamic-feed":
|
||||
import bench.cli
|
||||
bench.cli.dynamic_feed = True
|
||||
bench.cli.verbose = True
|
||||
else:
|
||||
from bench.exceptions import FeatureDoesNotExistError
|
||||
raise FeatureDoesNotExistError(f"Feature {value} does not exist")
|
||||
|
||||
|
||||
def setup_verbosity(ctx, param, value):
|
||||
if not value:
|
||||
return
|
||||
|
||||
import bench.cli
|
||||
bench.cli.verbose = True
|
||||
|
@ -50,9 +50,12 @@ def init(
|
||||
# Use print("\033c", end="") to clear entire screen after each step and re-render each list
|
||||
# another way => https://stackoverflow.com/a/44591228/10309266
|
||||
|
||||
import bench.cli
|
||||
from bench.app import get_app, install_apps_from_path
|
||||
from bench.bench import Bench
|
||||
|
||||
verbose = bench.cli.verbose or verbose
|
||||
|
||||
bench = Bench(path)
|
||||
|
||||
bench.setup.dirs()
|
||||
|
Loading…
x
Reference in New Issue
Block a user