From 49577f1d4dd196068341a2161eee0fe5503af88e Mon Sep 17 00:00:00 2001 From: Jian Yuan Lee Date: Wed, 31 Jan 2018 10:55:40 +0000 Subject: [PATCH 1/2] Use relative imports --- business_rules/engine.py | 6 +++--- business_rules/operators.py | 15 ++++++++------- business_rules/utils.py | 5 ++--- business_rules/variables.py | 18 +++++------------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/business_rules/engine.py b/business_rules/engine.py index a2344d36..5cdfa1d5 100644 --- a/business_rules/engine.py +++ b/business_rules/engine.py @@ -1,10 +1,10 @@ import inspect import logging -import utils -from business_rules.models import ConditionResult -from util import method_type +from . import utils from .fields import FIELD_NO_INPUT +from .models import ConditionResult +from .util import method_type logger = logging.getLogger(__name__) diff --git a/business_rules/operators.py b/business_rules/operators.py index e8860983..4d54c993 100644 --- a/business_rules/operators.py +++ b/business_rules/operators.py @@ -1,15 +1,16 @@ +import calendar import inspect import re +from datetime import date, datetime, time from decimal import Decimal from functools import wraps -from datetime import datetime, date, time -from six import string_types, integer_types -import calendar -from .fields import ( - FIELD_TEXT, FIELD_NUMERIC, FIELD_NO_INPUT, FIELD_SELECT, FIELD_SELECT_MULTIPLE, FIELD_DATETIME, FIELD_TIME -) -from .utils import fn_name_to_pretty_label, float_to_decimal +from six import integer_types, string_types + +from .fields import (FIELD_DATETIME, FIELD_NO_INPUT, FIELD_NUMERIC, + FIELD_SELECT, FIELD_SELECT_MULTIPLE, FIELD_TEXT, + FIELD_TIME) +from .utils import float_to_decimal, fn_name_to_pretty_label class BaseType(object): diff --git a/business_rules/utils.py b/business_rules/utils.py index c7331abb..56cdd881 100644 --- a/business_rules/utils.py +++ b/business_rules/utils.py @@ -1,8 +1,7 @@ import inspect -from decimal import Decimal, Inexact, Context +from decimal import Context, Decimal, Inexact -import fields, engine -from util import method_type +from .util import method_type def fn_name_to_pretty_label(name): diff --git a/business_rules/variables.py b/business_rules/variables.py index 4a6d5fa5..c82c5223 100644 --- a/business_rules/variables.py +++ b/business_rules/variables.py @@ -1,18 +1,10 @@ import inspect -from typing import List, Callable, Type - -import utils -from .operators import ( - BaseType, - NumericType, - StringType, - BooleanType, - SelectType, - SelectMultipleType, - DateTimeType, - TimeType, -) +from typing import Callable, List, Type # noqa: F401 + +from . import utils +from .operators import (BaseType, BooleanType, DateTimeType, NumericType, + SelectMultipleType, SelectType, StringType, TimeType) from .utils import fn_name_to_pretty_label From 052de5b5b12706ddbe25bed6026e9a06078d464e Mon Sep 17 00:00:00 2001 From: Jian Yuan Lee Date: Wed, 31 Jan 2018 10:59:23 +0000 Subject: [PATCH 2/2] Fix valid fields import --- business_rules/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/business_rules/utils.py b/business_rules/utils.py index 56cdd881..69ded344 100644 --- a/business_rules/utils.py +++ b/business_rules/utils.py @@ -55,6 +55,8 @@ def float_to_decimal(f): def get_valid_fields(): + from . import fields + valid_fields = [getattr(fields, f) for f in dir(fields) if f.startswith("FIELD_")] return valid_fields