Add API docs

This commit is contained in:
Roman Mogilatov 2015-11-14 22:47:33 +02:00
parent da4976e3c7
commit ec6bd0c2c1
9 changed files with 55 additions and 87 deletions

View File

@ -1,62 +1,7 @@
dependency_injector.catalogs ``dependency_injector.catalogs``
---------------------------- --------------------------------
.. automodule:: dependency_injector.catalogs .. automodule:: dependency_injector.catalogs
:members:
Declarative catalog
-------------------
.. autoclass:: DeclarativeCatalog
:member-order: bysource
:members:
.. classmethod:: __getattr__(name)
Return provider with specified name or raise en error.
:param name: Attribute's name
:type name: str
:raise: dependency_injector.UndefinedProviderError
.. classmethod:: __setattr__(cls, name, value)
Handle setting of catalog attributes.
Setting of attributes works as usual, but if value of attribute is
provider, this provider will be bound to catalog correctly.
:param name: Attribute's name
:type name: str
:param value: Attribute's value
:type value: dependency_injector.Provider | object
:rtype: None
.. classmethod:: __delattr__(cls, name)
Handle deleting of catalog attibute.
Deleting of attributes works as usual, but if value of attribute is
provider, this provider will be unbound from catalog correctly.
:param name: Attribute's name
:type name: str
:rtype: None
.. classmethod:: __repr__(cls, name)
Return string representation of the catalog.
:rtype: str
Dynamic catalog
---------------
.. autoclass:: DynamicCatalog
:member-order: bysource
:members:
:special-members: :special-members:
:member-order: bysource

5
docs/api/errors.rst Normal file
View File

@ -0,0 +1,5 @@
``dependency_injector.errors``
------------------------------
.. automodule:: dependency_injector.errors
:members:

View File

@ -3,7 +3,10 @@ API
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 2
top_level
providers providers
catalogs catalogs
errors
utils

View File

@ -1,3 +1,8 @@
dependency_injector.providers ``dependency_injector.providers``
----------------------------- ---------------------------------
.. automodule:: dependency_injector.providers
:members:
:special-members:
:private-members:
:member-order: bysource

6
docs/api/top_level.rst Normal file
View File

@ -0,0 +1,6 @@
``dependency_injector``
-----------------------
.. automodule:: dependency_injector
:members:
:special-members:

5
docs/api/utils.rst Normal file
View File

@ -0,0 +1,5 @@
``dependency_injector.utils``
-----------------------------
.. automodule:: dependency_injector.utils
:members:

View File

@ -1,13 +1,13 @@
Declarative catalogs Declarative catalogs
-------------------- --------------------
``di.DeclarativeCatalog`` is a catalog of providers that could be defined in :py:class:`dependency_injector.catalogs.DeclarativeCatalog` is a catalog of
declarative manner. It should cover most of the cases when list of providers providers that could be defined in declarative manner. It should cover most
that would be included in catalog is deterministic (catalog will not change of the cases when list of providers that would be included in catalog is
its structure in runtime). deterministic (catalog will not change its structure in runtime).
Declarative catalogs have to extend base declarative catalog class - Declarative catalogs have to extend base declarative catalog class -
``di.DeclarativeCatalog``. :py:class:`dependency_injector.catalogs.DeclarativeCatalog`.
Providers have to be defined like catalog's class attributes. Every provider in Providers have to be defined like catalog's class attributes. Every provider in
catalog has name. This name should follow ``some_provider`` convention, catalog has name. This name should follow ``some_provider`` convention,
@ -15,7 +15,8 @@ that is standard naming convention for attribute names in Python.
.. note:: .. note::
It might be useful to add such ``""":type: di.Provider -> Object1"""`` It might be useful to add such
``""":type: dependency_injector.providers.Provider -> Object1"""``
docstrings just on the next line after provider's definition. It will docstrings just on the next line after provider's definition. It will
help code analyzing tools and IDE's to understand that variable above help code analyzing tools and IDE's to understand that variable above
contains some callable object, that returns particular instance as a contains some callable object, that returns particular instance as a
@ -30,9 +31,9 @@ Here is an simple example of declarative catalog with several factories:
.. literalinclude:: ../../examples/catalogs/declarative.py .. literalinclude:: ../../examples/catalogs/declarative.py
:language: python :language: python
``di.DeclarativeCatalog`` has several features that could be useful for some :py:class:`dependency_injector.catalogs.DeclarativeCatalog` has several
kind of operations on catalog's providers (please visit API docs for features that could be useful for some kind of operations on catalog's
getting full list of feautes - providers (please visit API docs for getting full list of feautes -
:py:class:`dependency_injector.catalogs.DeclarativeCatalog`): :py:class:`dependency_injector.catalogs.DeclarativeCatalog`):
Example: Example:

View File

@ -1,16 +1,17 @@
"""Declarative catalog example.""" """Declarative catalog example."""
import dependency_injector as di from dependency_injector import catalogs
from dependency_injector import providers
class Catalog(di.DeclarativeCatalog): class Catalog(catalogs.DeclarativeCatalog):
"""Providers catalog.""" """Providers catalog."""
factory1 = di.Factory(object) factory1 = providers.Factory(object)
""":type: di.Provider -> object""" """:type: providers.Provider -> object"""
factory2 = di.Factory(object) factory2 = providers.Factory(object)
""":type: di.Provider -> object""" """:type: providers.Provider -> object"""
# Creating some objects: # Creating some objects:
object1 = Catalog.factory1() object1 = Catalog.factory1()

View File

@ -1,20 +1,21 @@
"""Declarative catalog API example.""" """Declarative catalog API example."""
import dependency_injector as di from dependency_injector import catalogs
from dependency_injector import providers
class CatalogA(di.DeclarativeCatalog): class CatalogA(catalogs.DeclarativeCatalog):
"""Example catalog A.""" """Example catalog A."""
provider1 = di.Factory(object) provider1 = providers.Factory(object)
""":type: di.Provider -> object""" """:type: providers.Provider -> object"""
class CatalogB(CatalogA): class CatalogB(CatalogA):
"""Example catalog B.""" """Example catalog B."""
provider2 = di.Singleton(object) provider2 = providers.Singleton(object)
""":type: di.Provider -> object""" """:type: providers.Provider -> object"""
# Making some asserts for `providers` attribute: # Making some asserts for `providers` attribute:
@ -29,7 +30,3 @@ assert CatalogB.cls_providers == dict(provider2=CatalogB.provider2)
# Making some asserts for `inherited_providers` attribute: # Making some asserts for `inherited_providers` attribute:
assert CatalogA.inherited_providers == dict() assert CatalogA.inherited_providers == dict()
assert CatalogB.inherited_providers == dict(provider1=CatalogA.provider1) assert CatalogB.inherited_providers == dict(provider1=CatalogA.provider1)
# Making some asserts for `filter()` method:
assert CatalogB.filter(di.Factory) == dict(provider1=CatalogA.provider1)
assert CatalogB.filter(di.Singleton) == dict(provider2=CatalogB.provider2)