mirror of
https://github.com/frappe/bench.git
synced 2025-01-09 08:30:39 +00:00
fix: check frappe-deps during get-app
This commit is contained in:
parent
9988b8356b
commit
d93656e8d9
86
bench/app.py
86
bench/app.py
@ -18,6 +18,7 @@ from urllib.parse import urlparse
|
|||||||
# imports - third party imports
|
# imports - third party imports
|
||||||
import click
|
import click
|
||||||
import git
|
import git
|
||||||
|
import semantic_version as sv
|
||||||
|
|
||||||
# imports - module imports
|
# imports - module imports
|
||||||
import bench
|
import bench
|
||||||
@ -180,6 +181,7 @@ class App(AppMeta):
|
|||||||
self.required_by = None
|
self.required_by = None
|
||||||
self.local_resolution = []
|
self.local_resolution = []
|
||||||
self.cache_key = cache_key
|
self.cache_key = cache_key
|
||||||
|
self.pyproject = None
|
||||||
super().__init__(name, branch, *args, **kwargs)
|
super().__init__(name, branch, *args, **kwargs)
|
||||||
|
|
||||||
@step(title="Fetching App {repo}", success="App {repo} Fetched")
|
@step(title="Fetching App {repo}", success="App {repo} Fetched")
|
||||||
@ -239,6 +241,8 @@ class App(AppMeta):
|
|||||||
import bench.cli
|
import bench.cli
|
||||||
from bench.utils.app import get_app_name
|
from bench.utils.app import get_app_name
|
||||||
|
|
||||||
|
self.validate_app_dependencies()
|
||||||
|
|
||||||
verbose = bench.cli.verbose or verbose
|
verbose = bench.cli.verbose or verbose
|
||||||
app_name = get_app_name(self.bench.name, self.app_name)
|
app_name = get_app_name(self.bench.name, self.app_name)
|
||||||
if not resolved and self.app_name != "frappe" and not ignore_resolution:
|
if not resolved and self.app_name != "frappe" and not ignore_resolution:
|
||||||
@ -293,6 +297,28 @@ class App(AppMeta):
|
|||||||
required=self.local_resolution,
|
required=self.local_resolution,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_pyproject(self) -> Optional[dict]:
|
||||||
|
from bench.utils.app import get_pyproject
|
||||||
|
|
||||||
|
if self.pyproject:
|
||||||
|
return self.pyproject
|
||||||
|
|
||||||
|
apps_path = os.path.join(os.path.abspath(self.bench.name), "apps")
|
||||||
|
pyproject_path = os.path.join(apps_path, self.app_name, "pyproject.toml")
|
||||||
|
self.pyproject = get_pyproject(pyproject_path)
|
||||||
|
return self.pyproject
|
||||||
|
|
||||||
|
def validate_app_dependencies(self) -> None:
|
||||||
|
pyproject = self.get_pyproject() or {}
|
||||||
|
deps: Optional[dict] = (
|
||||||
|
pyproject.get("tool", {}).get("bench", {}).get("frappe-dependencies")
|
||||||
|
)
|
||||||
|
if not deps:
|
||||||
|
return
|
||||||
|
|
||||||
|
for dep, version in deps.items():
|
||||||
|
validate_dependency(self, dep, version)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Get App Cache
|
Get App Cache
|
||||||
|
|
||||||
@ -396,8 +422,6 @@ def can_frappe_use_cached(app: App) -> bool:
|
|||||||
if not min_frappe:
|
if not min_frappe:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
import semantic_version as sv
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return sv.Version(min_frappe) in sv.SimpleSpec(">=15.12.0")
|
return sv.Version(min_frappe) in sv.SimpleSpec(">=15.12.0")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -414,19 +438,63 @@ def can_frappe_use_cached(app: App) -> bool:
|
|||||||
"""
|
"""
|
||||||
return sv.Version("15.12.0") not in sv.SimpleSpec(min_frappe)
|
return sv.Version("15.12.0") not in sv.SimpleSpec(min_frappe)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
click.secho(
|
click.secho(f"Invalid value found for frappe version '{min_frappe}'", fg="yellow")
|
||||||
f"Invalid value found for frappe version '{min_frappe}'",
|
|
||||||
fg="yellow"
|
|
||||||
)
|
|
||||||
# Invalid expression
|
# Invalid expression
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_required_frappe_version(app: App) -> Optional[str]:
|
def validate_dependency(app: App, dep: str, req_version: str) -> None:
|
||||||
|
dep_path = Path(app.bench.name) / "apps" / dep
|
||||||
|
if not dep_path.is_dir():
|
||||||
|
click.secho(
|
||||||
|
f"Required frappe-dependency '{dep}' not found. "
|
||||||
|
f"Aborting '{app.name}' installation. "
|
||||||
|
f"Please install '{dep}' first and retry",
|
||||||
|
fg="red",
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
dep_version = get_dep_version(dep, dep_path)
|
||||||
|
if not dep_version:
|
||||||
|
return
|
||||||
|
|
||||||
|
if sv.Version(dep_version) not in sv.SimpleSpec(req_version):
|
||||||
|
click.secho(
|
||||||
|
f"Installed frappe-dependency '{dep}' version '{dep_version}' "
|
||||||
|
f"does not satisfy required version '{req_version}'. "
|
||||||
|
f"App '{app.name}' might not work as expected",
|
||||||
|
fg="yellow",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_dep_version(dep: str, dep_path: Path) -> Optional[str]:
|
||||||
from bench.utils.app import get_pyproject
|
from bench.utils.app import get_pyproject
|
||||||
|
|
||||||
apps_path = os.path.join(os.path.abspath(app.bench.name), "apps")
|
dep_pp = get_pyproject(str(dep_path / "pyproject.toml"))
|
||||||
pyproject = get_pyproject(apps_path, app.app_name)
|
version = dep_pp.get("project", {}).get("version")
|
||||||
|
if version:
|
||||||
|
return version
|
||||||
|
|
||||||
|
dinit_path = dep_path / dep / "__init__.py"
|
||||||
|
if not dinit_path.is_file():
|
||||||
|
return None
|
||||||
|
|
||||||
|
with dinit_path.open("r", encoding="utf-8") as dinit:
|
||||||
|
for line in dinit:
|
||||||
|
if not line.startswith("__version__ =") and not line.startswith("VERSION ="):
|
||||||
|
continue
|
||||||
|
|
||||||
|
version = line.split("=")[1].strip().strip("\"'")
|
||||||
|
if version:
|
||||||
|
return version
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_required_frappe_version(app: App) -> Optional[str]:
|
||||||
|
pyproject = app.get_pyproject() or {}
|
||||||
|
|
||||||
# Reference: https://github.com/frappe/bench/issues/1524
|
# Reference: https://github.com/frappe/bench/issues/1524
|
||||||
req_frappe = (
|
req_frappe = (
|
||||||
|
@ -233,7 +233,8 @@ def get_app_name(bench_path: str, folder_name: str) -> str:
|
|||||||
config_py_path = os.path.join(apps_path, folder_name, "setup.cfg")
|
config_py_path = os.path.join(apps_path, folder_name, "setup.cfg")
|
||||||
setup_py_path = os.path.join(apps_path, folder_name, "setup.py")
|
setup_py_path = os.path.join(apps_path, folder_name, "setup.py")
|
||||||
|
|
||||||
pyproject = get_pyproject(apps_path, folder_name)
|
pyproject_path = os.path.join(apps_path, folder_name, "pyproject.toml")
|
||||||
|
pyproject = get_pyproject(pyproject_path)
|
||||||
if pyproject:
|
if pyproject:
|
||||||
app_name = pyproject.get("project", {}).get("name")
|
app_name = pyproject.get("project", {}).get("name")
|
||||||
|
|
||||||
@ -255,8 +256,7 @@ def get_app_name(bench_path: str, folder_name: str) -> str:
|
|||||||
return folder_name
|
return folder_name
|
||||||
|
|
||||||
|
|
||||||
def get_pyproject(apps_path:str, folder_name:str) -> Optional[dict]:
|
def get_pyproject(pyproject_path: str) -> Optional[dict]:
|
||||||
pyproject_path = os.path.join(apps_path, folder_name, "pyproject.toml")
|
|
||||||
if not os.path.exists(pyproject_path):
|
if not os.path.exists(pyproject_path):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user