diff --git a/pyprobe/__init__.py b/pyprobe/__init__.py index 9bde78aa..7a41a9da 100644 --- a/pyprobe/__init__.py +++ b/pyprobe/__init__.py @@ -1,13 +1,5 @@ """The PyProBE package.""" -import os - -import toml - -from .cell import Cell, load_archive, make_cell_list # noqa: F401 +from .cell import Cell, __version__, load_archive, make_cell_list # noqa: F401 from .dashboard import launch_dashboard # noqa: F401 from .plot import Plot # noqa: F401 from .result import Result # noqa: F401 - -pyproject_path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml") -pyproject_data = toml.load(pyproject_path) -__version__ = pyproject_data["project"]["version"] diff --git a/pyprobe/cell.py b/pyprobe/cell.py index 81064f21..bb453670 100644 --- a/pyprobe/cell.py +++ b/pyprobe/cell.py @@ -10,13 +10,14 @@ import distinctipy import polars as pl import pybamm.solvers.solution -import toml from pydantic import BaseModel, Field, field_validator, validate_call from pyprobe.cyclers import basecycler, biologic, neware from pyprobe.filters import Procedure from pyprobe.readme_processor import process_readme +__version__ = "1.0.3" + class Cell(BaseModel): """A class for a cell in a battery experiment.""" @@ -450,9 +451,7 @@ def archive(self, path: str) -> None: if not os.path.exists(path): os.makedirs(path) metadata = self.dict() - pyproject_path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml") - pyproject_data = toml.load(pyproject_path) - metadata["PyProBE Version"] = pyproject_data["project"]["version"] + metadata["PyProBE Version"] = __version__ for procedure_name, procedure in self.procedure.items(): if isinstance(procedure.base_dataframe, pl.LazyFrame): df = procedure.base_dataframe.collect() @@ -500,13 +499,11 @@ def load_archive(path: str) -> Cell: with open(os.path.join(archive_path, "metadata.json"), "r") as f: metadata = json.load(f) - pyproject_path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml") - pyproject_data = toml.load(pyproject_path) - if metadata["PyProBE Version"] != pyproject_data["project"]["version"]: + if metadata["PyProBE Version"] != __version__: warnings.warn( f"The PyProBE version used to archive the cell was " f"{metadata['PyProBE Version']}, the current version is " - f"{pyproject_data['project']['version']}. There may be compatibility" + f"{__version__}. There may be compatibility" f" issues." ) metadata.pop("PyProBE Version")