diff --git a/examples/callable_provider.py b/examples/callable_provider.py index efc9f58c..df1c31ac 100644 --- a/examples/callable_provider.py +++ b/examples/callable_provider.py @@ -1,40 +1,35 @@ -""" -Callable provider examples. -""" +"""Callable provider examples.""" + from objects import AbstractCatalog -from objects.providers import ( - Singleton, - Callable, -) -from objects.injections import ( - Injection, - InitArg, - Attribute, -) + +from objects.providers import Singleton +from objects.providers import Callable + +from objects.injections import InitArg +from objects.injections import Attribute +from objects.injections import Injection import sqlite3 -# Some example function. def consuming_function(arg, db): + """Example function that has input arg and dependency on database.""" return arg, db -# Catalog of objects providers. class Catalog(AbstractCatalog): - """ - Objects catalog. - """ + + """Catalog of objects providers.""" database = Singleton(sqlite3.Connection, InitArg('database', ':memory:'), Attribute('row_factory', sqlite3.Row)) - """ :type: (objects.Provider) -> sqlite3.Connection """ + """:type: (objects.Provider) -> sqlite3.Connection""" consuming_function = Callable(consuming_function, Injection('db', database)) - """ :type: (objects.Provider) -> consuming_function """ + """:type: (objects.Provider) -> consuming_function""" # Some calls. diff --git a/examples/concept.py b/examples/concept.py index db12e2b7..9ec87415 100644 --- a/examples/concept.py +++ b/examples/concept.py @@ -1,51 +1,53 @@ -""" -Concept example of objects catalogs. -""" +"""Concept example of objects catalogs.""" + from objects import AbstractCatalog -from objects.providers import ( - Singleton, - NewInstance, -) -from objects.injections import ( - InitArg, - Attribute, -) + +from objects.providers import Singleton +from objects.providers import NewInstance + +from objects.injections import InitArg +from objects.injections import Attribute import sqlite3 -# Some example classes. class ObjectA(object): + + """Example class ObjectA, that has dependency on database.""" + def __init__(self, db): + """Initializer.""" self.db = db class ObjectB(object): + + """Example class ObjectB, that has dependencies on ObjectA and database.""" + def __init__(self, a, db): + """Initializer.""" self.a = a self.db = db -# Catalog of objects providers. class Catalog(AbstractCatalog): - """ - Objects catalog. - """ + + """Catalog of objects providers.""" database = Singleton(sqlite3.Connection, InitArg('database', ':memory:'), Attribute('row_factory', sqlite3.Row)) - """ :type: (objects.Provider) -> sqlite3.Connection """ + """:type: (objects.Provider) -> sqlite3.Connection""" object_a = NewInstance(ObjectA, InitArg('db', database)) - """ :type: (objects.Provider) -> ObjectA """ + """:type: (objects.Provider) -> ObjectA""" object_b = NewInstance(ObjectB, InitArg('a', object_a), InitArg('db', database)) - """ :type: (objects.Provider) -> ObjectB """ + """:type: (objects.Provider) -> ObjectB""" # Catalog static provides. @@ -61,10 +63,13 @@ assert a1.db is a2.db is b1.db is b2.db is Catalog.database() # Dependencies injection (The Python Way) into class. class Consumer(object): + """Example consumer class.""" + dependencies = Catalog(Catalog.object_a, Catalog.object_b) - def test(self): + def example(self): + """Example method.""" a1 = self.dependencies.object_a() a2 = self.dependencies.object_a() @@ -83,12 +88,14 @@ class Consumer(object): else: raise Exception('Database is not listed as a dependency') -Consumer().test() + +Consumer().example() # Dependencies injection (The Python Way) into a callback. def consumer_callback(dependencies=Catalog(Catalog.object_a, Catalog.object_b)): + """Example function.""" a1 = dependencies.object_a() a2 = dependencies.object_a() diff --git a/manage.py b/manage.py index 98071a46..832bfe7b 100644 --- a/manage.py +++ b/manage.py @@ -1,6 +1,4 @@ -""" -CLI Commands. -""" +"""CLI Commands.""" import os from setup import version @@ -12,9 +10,7 @@ manager = Manager() @manager.command def publish(with_tag=True): - """ - Publishes current version to PyPi. - """ + """Publish current version to PyPi.""" os.system('python setup.py sdist upload') if with_tag: tag() @@ -22,12 +18,21 @@ def publish(with_tag=True): @manager.command def tag(): - """ - Makes tag from current version. - """ + """Make tag from current version.""" os.system('git tag -a {0} -m \'version {0}\''.format(version)) os.system('git push --tags') +@manager.command +def check(): + """Check `objects` library and examples with code analyzers.""" + os.system('pylint objects/') + os.system('flake8 objects/') + os.system('pep257 objects/') + + os.system('pylint examples/') + os.system('flake8 examples/') + os.system('pep257 examples/') + if __name__ == '__main__': manager.main()