Skip to content

Commit

Permalink
converting configuration to borg pattern
Browse files Browse the repository at this point in the history
Signed-off-by: WithPrecedent <coreyrayburnyung@gmail.com>
  • Loading branch information
WithPrecedent committed Mar 3, 2020
1 parent c2a4f6c commit f153d27
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 105 deletions.
16 changes: 8 additions & 8 deletions simplify/analyst/analyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ class AnalystScholar(Scholar):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand Down Expand Up @@ -405,11 +405,11 @@ class AnalystFinisher(Finisher):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

""" Private Methods """

Expand Down Expand Up @@ -473,11 +473,11 @@ class AnalystSpecialist(Specialist):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

""" Private Methods """

Expand Down Expand Up @@ -579,10 +579,10 @@ class Tools(Repository, SimpleSettings):
"""A dictonary of Tool options for the Analyst subpackage.
Args:
idea (ClassVar['Idea']): shared 'Idea' instance with project settings.
idea (Optional['Idea']): shared 'Idea' instance with project settings.
"""
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def create(self) -> None:
self.contents = {
Expand Down
16 changes: 8 additions & 8 deletions simplify/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class SimpleSettings(ABC):
"""Provides shared configuration settings and logger to subclasses.
Args:
idea (ClassVar['Idea']): instance with general project settings.
idea (Optional['Idea']): instance with general project settings.
filer (ClassVar['Filer']): instance with settings and methods for file
managerment.
journal (ClassVar['Journal']): instance which logs activity, errors,
and timing for a siMpLify 'Project'.
"""
idea: ClassVar['Idea']
idea: Optional['Idea'] = None
filer: ClassVar['Filer']
journal: ClassVar['Journal']

Expand All @@ -41,17 +41,17 @@ def __post_init__(self) -> None:


@dataclass
class SimpleCreator(SimpleSettings, ABC):
class SimpleCreator(ABC):
"""Base class for creating 'Book', 'Chapter', and 'Technique' instances.
Args:
worker ('Worker'): instance with information needed to create a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand All @@ -75,17 +75,17 @@ def publish(self, project: 'Project') -> 'Project':


@dataclass
class SimpleEngineer(SimpleSettings, ABC):
class SimpleEngineer(ABC):
"""Base class for applying 'Book' instances to data.
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand Down
2 changes: 1 addition & 1 deletion simplify/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Dataset(SimpleSettings):
coordination between siMpLify classes. 'name' is used instead of
__class__.__name__ to make such subclassing easier. Defaults to
None. If not passed, '__class__.__name__.lower()' is used.
idea (ClassVar['Idea']): shared 'Idea' instance with project settings.
idea (Optional['Idea']): shared 'Idea' instance with project settings.
filer (ClassVar['Filer']): shared 'Filer' instance with
project file management settings.
Expand Down
31 changes: 22 additions & 9 deletions simplify/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
Tuple, Union)

