examples codestyle fixes

This commit is contained in:
Roman Mogilatov 2015-03-10 00:54:05 +02:00
parent d48616736b
commit 4055b42e59
3 changed files with 56 additions and 49 deletions

View File

@ -1,31 +1,26 @@
""" """Callable provider examples."""
Callable provider examples.
"""
from objects import AbstractCatalog from objects import AbstractCatalog
from objects.providers import (
Singleton, from objects.providers import Singleton
Callable, from objects.providers import Callable
)
from objects.injections import ( from objects.injections import InitArg
Injection, from objects.injections import Attribute
InitArg, from objects.injections import Injection
Attribute,
)
import sqlite3 import sqlite3
# Some example function.
def consuming_function(arg, db): def consuming_function(arg, db):
"""Example function that has input arg and dependency on database."""
return arg, db return arg, db
# Catalog of objects providers.
class Catalog(AbstractCatalog): class Catalog(AbstractCatalog):
"""
Objects catalog. """Catalog of objects providers."""
"""
database = Singleton(sqlite3.Connection, database = Singleton(sqlite3.Connection,
InitArg('database', ':memory:'), InitArg('database', ':memory:'),

View File

@ -1,37 +1,39 @@
""" """Concept example of objects catalogs."""
Concept example of objects catalogs.
"""
from objects import AbstractCatalog from objects import AbstractCatalog
from objects.providers import (
Singleton, from objects.providers import Singleton
NewInstance, from objects.providers import NewInstance
)
from objects.injections import ( from objects.injections import InitArg
InitArg, from objects.injections import Attribute
Attribute,
)
import sqlite3 import sqlite3
# Some example classes.
class ObjectA(object): class ObjectA(object):
"""Example class ObjectA, that has dependency on database."""
def __init__(self, db): def __init__(self, db):
"""Initializer."""
self.db = db self.db = db
class ObjectB(object): class ObjectB(object):
"""Example class ObjectB, that has dependencies on ObjectA and database."""
def __init__(self, a, db): def __init__(self, a, db):
"""Initializer."""
self.a = a self.a = a
self.db = db self.db = db
# Catalog of objects providers.
class Catalog(AbstractCatalog): class Catalog(AbstractCatalog):
"""
Objects catalog. """Catalog of objects providers."""
"""
database = Singleton(sqlite3.Connection, database = Singleton(sqlite3.Connection,
InitArg('database', ':memory:'), InitArg('database', ':memory:'),
@ -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. # Dependencies injection (The Python Way) into class.
class Consumer(object): class Consumer(object):
"""Example consumer class."""
dependencies = Catalog(Catalog.object_a, dependencies = Catalog(Catalog.object_a,
Catalog.object_b) Catalog.object_b)
def test(self): def example(self):
"""Example method."""
a1 = self.dependencies.object_a() a1 = self.dependencies.object_a()
a2 = self.dependencies.object_a() a2 = self.dependencies.object_a()
@ -83,12 +88,14 @@ class Consumer(object):
else: else:
raise Exception('Database is not listed as a dependency') raise Exception('Database is not listed as a dependency')
Consumer().test()
Consumer().example()
# Dependencies injection (The Python Way) into a callback. # Dependencies injection (The Python Way) into a callback.
def consumer_callback(dependencies=Catalog(Catalog.object_a, def consumer_callback(dependencies=Catalog(Catalog.object_a,
Catalog.object_b)): Catalog.object_b)):
"""Example function."""
a1 = dependencies.object_a() a1 = dependencies.object_a()
a2 = dependencies.object_a() a2 = dependencies.object_a()

View File

@ -1,6 +1,4 @@
""" """CLI Commands."""
CLI Commands.
"""
import os import os
from setup import version from setup import version
@ -12,9 +10,7 @@ manager = Manager()
@manager.command @manager.command
def publish(with_tag=True): def publish(with_tag=True):
""" """Publish current version to PyPi."""
Publishes current version to PyPi.
"""
os.system('python setup.py sdist upload') os.system('python setup.py sdist upload')
if with_tag: if with_tag:
tag() tag()
@ -22,12 +18,21 @@ def publish(with_tag=True):
@manager.command @manager.command
def tag(): def tag():
""" """Make tag from current version."""
Makes tag from current version.
"""
os.system('git tag -a {0} -m \'version {0}\''.format(version)) os.system('git tag -a {0} -m \'version {0}\''.format(version))
os.system('git push --tags') 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__': if __name__ == '__main__':
manager.main() manager.main()