From 43a1a6cf3962dde8ee7980e52f08074b8e7ccaa9 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Wed, 29 Sep 2021 16:30:46 -0400 Subject: [PATCH] Update front example --- README.rst | 10 +++++----- docs/index.rst | 10 +++++----- docs/introduction/di_in_python.rst | 26 +++++++++++++------------- examples/demo/after.py | 6 +++--- examples/demo/before.py | 6 +++--- examples/demo/with_di.py | 11 +++++------ 6 files changed, 34 insertions(+), 35 deletions(-) diff --git a/README.rst b/README.rst index f6f27bbc..0b194d6e 100644 --- a/README.rst +++ b/README.rst @@ -80,7 +80,7 @@ Key features of the ``Dependency Injector``: .. code-block:: python from dependency_injector import containers, providers - from dependency_injector.wiring import inject, Provide + from dependency_injector.wiring import Provide, inject class Container(containers.DeclarativeContainer): @@ -104,11 +104,11 @@ Key features of the ``Dependency Injector``: ... - if __name__ == '__main__': + if __name__ == "__main__": container = Container() - container.config.api_key.from_env('API_KEY') - container.config.timeout.from_env('TIMEOUT') - container.wire(modules=[sys.modules[__name__]]) + container.config.api_key.from_env("API_KEY") + container.config.timeout.from_env("TIMEOUT") + container.wire(modules=[__name__]) main() # <-- dependency is injected automatically diff --git a/docs/index.rst b/docs/index.rst index 3cc5c295..afbee51e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -86,7 +86,7 @@ Key features of the ``Dependency Injector``: .. code-block:: python from dependency_injector import containers, providers - from dependency_injector.wiring import inject, Provide + from dependency_injector.wiring import Provide, inject class Container(containers.DeclarativeContainer): @@ -110,11 +110,11 @@ Key features of the ``Dependency Injector``: ... - if __name__ == '__main__': + if __name__ == "__main__": container = Container() - container.config.api_key.from_env('API_KEY') - container.config.timeout.from_env('TIMEOUT') - container.wire(modules=[sys.modules[__name__]]) + container.config.api_key.from_env("API_KEY") + container.config.timeout.from_env("TIMEOUT") + container.wire(modules=[__name__]) main() # <-- dependency is injected automatically diff --git a/docs/introduction/di_in_python.rst b/docs/introduction/di_in_python.rst index 80ede500..7c1a3cfd 100644 --- a/docs/introduction/di_in_python.rst +++ b/docs/introduction/di_in_python.rst @@ -67,8 +67,8 @@ Before: class ApiClient: def __init__(self): - self.api_key = os.getenv('API_KEY') # <-- dependency - self.timeout = os.getenv('TIMEOUT') # <-- dependency + self.api_key = os.getenv("API_KEY") # <-- dependency + self.timeout = os.getenv("TIMEOUT") # <-- dependency class Service: @@ -82,7 +82,7 @@ Before: ... - if __name__ == '__main__': + if __name__ == "__main__": main() After: @@ -109,12 +109,12 @@ After: ... - if __name__ == '__main__': + if __name__ == "__main__": main( service=Service( api_client=ApiClient( - api_key=os.getenv('API_KEY'), - timeout=os.getenv('TIMEOUT'), + api_key=os.getenv("API_KEY"), + timeout=os.getenv("TIMEOUT"), ), ), ) @@ -136,8 +136,8 @@ Now you need to assemble and inject the objects like this: main( service=Service( api_client=ApiClient( - api_key=os.getenv('API_KEY'), - timeout=os.getenv('TIMEOUT'), + api_key=os.getenv("API_KEY"), + timeout=os.getenv("TIMEOUT"), ), ), ) @@ -162,7 +162,7 @@ the dependency. .. code-block:: python from dependency_injector import containers, providers - from dependency_injector.wiring import inject, Provide + from dependency_injector.wiring import Provide, inject class Container(containers.DeclarativeContainer): @@ -186,11 +186,11 @@ the dependency. ... - if __name__ == '__main__': + if __name__ == "__main__": container = Container() - container.config.api_key.from_env('API_KEY') - container.config.timeout.from_env('TIMEOUT') - container.wire(modules=[sys.modules[__name__]]) + container.config.api_key.from_env("API_KEY") + container.config.timeout.from_env("TIMEOUT") + container.wire(modules=[__name__]) main() # <-- dependency is injected automatically diff --git a/examples/demo/after.py b/examples/demo/after.py index 1e8570c6..92240644 100644 --- a/examples/demo/after.py +++ b/examples/demo/after.py @@ -18,12 +18,12 @@ def main(service: Service): # <-- dependency is injected ... -if __name__ == '__main__': +if __name__ == "__main__": main( service=Service( api_client=ApiClient( - api_key=os.getenv('API_KEY'), - timeout=os.getenv('TIMEOUT'), + api_key=os.getenv("API_KEY"), + timeout=os.getenv("TIMEOUT"), ), ), ) diff --git a/examples/demo/before.py b/examples/demo/before.py index 832d4863..b7ca479b 100644 --- a/examples/demo/before.py +++ b/examples/demo/before.py @@ -4,8 +4,8 @@ import os class ApiClient: def __init__(self): - self.api_key = os.getenv('API_KEY') # <-- dependency - self.timeout = os.getenv('TIMEOUT') # <-- dependency + self.api_key = os.getenv("API_KEY") # <-- dependency + self.timeout = os.getenv("TIMEOUT") # <-- dependency class Service: @@ -19,5 +19,5 @@ def main() -> None: ... -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/examples/demo/with_di.py b/examples/demo/with_di.py index 094fdf52..9cb51e16 100644 --- a/examples/demo/with_di.py +++ b/examples/demo/with_di.py @@ -1,8 +1,7 @@ -import sys from unittest import mock from dependency_injector import containers, providers -from dependency_injector.wiring import inject, Provide +from dependency_injector.wiring import Provide, inject from after import ApiClient, Service @@ -28,11 +27,11 @@ def main(service: Service = Provide[Container.service]): ... -if __name__ == '__main__': +if __name__ == "__main__": container = Container() - container.config.api_key.from_env('API_KEY') - container.config.timeout.from_env('TIMEOUT') - container.wire(modules=[sys.modules[__name__]]) + container.config.api_key.from_env("API_KEY") + container.config.timeout.from_env("TIMEOUT") + container.wire(modules=[__name__]) main() # <-- dependency is injected automatically