Skip to content

Commit

Permalink
chore: debugging flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdeali099 committed May 3, 2024
1 parent 921957c commit d71f3c5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
9 changes: 9 additions & 0 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,9 @@ def install_app(
if resolution == UNSET_ARG:
resolution = []

# REMOVE : debug logs
click.secho("\n--- `install app` function Called ---\n",fg="yellow",bold=True)

bench = Bench(bench_path)
conf = bench.conf

Expand All @@ -898,6 +901,9 @@ def install_app(

app_path = os.path.realpath(os.path.join(bench_path, "apps", app))

# REMOVE : debug logs
click.secho(f"\n--- path : {app_path} ---\n",fg="yellow",bold=True)

bench.run(
f"{bench.python} -m pip install {quiet_flag} --upgrade -e {app_path} {cache_flag}"
)
Expand All @@ -911,6 +917,9 @@ def install_app(
yarn_install += " --verbose"
bench.run(yarn_install, cwd=app_path)

# REMOVE : debug logs
click.secho(f"\n--- before sync ---\n",fg="yellow",bold=True)

bench.apps.sync(app_name=app, required=resolution, branch=tag, app_dir=app_path)

if not skip_assets:
Expand Down
47 changes: 45 additions & 2 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import logging
from typing import List, MutableSequence, TYPE_CHECKING, Union

import click

# imports - module imports
import bench
from bench.exceptions import AppNotInstalledError, InvalidRemoteException
Expand Down Expand Up @@ -58,6 +60,8 @@ def validate_app_uninstall(self, app):
@lru_cache(maxsize=None)
class Bench(Base, Validator):
def __init__(self, path):
# REMOVE : debug logs
click.secho(f"\n--- Bench __init__ called ---\n",fg="blue",bold=True)
self.name = path
self.cwd = os.path.abspath(path)
self.exists = is_bench_directory(self.name)
Expand Down Expand Up @@ -155,11 +159,13 @@ def reload(self, web=False, supervisor=True, systemd=True, _raise=True):

def get_installed_apps(self) -> List:
"""Returns list of installed apps on bench, not in excluded_apps.txt"""
click.secho("\n--- `get_installed_apps` method Called ---\n",fg="yellow",bold=True)

try:
installed_packages = get_cmd_output(f"{self.python} -m pip freeze", cwd=self.name)
except Exception:
installed_packages = []

click.secho(f"\n--- `get_installed_apps` method Called installed_packages : {installed_packages} ---\n",fg="yellow",bold=True)
return [
app
for app in self.apps
Expand All @@ -169,16 +175,22 @@ def get_installed_apps(self) -> List:

class BenchApps(MutableSequence):
def __init__(self, bench: Bench):
# REMOVE : debug logs
click.secho(f"\n--- BenchApps __init__ called ---\n",fg="blue",bold=True)
self.bench = bench
self.states_path = os.path.join(self.bench.name, "sites", "apps.json")
self.apps_path = os.path.join(self.bench.name, "apps")
self.initialize_apps()
self.set_states()

def set_states(self):
# REMOVE : debug logs
click.secho(f"\n--- set_states method called ---\n",fg="yellow",bold=True)
try:
with open(self.states_path) as f:
self.states = json.loads(f.read() or "{}")
click.secho(f"\n--- self.states : {self.states} ---\n",fg="green",bold=True)

except FileNotFoundError:
self.states = {}

Expand All @@ -191,13 +203,23 @@ def update_apps_states(
):
if required == UNSET_ARG:
required = []

# REMOVE : debug logs
click.secho(f"\n--- update_apps_states method called ---\n",fg="yellow",bold=True)
click.secho(f"\n--- self.apps : {self.apps} ---\n",fg="green",bold=True)
click.secho(f"\n--- self.states_path : {self.states_path} ---\n",fg="green",bold=True)
click.secho(f"\n--- exist? : {os.path.exists(self.states_path)} ---\n",fg="green",bold=True)


if self.apps and not os.path.exists(self.states_path):
click.secho(f"\n--- I am in if ? : True ---\n",fg="blue",bold=True)

# idx according to apps listed in apps.txt (backwards compatibility)
# Keeping frappe as the first app.
if "frappe" in self.apps:
self.apps.remove("frappe")
self.apps.insert(0, "frappe")
with open(self.bench.apps_txt, "w") as f:
with open(self.bench.apps_txt, "w") as f: #NOTE : here changes in apps.txt
f.write("\n".join(self.apps))

print("Found existing apps updating states...")
Expand All @@ -210,6 +232,10 @@ def update_apps_states(
}

apps_to_remove = []
#REMOVE
click.secho(f"\n--- self.states? : {self.states} ---\n",fg="green",bold=True)
click.secho(f"\n--- self.apps? : {self.apps} ---\n",fg="green",bold=True)
# FIXME : can make this code more efficient
for app in self.states:
if app not in self.apps:
apps_to_remove.append(app)
Expand All @@ -221,6 +247,8 @@ def update_apps_states(
app_dir = app_name

if app_name and app_name not in self.states:
click.secho(f"\n--- update_apps_state_condition ---\n",fg="yellow",bold=True)

version = get_current_version(app_name, self.bench.name)

app_dir = os.path.join(self.apps_path, app_dir)
Expand Down Expand Up @@ -254,17 +282,28 @@ def update_apps_states(
with open(self.states_path, "w") as f:
f.write(json.dumps(self.states, indent=4))

#REMOVE
click.secho(f"\n--- update_apps_state() completed ---\n",fg="blue",bold=True)

def sync(
self,
app_name: Union[str, None] = None,
app_dir: Union[str, None] = None,
branch: Union[str, None] = None,
required: List = UNSET_ARG,
):
# REMOVE : debug logs
click.secho(f"\n--- sync method called ---\n",fg="yellow",bold=True)
click.secho(f"\n--- app_name : {app_name} ---\n",fg="green",bold=True)
click.secho(f"\n--- app_dir : {app_dir} ---\n",fg="green",bold=True)
click.secho(f"\n--- branch : {branch} ---\n",fg="green",bold=True)
click.secho(f"\n--- required : {required} ---\n",fg="green",bold=True)

if required == UNSET_ARG:
required = []
self.initialize_apps()

# FIXME: here is problem if new-app is created then that app details not stored in apps.txt
with open(self.bench.apps_txt, "w") as f:
f.write("\n".join(self.apps))

Expand Down Expand Up @@ -333,6 +372,8 @@ def __str__(self):

class BenchSetup(Base):
def __init__(self, bench: Bench):
# REMOVE : debug logs
click.secho(f"\n--- BenchSetup __init__ called ---\n",fg="blue",bold=True)
self.bench = bench
self.cwd = self.bench.cwd

Expand Down Expand Up @@ -492,6 +533,8 @@ def node(self, apps=None):

class BenchTearDown:
def __init__(self, bench):
# REMOVE : debug logs
click.secho(f"\n--- BenchTearDown __init__ called ---\n",fg="blue",bold=True)
self.bench = bench

def backups(self):
Expand Down
8 changes: 8 additions & 0 deletions bench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def execute_cmd(check_for_update=True, command: str = None, logger: Logger = Non


def cli():
click.secho("\n--- `cli` function Called : cli in bench>cli ---\n",fg="blue",bold=True)

setup_clear_cache()
global from_command_line, bench_config, is_envvar_warn_set, verbose

Expand Down Expand Up @@ -126,6 +128,10 @@ def cli():
# handle usages like `--use-feature='feat-x'` and `--use-feature 'feat-x'`
if cmd_from_sys and cmd_from_sys.split("=", 1)[0].strip() in opts:
bench_command()

click.secho("\n--- `I am before error generation` ---\n",fg="blue",bold=True)
click.secho(f"\n--- `cmd_from_sys` : {cmd_from_sys}---\n",fg="green",bold=True)
click.secho(f"\n--- `bench_command.commands` : {bench_command.commands}---\n",fg="green",bold=True)

if cmd_from_sys in bench_command.commands:
with execute_cmd(check_for_update=is_cli_command, command=command, logger=logger):
Expand Down Expand Up @@ -232,6 +238,8 @@ def change_working_directory():


def setup_clear_cache():
click.secho("\n--- `setup_clear_cache` function Called : cli in bench>cli ---\n",fg="blue",bold=True)

from copy import copy

f = copy(os.chdir)
Expand Down
7 changes: 7 additions & 0 deletions bench/commands/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,17 @@ def get_app(
)
@click.argument("app-name")
def new_app(app_name, no_git=None):
click.secho("\n--- `new_app` function Called before import ---\n",fg="yellow",bold=True)

from bench.app import new_app
# REMOVE : debug logs
click.secho("\n--- `new_app` function Called after import ---\n",fg="yellow",bold=True)

new_app(app_name, no_git)

click.secho("\n--- `new_app` function ENDS ---\n",fg="yellow",bold=True)



@click.command(
["remove", "rm", "remove-app"],
Expand Down
7 changes: 7 additions & 0 deletions bench/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,14 @@ def setup_requirements(node=False, python=False, dev=False, apps=None):
"""
from bench.bench import Bench

# REMOVE : debug logs
click.secho("\n--- `setup requirements` Command Called ---\n",fg="yellow",bold=True)

bench = Bench(".")

click.secho("\n--- `setup requirements` Command Called : After Bench() ---\n",fg="yellow",bold=True)


if not (node or python or dev):
bench.setup.requirements(apps=apps)

Expand All @@ -237,6 +243,7 @@ def setup_requirements(node=False, python=False, dev=False, apps=None):

else:
from bench.utils.bench import install_python_dev_dependencies
click.secho("\n--- `setup requirements` Command Called : else condition for dev_dependency ---\n",fg="yellow",bold=True)

install_python_dev_dependencies(apps=apps)

Expand Down
11 changes: 11 additions & 0 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def update_node_packages(bench_path=".", apps=None, verbose=None):


def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False):
# REMOVE : debug logs
click.secho("\n--- `install_python_dev_dependencies` method Called ---\n",fg="blue",bold=True)

import bench.cli
from bench.bench import Bench

Expand All @@ -85,11 +88,18 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False):

bench = Bench(bench_path)

click.secho("\n--- `install_python_dev_dependencies` method Called after : Bench() ---\n",fg="yellow",bold=True)
click.secho(f"\n--- `install_python_dev_dependencies` method Called Apps : {app} ---\n",fg="green",bold=True)


if isinstance(apps, str):
apps = [apps]
elif not apps:
apps = bench.get_installed_apps()

click.secho(f"\n--- `install_python_dev_dependencies` method Called Apps after : {app} ---\n",fg="green",bold=True)


for app in apps:
pyproject_deps = None
app_path = os.path.join(bench_path, "apps", app)
Expand Down Expand Up @@ -369,6 +379,7 @@ def restart_process_manager(bench_path=".", web_workers=False):


def build_assets(bench_path=".", app=None, using_cached=False):

command = "bench build"
if app:
command += f" --app {app}"
Expand Down

0 comments on commit d71f3c5

Please sign in to comment.