diff --git a/fill_resistance/__init__.py b/fill_resistance/__init__.py index e69de29..b3ca363 100644 --- a/fill_resistance/__init__.py +++ b/fill_resistance/__init__.py @@ -0,0 +1,7 @@ +"""Fill Resistance - DC resistance of copper zone fills and traces. + +__version__ is the runtime source of truth (metadata.json and +pyproject.toml are not deployed with the plugin); a test keeps the +three in sync. +""" +__version__ = "1.3.0" diff --git a/fill_resistance/report.py b/fill_resistance/report.py index e951c28..d889205 100644 --- a/fill_resistance/report.py +++ b/fill_resistance/report.py @@ -7,7 +7,7 @@ from pathlib import Path import numpy as np -from . import config +from . import __version__, config from .geometry import Problem, save_problem from .raster import RasterStack from .solver import Result @@ -59,9 +59,10 @@ def write_summary(outdir: Path, problem: Problem, stack: RasterStack, result: Result) -> Path: ny, nx = stack.shape2d info = result.solve_info + head = f"fill_resistance {__version__} summary" lines = [ - "fill_resistance summary", - "=======================", + head, + "=" * len(head), f"board: {problem.board_path}", f"net: {problem.net_name}", f"test current: {result.i_test:g} A", diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..2edc54b --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,33 @@ +"""fill_resistance.__version__ is the runtime source of the version: +it must match the packaging metadata (which is not deployed with the +plugin) and show up in summary.txt.""" +import json +import re +from pathlib import Path + +import fill_resistance +from fill_resistance import raster, report, solver +from tests.util import NM, strip_problem + +ROOT = Path(__file__).resolve().parent.parent + + +def test_version_matches_packaging_metadata(): + meta = json.loads((ROOT / "metadata.json").read_text(encoding="utf-8")) + assert meta["versions"][0]["version"] == fill_resistance.__version__ + + pyproject = (ROOT / "pyproject.toml").read_text(encoding="utf-8") + m = re.search(r'^version = "([^"]+)"', pyproject, re.M) + assert m is not None + assert m.group(1) == fill_resistance.__version__ + + +def test_summary_shows_version(tmp_path): + problem = strip_problem() + stack = raster.rasterize_stack(problem, 1.0 * NM) + e1, e2 = raster.electrode_masks(stack, problem) + result = solver.run_solve(problem, stack, e1, e2, 1.0, + contact_model="equipotential") + text = report.write_summary(tmp_path, problem, stack, + result).read_text(encoding="utf-8") + assert fill_resistance.__version__ in text.splitlines()[0]