Skip to content

Commit

Permalink
fix: improve version check patch (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarvora authored Jul 26, 2023
1 parent e3331c6 commit 542209c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
3 changes: 0 additions & 3 deletions india_compliance/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
__version__ = "15.0.0-dev"

MIN_FRAPPE_VERSION = "15.0.0-dev"
MIN_ERPNEXT_VERSION = "15.0.0-dev"
52 changes: 34 additions & 18 deletions india_compliance/patches/check_version_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,55 @@
from packaging import version

import frappe
from frappe.utils.change_log import get_app_branch
import erpnext

from india_compliance import MIN_ERPNEXT_VERSION, MIN_FRAPPE_VERSION
import india_compliance

IC_VERSION = version.parse(india_compliance.__version__)

VERSIONS_TO_COMPARE = [
{
"app_name": "frappe",
"current_version": frappe.__version__,
"required_version": MIN_FRAPPE_VERSION,
"app_name": "Frappe",
"current_version": version.parse(frappe.__version__),
"required_versions": {"version-14": "14.42.0"},
},
{
"app_name": "erpnext",
"current_version": erpnext.__version__,
"required_version": MIN_ERPNEXT_VERSION,
"app_name": "ERPNext",
"current_version": version.parse(erpnext.__version__),
"required_versions": {"version-14": "14.32.0"},
},
]


def execute():
for app in VERSIONS_TO_COMPARE:
app_name = app["app_name"]
current_version = app["current_version"]
required_version = app["required_version"]
app_version = app["current_version"]

if IC_VERSION.major != app_version.major:
show_error_and_exit(
f"Incompatible {app_name} Version: \nPlease switch to version"
f" {IC_VERSION.major} of {app_name} to use the current version of India"
" Compliance.\n"
)

app_branch = get_app_branch(app_name.lower())
required_versions = app["required_versions"]

if version.parse(current_version) >= version.parse(required_version):
if app_branch not in required_versions:
continue

click.secho(
(
f"Please upgrade {app_name} to version {required_version} or"
" above to use the current version of India Compliance."
),
fg="red",
)
required_version = version.parse(required_versions[app_branch])

if app_version < required_version:
show_error_and_exit(
f"Incompatible {app_name} Version: \nPlease upgrade {app_name} to"
f" version {required_version} or above to use the current version of"
" India Compliance.\n"
)


frappe.throw(f"Incompatible {app_name.title()} Version")
def show_error_and_exit(error_message):
click.secho(error_message, fg="red")
raise SystemExit(1)

0 comments on commit 542209c

Please sign in to comment.