Skip to content

Commit c35c9c9

Browse files
committed
bootstrap: engine requirement derives from the plugin's own version
1 parent c8e4769 commit c35c9c9

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

isobenefit_qgis/bootstrap.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,30 @@
2424

2525
CORE_IMPORT = "isobenefit"
2626
CORE_PACKAGE = "isobenefit"
27-
# the floor tracks the oldest core this plugin should drive: 0.12.17 adds the
28-
# engine-side walk_distance field that makes post-processing fast on large windows
29-
# (the plugin falls back to a slow Python walk on older engines)
30-
MIN_VERSION = (0, 12, 18)
3127
MAX_VERSION_EXCLUSIVE = (0, 13, 0)
32-
PIP_SPEC = "isobenefit>=0.12.18,<0.13"
28+
29+
30+
def _plugin_version() -> str:
31+
"""The plugin's own version from metadata.txt — the engine requirement.
32+
33+
Plugin and engine release in strict lockstep, so the engine must be at least the
34+
plugin's version (a newer 0.12.x is fine). Deriving the requirement here, rather
35+
than from a hand-maintained floor, means the two can never drift and the upgrade
36+
prompt fires exactly when the versions differ.
37+
"""
38+
import configparser
39+
40+
parser = configparser.ConfigParser()
41+
parser.read(os.path.join(os.path.dirname(__file__), "metadata.txt"))
42+
return parser.get("general", "version")
43+
44+
45+
def min_version() -> tuple[int, int, int]:
46+
return _parse_version(_plugin_version())
47+
48+
49+
def pip_spec() -> str:
50+
return f"{CORE_PACKAGE}>={_plugin_version()},<{MAX_VERSION_EXCLUSIVE[0]}.{MAX_VERSION_EXCLUSIVE[1]}"
3351

3452
# module-level so the running install survives ensure_core returning
3553
_install_task: QgsTask | None = None
@@ -64,7 +82,7 @@ def core_status() -> tuple[bool, str | None]:
6482
except Exception:
6583
return False, None
6684
parsed = _parse_version(version)
67-
if parsed < MIN_VERSION or parsed >= MAX_VERSION_EXCLUSIVE:
85+
if parsed < min_version() or parsed >= MAX_VERSION_EXCLUSIVE:
6886
return False, version
6987
return True, version
7088

@@ -240,7 +258,7 @@ def ensure_core(parent: QWidget | None = None) -> bool:
240258
return False
241259

242260
def _install(_task: QgsTask):
243-
return _pip_install(PIP_SPEC)
261+
return _pip_install(pip_spec())
244262

245263
def _done(exception, result=None):
246264
global _install_task
@@ -258,7 +276,7 @@ def _done(exception, result=None):
258276
parent,
259277
"Isobenefit: install failed",
260278
"Automatic installation failed. Install it manually from a terminal:\n\n"
261-
f' "{python}" -m pip install "{PIP_SPEC}"\n\n'
279+
f' "{python}" -m pip install "{pip_spec()}"\n\n'
262280
"Then restart QGIS.\n\nDetails:\n" + (output[-1500:] if output else "(no output)"),
263281
)
264282

0 commit comments

Comments
 (0)