Skip to content

Commit

Permalink
Move versioning into cell module and hardcode
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjholland committed Oct 21, 2024
1 parent 001eef7 commit 2d7bde7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
10 changes: 1 addition & 9 deletions pyprobe/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 5 additions & 8 deletions pyprobe/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 2d7bde7

Please sign in to comment.