mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 03:36:41 +03:00
Merge branch 'release/3.6.1' into master
This commit is contained in:
commit
a4bb5514b1
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
3.6.1
|
||||
-----
|
||||
- Regenerate C sources using Cython 0.26.
|
||||
|
||||
3.6.0
|
||||
-----
|
||||
- Add ``CallableDelegate`` provider.
|
||||
|
|
41
examples/miniapps/mail_service/container.py
Normal file
41
examples/miniapps/mail_service/container.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
"""Mail service and user registration DI container example."""
|
||||
|
||||
from dependency_injector.containers import DeclarativeContainer
|
||||
from dependency_injector.providers import Callable, Singleton
|
||||
|
||||
import example
|
||||
|
||||
|
||||
class Container(DeclarativeContainer):
|
||||
"""DI container."""
|
||||
|
||||
mail_service = Singleton(example.MailService,
|
||||
host='localhost',
|
||||
port=587,
|
||||
login='my_login',
|
||||
password='super_secret_password')
|
||||
|
||||
add_user = Callable(example.add_user,
|
||||
mailer=mail_service)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Using real mail service:')
|
||||
Container.add_user('sample@mail.com', 'password')
|
||||
# Using real mail service:
|
||||
# Connecting server localhost:587 with my_login:super_secret_password
|
||||
# Sending "Your password is password" to "sample@mail.com"
|
||||
|
||||
print('Using mail service stub:')
|
||||
Container.add_user('sample@mail.com', 'password',
|
||||
mailer=example.MailServiceStub())
|
||||
# Using mail service stub:
|
||||
# Emulating sending "Your password is password" to "sample@mail.com"
|
||||
|
||||
# Also you can override provider by another provider:
|
||||
Container.mail_service.override(Singleton(example.MailServiceStub))
|
||||
print('Using mail service stub by overriding mail service provider:')
|
||||
Container.add_user('sample@mail.com', 'password')
|
||||
# Using mail service stub by overriding mail service provider:
|
||||
# Emulating sending "Your password is password" to "sample@mail.com"
|
||||
Container.mail_service.reset_override() # Resetting provider overriding
|
39
examples/miniapps/mail_service/example.py
Normal file
39
examples/miniapps/mail_service/example.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
"""Mail service and user registration example."""
|
||||
|
||||
|
||||
class AbstractMailService(object):
|
||||
"""Abstract mail service."""
|
||||
|
||||
def send(self, email, body):
|
||||
"""Send email."""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class MailService(AbstractMailService):
|
||||
"""Mail service."""
|
||||
|
||||
def __init__(self, host, port, login, password):
|
||||
"""Initializer."""
|
||||
self._host = host
|
||||
self._port = port
|
||||
self._login = login
|
||||
self._password = password
|
||||
|
||||
def send(self, email, body):
|
||||
"""Send email."""
|
||||
print('Connecting server {0}:{1} with {2}:{3}'.format(
|
||||
self._host, self._port, self._login, self._password))
|
||||
print('Sending "{0}" to "{1}"'.format(body, email))
|
||||
|
||||
|
||||
class MailServiceStub(AbstractMailService):
|
||||
"""Mail service stub."""
|
||||
|
||||
def send(self, email, body):
|
||||
"""Send email."""
|
||||
print('Emulating sending "{0}" to "{1}"'.format(body, email))
|
||||
|
||||
|
||||
def add_user(email, password, mailer):
|
||||
"""Register user."""
|
||||
mailer.send(email, 'Your password is {0}'.format(password))
|
|
@ -1,4 +1,4 @@
|
|||
cython
|
||||
cython==0.26
|
||||
tox
|
||||
unittest2
|
||||
coverage
|
||||
|
|
12
setup.py
12
setup.py
|
@ -7,7 +7,8 @@ from setuptools import setup, Extension
|
|||
|
||||
|
||||
# Defining setup variables:
|
||||
defined_macros = list()
|
||||
defined_macros = dict()
|
||||
defined_macros['CYTHON_CLINE_IN_TRACEBACK'] = 0
|
||||
|
||||
# Getting description:
|
||||
with open('README.rst') as readme_file:
|
||||
|
@ -23,8 +24,9 @@ with open('src/dependency_injector/__init__.py') as init_file:
|
|||
|
||||
# Adding debug options:
|
||||
if os.environ.get('DEPENDENCY_INJECTOR_DEBUG_MODE') == '1':
|
||||
defined_macros.append(('CYTHON_TRACE', 1))
|
||||
defined_macros.append(('CYTHON_TRACE_NOGIL', 1))
|
||||
defined_macros['CYTHON_TRACE'] = 1
|
||||
defined_macros['CYTHON_TRACE_NOGIL'] = 1
|
||||
defined_macros['CYTHON_CLINE_IN_TRACEBACK'] = 1
|
||||
|
||||
|
||||
setup(name='dependency-injector',
|
||||
|
@ -47,11 +49,11 @@ setup(name='dependency-injector',
|
|||
ext_modules=[
|
||||
Extension('dependency_injector.containers',
|
||||
['src/dependency_injector/containers.c'],
|
||||
define_macros=defined_macros,
|
||||
define_macros=list(defined_macros.items()),
|
||||
extra_compile_args=['-O2']),
|
||||
Extension('dependency_injector.providers',
|
||||
['src/dependency_injector/providers.c'],
|
||||
define_macros=defined_macros,
|
||||
define_macros=list(defined_macros.items()),
|
||||
extra_compile_args=['-O2']),
|
||||
],
|
||||
package_data={
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Dependency injector top-level package."""
|
||||
|
||||
__version__ = '3.6.0'
|
||||
__version__ = '3.6.1'
|
||||
"""Version number that follows semantic versioning.
|
||||
|
||||
:type: str
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user