From 4c5bc1cf6c8b3d02b6a029c035910a96aa070c95 Mon Sep 17 00:00:00 2001 From: leoentersthevoid Date: Fri, 28 Jun 2024 17:30:39 +0300 Subject: [PATCH 1/2] reviving the pkg; adapted scripts to latest pydantic --- arc/interface.py | 10 +++++----- arc/metrics.py | 3 +-- arc/settings.py | 4 ++-- setup.py | 1 + 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arc/interface.py b/arc/interface.py index c4ba19c..f0bfa68 100755 --- a/arc/interface.py +++ b/arc/interface.py @@ -17,16 +17,16 @@ COLORMAP = {0: 0, 1: 4, 2: 1, 3: 2, 4: 3, 5: 8, 6: 5, 7: 166, 8: 6, 9: 52} -class Board(pydantic.BaseModel): - __root__: list[list[int]] +class Board(pydantic.RootModel): + root: list[list[int]] - @pydantic.validator("__root__", pre=True) + @pydantic.validator("root", pre=True) def validate_native_list(cls, v): if isinstance(v, np.ndarray): v = v.tolist() return v - @pydantic.validator("__root__") + @pydantic.validator("root") def validate_non_ragged(cls, v): if len(set(lengths := list(map(len, v)))) != 1: raise ValueError( @@ -36,7 +36,7 @@ def validate_non_ragged(cls, v): @property def data(self): - return self.__root__ + return self.root @property def data_flat(self): diff --git a/arc/metrics.py b/arc/metrics.py index 6f22e9a..f176881 100755 --- a/arc/metrics.py +++ b/arc/metrics.py @@ -6,7 +6,6 @@ import numpy as np import pydantic -import pydantic.generics from arc.interface import Board, BoardPair, EvalResult, EvalResultList, TopKList @@ -14,7 +13,7 @@ A = TypeVar("A") -class MetricResult(pydantic.generics.GenericModel, Generic[C, A]): +class MetricResult(pydantic.BaseModel, Generic[C, A]): name: str compute_results: Optional[list[C]] = None aggregate_result: Optional[A] = None diff --git a/arc/settings.py b/arc/settings.py index f4206ab..5651adc 100755 --- a/arc/settings.py +++ b/arc/settings.py @@ -3,10 +3,10 @@ import os.path from typing import Optional -import pydantic +from pydantic_settings import BaseSettings -class Settings(pydantic.BaseSettings): +class Settings(BaseSettings): cache_path: str = os.path.expanduser("~/.arc/cache") dataset_dir: Optional[str] = None cell_padding: int = 1 diff --git a/setup.py b/setup.py index a701505..0221144 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ "loguru", "tqdm", "pydantic", + "pydantic-settings", "filelock", "colored", "matplotlib", From 7b9cd301c35c30230573808558d6d5da8bc90023 Mon Sep 17 00:00:00 2001 From: leoentersthevoid Date: Fri, 2 Aug 2024 23:45:01 +0200 Subject: [PATCH 2/2] fixed nasty maggot --- arc/interface.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arc/interface.py b/arc/interface.py index f0bfa68..f72fa77 100755 --- a/arc/interface.py +++ b/arc/interface.py @@ -14,8 +14,7 @@ BOARD_GAP_STR = " " * settings.board_gap PAIR_GAP_STR = "\n" + " " * settings.pair_gap + "\n" -COLORMAP = {0: 0, 1: 4, 2: 1, 3: 2, 4: 3, 5: 8, 6: 5, 7: 166, 8: 6, 9: 52} - +COLORMAP = {0: 0, 1: 4, 2: 1, 3: 2, 4: 3, 5: 220, 6: 5, 7: 166, 8: 6, 9: 52} class Board(pydantic.RootModel): root: list[list[int]] @@ -75,7 +74,7 @@ def fmt_cell(self, row: int, col: int, colored=False) -> str: color = COLORMAP[value] value_str = f"{CELL_PADDING_STR}{value}{CELL_PADDING_STR}" if colored: - return f"{fg(15)}{bg(color)}{value_str}{attr(0)}" + return f"{fg(15)}{bg(color)}{value_str}{attr('reset')}" else: return value_str