Skip to content

Commit

Permalink
Merge pull request #32 from jwbixby/master
Browse files Browse the repository at this point in the history
Remove caching functionality to reduce the possibility of a memory leak
  • Loading branch information
simon-weber committed Mar 16, 2016
2 parents 60f0176 + 9fc976c commit 8e17a8b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 36 deletions.
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
History
-------

1.0.0
+++++
released 2016-3-16

- Removes caching layer on rule decorator
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include HISTORY.rst LICENSE README.md
2 changes: 1 addition & 1 deletion business_rules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.2.0'
__version__ = '1.0.0'

from .engine import run_all
from .utils import export_rule_data
Expand Down
17 changes: 1 addition & 16 deletions business_rules/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_all_variables(cls):
} for m in methods if getattr(m[1], 'is_rule_variable', False)]


def rule_variable(field_type, label=None, options=None, cache_result=True):
def rule_variable(field_type, label=None, options=None):
""" Decorator to make a function into a rule variable
"""
options = options or []
Expand All @@ -31,8 +31,6 @@ def wrapper(func):
raise AssertionError("{0} is not instance of BaseType in"\
" rule_variable field_type".format(field_type))
func.field_type = field_type
if cache_result:
func = _memoize_return_values(func)
func.is_rule_variable = True
func.label = label \
or fn_name_to_pretty_label(func.__name__)
Expand Down Expand Up @@ -61,16 +59,3 @@ def select_rule_variable(label=None, options=None):

def select_multiple_rule_variable(label=None, options=None):
return rule_variable(SelectMultipleType, label=label, options=options)

def _memoize_return_values(func):
""" Simple memoization (cacheing) decorator, copied from
http://code.activestate.com/recipes/577219-minimalistic-memoization/
"""
cache= {}
@wraps(func)
def memf(*args, **kwargs):
key = (args, frozenset(kwargs.items()))
if key not in cache:
cache[key] = func(*args, **kwargs)
return cache[key]
return memf
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

from business_rules import __version__ as version

with open('History.rst') as f:
history = f.read()

description = 'Python DSL for setting up business intelligence rules that can be configured without code'

setuptools.setup(
name='business-rules',
version=version,
description='Python DSL for setting up business intelligence rules that can be configured without code',
description='{0}\n\n{1}'.format(description, history),
author='Venmo',
author_email='[email protected]',
url='https://github.com/venmo/business-rules',
Expand Down
18 changes: 0 additions & 18 deletions tests/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ def test_rule_variable_decorator_auto_fills_label(self):
def some_test_function(self): pass
self.assertTrue(some_test_function.label, 'Some Test Function')

def test_rule_variable_decorator_caches_value(self):
foo = 1
@rule_variable(NumericType)
def foo_func():
return foo
self.assertEqual(foo_func(), 1)
foo = 2
self.assertEqual(foo_func(), 1)

def test_rule_variable_decorator_doesnt_cache_value_with_option_passed(self):
foo = 1
@rule_variable(NumericType, cache_result=False)
def foo_func():
return foo
self.assertEqual(foo_func(), 1)
foo = 2
self.assertEqual(foo_func(), 2)

###
### rule_variable wrappers for each variable type
###
Expand Down

0 comments on commit 8e17a8b

Please sign in to comment.