Replies: 9 comments 6 replies
|
Here are the current attributes: |
|
The full definitions of FolderTierBase and NotebookBase must have: |
|
Need to worry about how to iterate over children. Children need not necessarily reside directly in the Children obviously know where they are, as they know who their parent is. My idea was that this means the Tier should know where all of its' siblings are. For the simple recursive structure: For the way DataSets work This is going to be very confusing, and maybe it's just better to make them abstract and force users to define themselves... |
|
FYI I checked the performance, and the caching really does make quite a big difference. |
|
Define 2 ABC, one Where it's more obvious for a user to define their own explicitly, get rid of some of the magic properties. Specialisations, like techniques, etc. can be implemented in the Home can be a subclass of class TierBase(ABC):
rank: ClassVar[int] = -1 # give to Project
id_regex: ClassVar[str] = r"(\d+)" # keep!
@cached_class_prop
def hierarchy(cls) -> List[Type[TierBase]]: # probably get rid of, just use project.heirarchy.
@cached_class_prop
def pretty_type(cls) -> str: # make an attribute
@cached_class_prop
def short_type(cls) -> str: # make an attribute
@cached_class_prop
def name_part_template(cls) -> str: # make an attribute
@cached_class_prop
def name_part_regex(cls) -> str: # make an attribute
def __new__(cls, *args: str, **kwargs: Dict[str, Any]) -> TierBase:
_identifiers: Tuple[str, ...]
def __init__(self: Self, *args: str):
def setup_files(
self, template: Union[Path, None] = None, meta: Optional[MetaDict] = None
) -> None:
@cached_prop
def identifiers(self) -> Tuple[str, ...]:
@cached_prop
def name(self) -> str:
@cached_prop
def id(self) -> str:
@cached_prop
def folder(self) -> Path:
@cached_prop
def parent(self) -> Union[TierBase, None]:
@cached_prop
def href(self) -> Union[str, None]:
def exists(self) -> bool:
def open_folder(self) -> None:
def __truediv__(self, other: Any) -> Path:
def __getitem__(self, item: str) -> TierBase:
def __iter__(self) -> Iterator[Any]:
def __repr__(self) -> str:
def _repr_html_(self) -> str:
def __getattr__(self, item: str) -> TierBase:
def remove_files(self) -> None:NotebookTier class NotebookTier(TierABC):
rank: ClassVar[int] = -1 # give to Project
id_regex: ClassVar[str] = r"(\d+)" # keep!
gui_cls: Type[BaseTierGui[Self]] = BaseTierGui # Keep!
@cached_class_prop
def hierarchy(cls) -> List[Type[TierBase]]: # probably get rid of, just use project.heirarchy.
@cached_class_prop
def pretty_type(cls) -> str: # make an attribute
@cached_class_prop
def short_type(cls) -> str: # make an attribute
@cached_class_prop
def name_part_template(cls) -> str: # make an attribute
@cached_class_prop
def name_part_regex(cls) -> str: # make an attribute
@cached_class_prop
def parent_cls(cls) -> Union[Type[TierBase], None]: # get from project
@cached_class_prop
def child_cls(cls) -> Union[Type[TierBase], None]: # get from project
@cached_class_prop
def default_template(cls) -> Union[Path, None]: # probably fine.
@cached_class_prop
def _meta_folder_name(cls) -> str: # probably fine, let's force every class to have this at least
def __new__(cls, *args: str, **kwargs: Dict[str, Any]) -> TierBase:
@classmethod
def parse_name(cls, name: str) -> Tuple[str, ...]: # give to Project
@classmethod
def _iter_meta_dir(cls, path: Path) -> Iterator[Tuple[str, ...]]: # _iter_child_meta?
_identifiers: Tuple[str, ...]
gui: BaseTierGui[Self]
meta: Meta
def __init__(self: Self, *args: str):
def setup_files(
self, template: Union[Path, None] = None, meta: Optional[MetaDict] = None
) -> None:
description: MetaAttr[str, str] = MetaAttr() # ... do I really want this in the base class?
conclusion: MetaAttr[str, str] = MetaAttr()
started: MetaAttr[str, datetime.datetime] = MetaAttr(str_to_date, date_to_str)
@cached_prop
def identifiers(self) -> Tuple[str, ...]:
@cached_prop
def name(self) -> str:
@cached_prop
def id(self) -> str:
@cached_prop
def folder(self) -> Path:
@cached_prop
def meta_file(self) -> Union[Path, None]:
@cached_prop
def highlights_file(self) -> Union[Path, None]:
@cached_prop
def file(self) -> Union[Path, None]:
@cached_prop
def parent(self) -> Union[TierBase, None]:
@cached_prop
def href(self) -> Union[str, None]:
def exists(self) -> bool:
def get_child(self, id: str) -> TierBase:
def serialize(self) -> MetaDict:
def children_df(
self, *, include: Optional[List[str]] = None, exclude: Optional[List[str]]
) -> Union[pd.DataFrame, None]:
@classmethod
def get_templates(cls) -> List[Path]:
def render_template(self, template_path: Path) -> str:
def open_folder(self) -> None:
def get_highlights(self) -> Union[HighlightsType, None]:
def add_highlight(
self, name: str, data: HighlightType, overwrite: bool = True
) -> None:
def remove_highlight(self, name: str) -> None:
def __truediv__(self, other: Any) -> Path:
def __getitem__(self, item: str) -> TierBase:
def __iter__(self) -> Iterator[Any]:
def __repr__(self) -> str:
def _repr_html_(self) -> str:
def __getattr__(self, item: str) -> TierBase:
def remove_files(self) -> None: |
|
Ok I actually will add back in Adding a |
|
Here I am again... I wonder if we should use a mixin? I.e. a Notebook mixin and a Meta mixin? I think this would work? The problem we have is that Home isn't a Notebook or a Folder and that's annoying... |
|
I'm closing for now. They have been split up. Mixins maybe. People generally turn their noses up at multiple inheritance. |
Uh oh!
There was an error while loading. Please reload this page.
Currently TierBase represents a broad range of tiers.
DataSets don't have notebooks, therefore templates and meta and highlights etc.
TierBase should be split into two Base classes - FolderTierBase and NotebookTierBase.
A FolderTier is one with no notebook.
A NotebookTier is one with notebook, meta highlights etc.
This stops dodgy null implementations of the Notebook methods for DataSets.
It should be straightforward to incorporate is instance checks into the code and also into the jl_cassini_server. Providing a type would probably be very useful and a solution to poor handling of the top and bottom of the hierarchy by jl_cassini.
All reactions