Skip to content

Commit

Permalink
Merge pull request #38 from OrBin/bugfix/boolean-triggers
Browse files Browse the repository at this point in the history
Bugfix/boolean triggers
  • Loading branch information
meirhalachmi authored Mar 8, 2019
2 parents db395cd + f84e7a5 commit 3d46324
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gramhopper/configuration/boolean_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union, Callable
from boolean import boolean
from ruamel.yaml.comments import CommentedMap
from .partial_ruamel_yaml import CommentedMap
from .globals_dict import GlobalsDict
from .boolean_operators import OPERATOR_TYPE_TO_FUNCTION
from .trigger_response import TriggerResponse
Expand Down
18 changes: 18 additions & 0 deletions gramhopper/configuration/partial_ruamel_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
This file is a dirty hack to handle ruamel_yaml import problem
In certain distributions, the module name is ruamel_yaml, while in others it's ruamel.yaml.
As you can easily understand, that made us very sad :(
A fallback import wasn't enough to solve it since the same imports were done in 3 different files,
so we decided to create this file, which is a *very* partial accessor to ruamel_yaml.
"""

try:
from ruamel_yaml import YAML
from ruamel_yaml.comments import CommentedMap
except ImportError:
from ruamel.yaml import YAML
from ruamel.yaml.comments import CommentedMap


YAML = YAML
CommentedMap = CommentedMap # pylint: disable=invalid-name
4 changes: 2 additions & 2 deletions gramhopper/configuration/rules_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ruamel.yaml import YAML
from ruamel.yaml.comments import CommentedMap
from .partial_ruamel_yaml import YAML
from .partial_ruamel_yaml import CommentedMap
from .rules_parsing_helper import RulesParsingHelper
from ..handlers.handler import Handler
from .trigger_response_params import TriggerParams, ResponseParams
Expand Down
2 changes: 1 addition & 1 deletion gramhopper/configuration/rules_parsing_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ruamel.yaml.comments import CommentedMap
from .partial_ruamel_yaml import CommentedMap
from .boolean_helper import BooleanHelper
from .trigger_response import TriggerResponse
from .trigger_response_params import TriggerResponseParams
Expand Down
12 changes: 8 additions & 4 deletions gramhopper/configuration/triggers_reponses_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ def parse_single(cls, config, global_elements): # pylint: disable=unused-argume
if 'name' in config_copy:
config_copy.pop('name')

mapping_cls = cls.mapping_class()
element_cls = mapping_cls[config_copy.pop('type')]

return element_cls(**config_copy)
mapping_class = cls.mapping_class()
element = mapping_class[config_copy.pop('type')]

# Some triggers (most of them) are classes and some are instances (mostly filter triggers).
# This allows both cases to be used.
if isclass(element):
return element(**config_copy)
return element

@classmethod
def parse_many(cls, config, global_elements):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='gramhopper',
version='1.0.4',
version='1.0.5',

description='A bot platform for automatic responses based on various triggers',
long_description=LONG_DESCRIPTION,
Expand Down

0 comments on commit 3d46324

Please sign in to comment.