Skip to content

Commit

Permalink
:fix: typo and pylint badge
Browse files Browse the repository at this point in the history
  • Loading branch information
b3j0f committed Jun 15, 2015
1 parent 3800c92 commit b1b8376
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 210 deletions.
5 changes: 0 additions & 5 deletions .scrutinizer.yml

This file was deleted.

3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Utilities for Python.
:target: https://readthedocs.org/projects/b3j0futils/?badge=master
:alt: Documentation Status

.. image:: https://img.shields.io/badge/code quality-8.28-green.svg
:alt: Pylint code quality

Links
-----

Expand Down
34 changes: 20 additions & 14 deletions b3j0f/utils/chaining.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# SOFTWARE.
# --------------------------------------------------------------------

"""
This module aims to provide tools to chaining of calls.
"""This module aims to provide tools to chaining of calls.
It is inspired from method chaining pattern in embedding objects to chain
methods calls in a dedicated Chaining object. Such method calls return the
Expand Down Expand Up @@ -66,7 +65,7 @@ class Chaining(object):
"""

CONTENT = '_' #: content attribute name
RESULTS = '_r' #: chained method results attribute name
RESULTS = '___' #: chained method results attribute name

__slots__ = (CONTENT, RESULTS)

Expand All @@ -75,11 +74,11 @@ def __init__(self, content):
super(Chaining, self).__init__()

self._ = content
self._r = []
self.___ = []

def __getitem__(self, key):

return self._r[key]
return self.___[key]

def __getattribute__(self, key):

Expand All @@ -96,24 +95,24 @@ def __getattribute__(self, key):


def _process_function(chaining, routine):
"""
Chain function which returns a function.
"""Chain function which returns a function.
:param routine: routine to process.
:return: routine embedding execution function.
"""

def processing(*args, **kwargs):
"""Execute routine with input args and kwargs and add reuslt in
chaining._r.
chaining.___.
:param tuple args: routine varargs.
:param dict kwargs: routine kwargs.
:return: chaining chaining.
:rtype: Chaining
"""

result = routine(*args, **kwargs)
chaining._r.append(result)
chaining.___.append(result)

return chaining

Expand Down Expand Up @@ -166,9 +165,9 @@ def __getattribute__(self, key):
routine = None
try:
routine = getattr(content, key)
except Exception as e:
except AttributeError as excp:
# in case of exception, routine is the exception
routine = e
routine = excp
# in all cases, put routine in routines
routines[index] = routine
result = _process_function_list(self, routines)
Expand All @@ -185,18 +184,25 @@ def _process_function_list(self, routines):
"""

def processing(*args, **kwargs):
"""Execute routines with input args and kwargs and add reuslt in
chaining.___.
:param tuple args: routine varargs.
:param dict kwargs: routine kwargs.
:return: chaining chaining.
:rtype: Chaining
"""
results = [None] * len(routines)
for index, routine in enumerate(routines):
if isinstance(routine, Exception):
result = routine
else:
try:
result = routine(*args, **kwargs)
except Exception as e:
result = e
except AttributeError as excp:
result = excp
results[index] = result
self._r.append(results)
self.___.append(results)

return self

Expand Down
3 changes: 1 addition & 2 deletions b3j0f/utils/iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# SOFTWARE.
# --------------------------------------------------------------------

"""
Provides tools to manage iterable types
"""Provides tools to manage iterable types
"""

__all__ = ['isiterable', 'ensureiterable', 'first']
Expand Down
14 changes: 3 additions & 11 deletions b3j0f/utils/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# SOFTWARE.
# --------------------------------------------------------------------

"""
Tools for managing path resolution of python objects.
"""Tools for managing path resolution of python objects.
"""

# ensure str are unicodes
Expand Down Expand Up @@ -94,25 +93,20 @@ def incache(path):
True
"""

global __LOOKUP_CACHE

return path in __LOOKUP_CACHE


def lookup(path, cache=True):
"""Get element reference from input element.
:limitations: it does not resolve class methods
or static values such as True, False, numbers, string and keywords.
:limitations: it does not resolve class methods or static values such as
True, False, numbers, string and keywords.
:param str path: full path to a python element.
:param bool cache: if True (default), permits to reduce time complexity for
lookup resolution in using cache memory to save resolved elements.
:return: python object which is accessible through input path
or raise an exception if the path is wrong.
:rtype: object
:raises ImportError: if path is wrong
"""

Expand Down Expand Up @@ -158,7 +152,6 @@ def lookup(path, cache=True):
# try to import all sub-modules/packages
try: # check if name is defined from an external module
# find the right module

while index < components_len:
module_name = '{0}.{1}'.format(
module_name, components[index]
Expand All @@ -182,7 +175,6 @@ def lookup(path, cache=True):
)
)
else: # in case of PY26