from simplify.core.base import SimpleLoader
from simplify.core.base import SimpleSettings
from simplify.core.creators import Publisher
from simplify.core.library import Book
from simplify.core.library import Chapter
Expand All @@ -36,7 +35,7 @@ class Manager(MutableMapping):
'default_packages' to use. Defaults to an empty dictionary. If
nothing is provided, Project attempts to construct workers from
'idea' and 'default_packages'.
idea (ClassVar['Idea']): shared project configuration settings.
idea (Optional['Idea']): shared project configuration settings.
"""
workers: Optional[Union[Dict[str, 'Worker'], List[str]]] = field(
Expand All @@ -52,8 +51,8 @@ def __post_init__(self) -> None:

@classmethod
def create(cls,
packages: Union[Dict[str, Union['Worker', 'Package']],
'Repository',
packages: Union[Dict[str, Union['Worker', 'Package']],
'Repository',
'Manager'],
idea: 'Idea') -> 'Manager':
"""Creates a 'Manager' instance from 'packages'.
Expand All @@ -78,10 +77,10 @@ def create(cls,
return cls(workers = packages, idea = idea)
else:
try:
new_packages = {}
workers = {}
for key, package in packages.items():
new_packages[key] = package.load()
return cls(workers = new_packages, idea = idea)
workers[key] = package.load()
return cls(workers = workers, idea = idea)
except AttributeError:
raise TypeError(
'workers values must be Worker or Package type')
Expand Down Expand Up @@ -182,7 +181,7 @@ def _initialize_workers(self,


@dataclass
class Worker(SimpleLoader, SimpleSettings):
class Worker(SimpleLoader):
"""Object construction instructions used by a Project instance.
Args:
Expand Down Expand Up @@ -220,7 +219,7 @@ class Worker(SimpleLoader, SimpleSettings):
export_folder (Optional[str]): name of attribute in 'filer' which
contains the path to the default folder for exporting data objects.
Defaults to 'processed'.
idea (ClassVar['Idea']): shared project configuration settings.
idea (Optional['Idea']): shared project configuration settings.
"""
name: Optional[str] = None
Expand All @@ -240,6 +239,9 @@ class Worker(SimpleLoader, SimpleSettings):
def __post_init__(self) -> None:
if self.name is None:
self.name = self.__class__.__name__.lower()
self._to_load = ['chapter', 'technique']
self._to_instance = ['book', 'publisher', 'scholar', 'options']
self.draft()
return self

""" Core siMpLify Methods """
Expand All @@ -264,6 +266,17 @@ def outline(self) -> Dict[str, List[str]]:
suffix = 'techniques')
return catalog

def draft(self) -> None:
for attribute in self._to_load + self._to_instance:
setattr(self, attribute, self.load(attribute))
if attribute in self._to_instance:
if attribute in ['scholar', 'publisher']:
setattr(self, attribute, getattr(self, attribute)(
worker = self))
else:
setattr(self, attribute, getattr(self, attribute)())
return self

""" Private Methods """

def _get_settings(self,
Expand Down
6 changes: 3 additions & 3 deletions simplify/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Repository(MutableMapping):
defaults (Optional[List[str]]): a list of keys in 'contents' which
will be used to return items when 'default' is sought. If not
passed, 'default' will be set to all keys.
idea (ClassVar['Idea']): shared 'Idea' instance with project settings.
idea (Optional['Idea']): shared 'Idea' instance with project settings.
"""
name: Optional[str] = None
Expand Down Expand Up @@ -247,12 +247,12 @@ def subsetify(self, keys: Union[List[str], str]) -> 'Repository':
# empty list. All items in 'steps' should correspond to keys in
# 'repository' before iterating.
# repository ('Repository'): instance with options for 'steps'.
# idea (ClassVar['Idea']): shared 'Idea' instance with project settings.
# idea (Optional['Idea']): shared 'Idea' instance with project settings.

# """
# steps: Union[List[str], str]
# repository: 'Repository'
# idea: ClassVar['Idea'] = None
# idea: Optional['Idea'] = None = None

# def __post_init__(self) -> None:
# self.create()
Expand Down
12 changes: 6 additions & 6 deletions simplify/core/scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class Scholar(SimpleEngineer):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand Down Expand Up @@ -116,11 +116,11 @@ class Finisher(SimpleEngineer):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand Down Expand Up @@ -288,11 +288,11 @@ class Specialist(SimpleEngineer):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand Down
18 changes: 9 additions & 9 deletions simplify/critic/critic.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ class CriticScholar(Scholar):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

def __post_init__(self) -> None:
"""Initializes class instance attributes."""
Expand All @@ -190,11 +190,11 @@ class CriticFinisher(Finisher):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

""" Private Methods """

Expand Down Expand Up @@ -223,11 +223,11 @@ class CriticSpecialist(Specialist):
Args:
worker ('Worker'): instance with information needed to apply a 'Book'
instance.
idea (ClassVar['Idea']): instance with project settings.
idea (Optional['Idea']): instance with project settings.
"""
worker: 'Worker'
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

""" Private Methods """

Expand Down Expand Up @@ -267,10 +267,10 @@ class Evaluators(Repository):
"""A dictonary of Evaluator options for the Analyst subpackage.
Args:
idea (ClassVar['Idea']): shared 'Idea' instance with project settings.
idea (Optional['Idea']): shared 'Idea' instance with project settings.
"""
idea: ClassVar['Idea']
idea: Optional['Idea'] = None

""" Private Methods """

Expand Down Expand Up @@ -388,7 +388,7 @@ class Critic(Worker):
export_folder (Optional[str]): name of attribute in 'filer' which
contains the path to the default folder for exporting data objects.
Defaults to 'processed'.
idea (ClassVar['Idea']): shared project configuration settings.
idea (Optional['Idea']): shared project configuration settings.
"""
name: Optional[str] = field(default_factory = lambda: 'critic')
Expand Down

0 comments on commit f153d27

Please sign in to comment.