Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
merge FactoryDispatcher.py into factory.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Mar 13, 2018
1 parent 2a256cd commit a121c0f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
41 changes: 0 additions & 41 deletions alphatwirl/selection/factories/FactoryDispatcher.py

This file was deleted.

34 changes: 33 additions & 1 deletion alphatwirl/selection/factories/factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Tai Sakuma <tai.sakuma@gmail.com>
from .FactoryDispatcher import call_factory

from .expand import expand_path_cfg

##__________________________________________________________________||
def AllFactory(path_cfg_list, name=None, **kargs):
Expand All @@ -22,3 +23,34 @@ def LambdaStrFactory(lambda_str, LambdaStrClass, name=None, **kargs):
return LambdaStrClass(lambda_str=lambda_str.format(**kargs), name=name)

##__________________________________________________________________||
def FactoryDispatcher(path_cfg, **kargs):

alias_dict = kargs.get('aliasDict', { })
path_cfg = expand_path_cfg(path_cfg, alias_dict=alias_dict)

return call_factory(path_cfg, **kargs)

##__________________________________________________________________||
def call_factory(path_cfg, **kargs):

path_cfg_copy = path_cfg.copy()
factoryName = path_cfg_copy.pop('factory')
factory = find_factory(factoryName)
kargs_copy = kargs.copy()
kargs_copy.update(path_cfg_copy)

return factory(**kargs_copy)

##__________________________________________________________________||
def find_factory(name):

ret_dict = dict(
AllFactory=AllFactory,
AnyFactory=AnyFactory,
NotFactory=NotFactory,
LambdaStrFactory=LambdaStrFactory,
)

return ret_dict[name]

##__________________________________________________________________||
2 changes: 1 addition & 1 deletion alphatwirl/selection/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .modules.basic import Any
from .modules.basic import Not
from .modules.LambdaStr import LambdaStr
from .factories.FactoryDispatcher import FactoryDispatcher
from .factories.factory import FactoryDispatcher

import os, sys

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/selection/factories/test_FactoryDispatcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tai Sakuma <tai.sakuma@gmail.com>
import pytest

from alphatwirl.selection.factories.FactoryDispatcher import FactoryDispatcher
from alphatwirl.selection.factories.factory import FactoryDispatcher
from alphatwirl.selection.modules.LambdaStr import LambdaStr
from alphatwirl.selection.modules import All, Any, Not

Expand Down

0 comments on commit a121c0f

Please sign in to comment.