if PY26:
index = 1
while index < components_len:
Expand Down
9 changes: 3 additions & 6 deletions b3j0f/utils/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
# SOFTWARE.
# --------------------------------------------------------------------

"""
Library which aims to bind named properties on any element at runtime.
"""Library which aims to bind named properties on any element at runtime.
This module can bind a named property on any element but None methods.
Expand Down Expand Up @@ -565,8 +564,7 @@ def put_properties(elt, properties, ttl=None, ctx=None):


def put(properties, ttl=None, ctx=None):
"""
Decorator dedicated to put properties on an element.
"""Decorator dedicated to put properties on an element.
"""

def put_on(elt):
Expand All @@ -576,8 +574,7 @@ def put_on(elt):


def del_properties(elt, keys=None, ctx=None):
"""
Delete elt property.
"""Delete elt property.
:param elt: properties elt to del. Not None methods.
:param keys: property keys to delete from elt. If empty, delete all
Expand Down
28 changes: 15 additions & 13 deletions b3j0f/utils/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def proxify_elt(elt, bases=None, _dict=None):
else: # fill proxy_dict with routines of bases
bases = tuple(bases)
for base in bases:
for name, member in getmembers(base, lambda m: isroutine(m)):
for name, member in getmembers(base, isroutine):
if not hasattr(elt, name):
raise TypeError(
"Wrong elt {0}. Must implement {1} ({2}) of {3}".
Expand Down Expand Up @@ -153,8 +153,8 @@ def proxify_routine(routine, impl=None):
except TypeError:
__file__ = '<string>'

isMethod = ismethod(routine)
if isMethod:
is_method = ismethod(routine)
if is_method:
function = routine.__func__
else:
function = routine
Expand Down Expand Up @@ -194,8 +194,8 @@ def function(*args, **kwargs):
name = function.__name__

# flag for lambda function
isLambda = __LAMBDA_NAME__ == function.__name__
if isLambda:
islambda = __LAMBDA_NAME__ == function.__name__
if islambda:
name = '_{0}'.format(int(time()))

# get join method for reducing concatenation time execution
Expand All @@ -204,7 +204,7 @@ def function(*args, **kwargs):
# default indentation
indent = ' '

if isLambda:
if islambda:
newcodestr = "{0} = lambda ".format(name)
else:
newcodestr = "def {0}(".format(name)
Expand All @@ -225,12 +225,14 @@ def function(*args, **kwargs):
newcodestr = join((newcodestr, "**{0}".format(kwargs)))

# insert impl call
if isLambda:
if islambda:
newcodestr = join((newcodestr, ": impl("))
else:
newcodestr = join((
newcodestr,
"):\n{0}return impl(".format(indent))
newcodestr = join(
(
newcodestr,
"):\n{0}return impl(".format(indent)
)
)

if args:
Expand Down Expand Up @@ -266,7 +268,7 @@ def function(*args, **kwargs):
if PY3:
newcode = list(newco.co_code)
else:
newcode = map(ord, newco.co_code)
newcode = [ord(co) for co in newco.co_code]

consts_values = {'impl': impl}

Expand All @@ -290,7 +292,7 @@ def function(*args, **kwargs):
index += 1

# get code string
codestr = bytes(newcode) if PY3 else join(map(chr, newcode))
codestr = bytes(newcode) if PY3 else join([chr(co) for co in newcode])

# get vargs
vargs = [
Expand Down Expand Up @@ -336,7 +338,7 @@ def function(*args, **kwargs):
# set proxyfied element on proxy
setattr(result, __PROXIFIED__, routine)

if isMethod: # create a new method
if is_method: # create a new method
args = [result, routine.__self__]
if PY2:
args.append(routine.im_class)
Expand Down
27 changes: 9 additions & 18 deletions b3j0f/utils/reflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,14 @@
# SOFTWARE.
# --------------------------------------------------------------------

"""
Python reflection tools.
"""Python reflection tools.
"""

from b3j0f.utils.version import PY2
from b3j0f.utils.iterable import ensureiterable

from inspect import isclass, isroutine, ismethod, getmodule

try:
from types import NoneType
except ImportError:
NoneType = type(None)

__all__ = ['base_elts', 'find_embedding', 'is_inherited']


Expand Down Expand Up @@ -197,17 +191,14 @@ def find_embedding(elt, embedding=None):

else:

try: # get embedded module
embedded_module = getmodule(embedded)
except Exception:
pass
else:
# and compare it with elt module
if embedded_module is module:
# add embedded to compounds
compounds.append(embedded)
# end the second loop
break
# get embedded module
embedded_module = getmodule(embedded)
# and compare it with elt module
if embedded_module is module:
# add embedded to compounds
compounds.append(embedded)
# end the second loop
break

else:
# remove last element if no coumpound element is found
Expand Down

0 comments on commit b1b8376

Please sign in to comment.