From ffae670be79a0488b394ac03413497eebb740f89 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 16 Jun 2022 17:54:21 +0530 Subject: [PATCH 1/3] fix: (re)Install every Frappe app even if not installed to env --- bench/bench.py | 32 ++++++++++++-------------------- bench/utils/bench.py | 3 +-- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/bench/bench.py b/bench/bench.py index 3585769c..03496ce0 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -155,10 +155,13 @@ class Bench(Base, Validator): def get_installed_apps(self) -> List: """Returns list of installed apps on bench, not in excluded_apps.txt """ - apps = [app for app in self.apps if app not in self.excluded_apps] - apps.remove("frappe") - apps.insert(0, "frappe") - return apps + try: + installed_packages = get_cmd_output(f"{self.python} -m pip freeze", cwd=self.name) + except Exception: + installed_packages = [] + is_installed = lambda app: app in installed_packages + + return [app for app in self.apps if app not in self.excluded_apps and is_installed(app)] class BenchApps(MutableSequence): @@ -262,23 +265,14 @@ class BenchApps(MutableSequence): ) def initialize_apps(self): - is_installed = lambda app: app in installed_packages - - try: - installed_packages = get_cmd_output(f"{self.bench.python} -m pip freeze", cwd=self.bench.name) - except Exception: - self.apps = [] - return - try: self.apps = [ x for x in os.listdir(os.path.join(self.bench.name, "apps")) - if ( - is_frappe_app(os.path.join(self.bench.name, "apps", x)) - and is_installed(x) - ) + if is_frappe_app(os.path.join(self.bench.name, "apps", x)) ] + self.apps.remove("frappe") + self.apps.insert(0, "frappe") except FileNotFoundError: self.apps = [] @@ -438,8 +432,7 @@ class BenchSetup(Base): """ from bench.app import App - if not apps: - apps = self.bench.get_installed_apps() + apps = apps or self.bench.apps self.pip() @@ -456,8 +449,7 @@ class BenchSetup(Base): """ import bench.cli - if not apps: - apps = self.bench.get_installed_apps() + apps = apps or self.bench.apps quiet_flag = "" if bench.cli.verbose else "--quiet" diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 8a695b7b..17fbab67 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -97,8 +97,7 @@ def update_yarn_packages(bench_path=".", apps=None): bench = Bench(bench_path) - if not apps: - apps = bench.get_installed_apps() + apps = apps or bench.apps apps_dir = os.path.join(bench.name, "apps") From 75957a56ee374fa7e3b9dd66c2c154f6d9def9af Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 16 Jun 2022 18:16:57 +0530 Subject: [PATCH 2/3] feat: Setup dev-dependencies defined via pyproject Since support for pyproject.toml exists, Frappe has gotten rid of requirements.txt file. However, dev-requirements.txt file still existed in Frappe & other apps. With this, we can get rid of the separate dev-reqs file as well and replace it by defining the deps in pyproject under [tool.bench.dev-dependencies] Example: For Frappe, this transition will look like moving the contents of dev-requirements.txt as follows: ``` \# dev-requirements.txt coverage==5.5 Faker~=13.12.1 pyngrok~=5.0.5 unittest-xml-reporting~=3.0.4 ``` ``` \# pyproject.toml [tool.bench.dev-dependencies] coverage = "==5.5" Faker = "~=13.12.1" pyngrok = "~=5.0.5" unittest-xml-reporting = "~=3.0.4" ``` Note: If dev-dependencies are defined in pyproject.toml, and a dev-dependencies.txt file exists - the txt file will be ignored. --- bench/utils/bench.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 17fbab67..51d52ddb 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -84,14 +84,38 @@ def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False): apps = bench.get_installed_apps() for app in apps: + pyproject_deps = None app_path = os.path.join(bench_path, "apps", app) - + pyproject_path = os.path.join(app_path, "pyproject.toml") dev_requirements_path = os.path.join(app_path, "dev-requirements.txt") - if os.path.exists(dev_requirements_path): + if os.path.exists(pyproject_path): + pyproject_deps = _generate_dev_deps_pattern(pyproject_path) + if pyproject_deps: + bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade {pyproject_deps}") + + if not pyproject_deps and os.path.exists(dev_requirements_path): bench.run(f"{bench.python} -m pip install {quiet_flag} --upgrade -r {dev_requirements_path}") +def _generate_dev_deps_pattern(pyproject_path): + try: + from tomli import loads + except ImportError: + from tomllib import loads + + requirements_pattern = "" + pyroject_config = loads(open(pyproject_path).read()) + + try: + for pkg, version in pyroject_config['tool']['bench']['dev-dependencies'].items(): + op = "=" if "=" not in version else "" + requirements_pattern += f"{pkg}{op}{version} " + except KeyError: + pass + return requirements_pattern + + def update_yarn_packages(bench_path=".", apps=None): from bench.bench import Bench From 45267fc8979fe9bb7819a770df97482d87732577 Mon Sep 17 00:00:00 2001 From: Aradhya Tripathi <67282231+Aradhya-Tripathi@users.noreply.github.com> Date: Thu, 23 Jun 2022 00:10:41 +0530 Subject: [PATCH 3/3] fix: fixed update_app_states call (#1326) --- bench/app.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bench/app.py b/bench/app.py index 1dd0b8aa..ed006427 100755 --- a/bench/app.py +++ b/bench/app.py @@ -158,7 +158,15 @@ class AppMeta: @functools.lru_cache(maxsize=None) class App(AppMeta): - def __init__(self, name: str, branch: str = None, bench: "Bench" = None, soft_link : bool = False, *args, **kwargs): + def __init__( + self, + name: str, + branch: str = None, + bench: "Bench" = None, + soft_link: bool = False, + *args, + **kwargs, + ): self.bench = bench self.soft_link = soft_link self.required_by = None @@ -257,9 +265,14 @@ class App(AppMeta): def update_app_state(self): from bench.bench import Bench + bench = Bench(self.bench.name) - bench.apps.sync(app_dir=self.app_name, app_name=self.name, - branch=self.tag, required_list=self.local_resolution) + bench.apps.sync( + app_dir=self.app_name, + app_name=self.name, + branch=self.tag, + required=self.local_resolution, + )