-- -- --- --- --- --- --- --- ------- ------- ------- |
"""Define a standard data class for Wily Configuration."""
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
import logging
-- -- --- --- --- --- --- --- ------- ------- ------- |
import pathlib
-- -- --- --- --- --- --- --- ------- ------- ------- |
from dataclasses import InitVar, dataclass, field
-- -- --- --- --- --- --- --- ------- ------- ------- |
from typing import Any, Iterable, List, Optional
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
from wily.helper import generate_cache_path
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
logger = logging.getLogger(__name__)
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
-- -- --- --- --- --- --- --- ------- ------- ------- |
@dataclass
03 -- --- --- --- --- --- --- ------- ------- ------- |
class WilyConfig:
03 -- --- --- --- --- --- --- ------- ------- ------- |
"""
03 -- --- --- --- --- --- --- ------- ------- ------- |
Wily configuration.
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- |
A data class to reflect the configurable options within Wily.
03 -- --- --- --- --- --- --- ------- ------- ------- |
"""
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- |
operators: Iterable[str]
03 -- --- --- --- --- --- --- ------- ------- ------- |
archiver: Any
03 -- --- --- --- --- --- --- ------- ------- ------- |
path: str
03 -- --- --- --- --- --- --- ------- ------- ------- |
max_revisions: int
03 -- --- --- --- --- --- --- ------- ------- ------- |
include_ipynb: bool = True
03 -- --- --- --- --- --- --- ------- ------- ------- |
ipynb_cells: bool = True
03 -- --- --- --- --- --- --- ------- ------- ------- |
targets: Optional[List[str]] = None
03 -- --- --- --- --- --- --- ------- ------- ------- |
checkout_options: dict = field(default_factory=dict)
03 -- --- --- --- --- --- --- ------- ------- ------- |
_cache_path: InitVar[str] = ""
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
def __post_init__(self, _cache_path):
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
"""Parse operators string to list and clone targets as a list of path."""
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
if isinstance(self.operators, str):
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
self.operators = self._parse_to_list(self.operators)
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
if self.targets is None or "":
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
self.targets = [self.path]
03 04 002 004 002 004 006 006 0015.51 0015.51 0001.00 |
self._cache_path = _cache_path # type: ignore
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- |
@property
03 -- --- --- --- --- --- --- ------- ------- ------- |
def cache_path(self):
03 -- --- --- --- --- --- --- ------- ------- ------- |
"""Path to the cache."""
03 -- --- --- --- --- --- --- ------- ------- ------- |
if not self._cache_path: # type: ignore
03 -- --- --- --- --- --- --- ------- ------- ------- |
self._cache_path = generate_cache_path(pathlib.Path(self.path).absolute()) # type: ignore
03 -- --- --- --- --- --- --- ------- ------- ------- |
return self._cache_path # type: ignore
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- |
@cache_path.setter
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def cache_path(self, value):
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
"""Override the cache path."""
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
logger.debug(f"Setting custom cache path to {value}")
03 01 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
self._cache_path = value # type: ignore
03 -- --- --- --- --- --- --- ------- ------- ------- |
03 -- --- --- --- --- --- --- ------- ------- ------- |
@staticmethod
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
def _parse_to_list(string, separator=","):
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
items = []
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
for raw_item in string.split(separator):
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
item = raw_item.strip()
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
if item:
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
items.append(item)
03 03 000 000 000 000 000 000 0000.00 0000.00 0000.00 |
return items