|
| 1 | +Objects |
| 2 | +======= |
| 3 | + |
| 4 | +Dependency management tool for Python projects. |
| 5 | + |
| 6 | ++---------------------------------------+-------------------------------------------------------------------+ |
| 7 | +| *PyPi* | .. image:: https://pypip.in/version/Objects/badge.svg | |
| 8 | +| | :target: https://pypi.python.org/pypi/Objects/ | |
| 9 | +| | :alt: Latest Version | |
| 10 | +| | .. image:: https://pypip.in/download/Objects/badge.svg | |
| 11 | +| | :target: https://pypi.python.org/pypi/Objects/ | |
| 12 | +| | :alt: Downloads | |
| 13 | +| | .. image:: https://pypip.in/license/Objects/badge.svg | |
| 14 | +| | :target: https://pypi.python.org/pypi/Objects/ | |
| 15 | +| | :alt: License | |
| 16 | ++---------------------------------------+-------------------------------------------------------------------+ |
| 17 | +| *Python versions and implementations* | .. image:: https://pypip.in/py_versions/Objects/badge.svg | |
| 18 | +| | :target: https://pypi.python.org/pypi/Objects/ | |
| 19 | +| | :alt: Supported Python versions | |
| 20 | +| | .. image:: https://pypip.in/implementation/Objects/badge.svg | |
| 21 | +| | :target: https://pypi.python.org/pypi/Objects/ | |
| 22 | +| | :alt: Supported Python implementations | |
| 23 | ++---------------------------------------+-------------------------------------------------------------------+ |
| 24 | +| *Builds and test coverage* | .. image:: https://travis-ci.org/rmk135/objects.svg?branch=master | |
| 25 | +| | :target: https://travis-ci.org/rmk135/objects | |
| 26 | +| | :alt: Build Status | |
| 27 | +| | .. image:: https://coveralls.io/repos/rmk135/objects/badge.svg | |
| 28 | +| | :target: https://coveralls.io/r/rmk135/objects | |
| 29 | +| | :alt: Coverage Status | |
| 30 | ++---------------------------------------+-------------------------------------------------------------------+ |
| 31 | + |
| 32 | +Introduction |
| 33 | +------------ |
| 34 | + |
| 35 | +Python ecosystem consists of a big amount of various classes, functions and |
| 36 | +objects that could be used for applications development. Each of them has its |
| 37 | +own role. |
| 38 | + |
| 39 | +Modern Python applications are mostly the composition of well-known open |
| 40 | +source systems, frameworks, libraries and some turnkey functionality. |
| 41 | + |
| 42 | +When application goes bigger, its amount of objects and their dependencies |
| 43 | +also increased extremely fast and became hard to maintain. |
| 44 | + |
| 45 | +**Objects** is designed to be developer's friendly tool for managing objects |
| 46 | +and their dependencies in formal, pretty way. Main idea of **Objects** is to |
| 47 | +keep dependencies under control. |
| 48 | + |
| 49 | +Installation |
| 50 | +------------ |
| 51 | + |
| 52 | +**Objects** library is available on PyPi_:: |
| 53 | + |
| 54 | + pip install objects |
| 55 | + |
| 56 | +Documentation |
| 57 | +------------- |
| 58 | + |
| 59 | +**Objects** documentation is hosted on ReadTheDocs: |
| 60 | + |
| 61 | +- `Stable version`_ |
| 62 | +- `Latest version`_ |
| 63 | + |
| 64 | +Examples |
| 65 | +-------- |
| 66 | + |
| 67 | +.. code-block:: python |
| 68 | +
|
| 69 | + """Concept example of `Objects`.""" |
| 70 | +
|
| 71 | + from objects.catalog import AbstractCatalog |
| 72 | +
|
| 73 | + from objects.providers import Singleton |
| 74 | + from objects.providers import NewInstance |
| 75 | +
|
| 76 | + from objects.injections import KwArg |
| 77 | + from objects.injections import Attribute |
| 78 | + from objects.injections import inject |
| 79 | +
|
| 80 | + import sqlite3 |
| 81 | +
|
| 82 | +
|
| 83 | + class ObjectA(object): |
| 84 | +
|
| 85 | + """Example class ObjectA, that has dependency on database.""" |
| 86 | +
|
| 87 | + def __init__(self, db): |
| 88 | + """Initializer.""" |
| 89 | + self.db = db |
| 90 | +
|
| 91 | +
|
| 92 | + class ObjectB(object): |
| 93 | +
|
| 94 | + """Example class ObjectB, that has dependencies on ObjectA and database.""" |
| 95 | +
|
| 96 | + def __init__(self, a, db): |
| 97 | + """Initializer.""" |
| 98 | + self.a = a |
| 99 | + self.db = db |
| 100 | +
|
| 101 | +
|
| 102 | + class Catalog(AbstractCatalog): |
| 103 | +
|
| 104 | + """Catalog of objects providers.""" |
| 105 | +
|
| 106 | + database = Singleton(sqlite3.Connection, |
| 107 | + KwArg('database', ':memory:'), |
| 108 | + Attribute('row_factory', sqlite3.Row)) |
| 109 | + """:type: (objects.Provider) -> sqlite3.Connection""" |
| 110 | +
|
| 111 | + object_a = NewInstance(ObjectA, |
| 112 | + KwArg('db', database)) |
| 113 | + """:type: (objects.Provider) -> ObjectA""" |
| 114 | +
|
| 115 | + object_b = NewInstance(ObjectB, |
| 116 | + KwArg('a', object_a), |
| 117 | + KwArg('db', database)) |
| 118 | + """:type: (objects.Provider) -> ObjectB""" |
| 119 | +
|
| 120 | +
|
| 121 | + # Catalog static provides. |
| 122 | + a1, a2 = Catalog.object_a(), Catalog.object_a() |
| 123 | + b1, b2 = Catalog.object_b(), Catalog.object_b() |
| 124 | +
|
| 125 | + assert a1 is not a2 |
| 126 | + assert b1 is not b2 |
| 127 | + assert a1.db is a2.db is b1.db is b2.db is Catalog.database() |
| 128 | +
|
| 129 | +
|
| 130 | + # Example of inline injections. |
| 131 | + @inject(KwArg('a', Catalog.object_a)) |
| 132 | + @inject(KwArg('b', Catalog.object_b)) |
| 133 | + @inject(KwArg('database', Catalog.database)) |
| 134 | + def example(a, b, database): |
| 135 | + assert a.db is b.db is database is Catalog.database() |
| 136 | +
|
| 137 | +
|
| 138 | + example() |
| 139 | +
|
| 140 | +You can get more **Objects** examples in ``/examples`` directory on |
| 141 | +GitHub: |
| 142 | + |
| 143 | + https://github.com/rmk135/objects |
| 144 | + |
| 145 | + |
| 146 | +Feedback |
| 147 | +-------- |
| 148 | + |
| 149 | +Feel free to post questions, bugs, feature requests, proposals etc. on |
| 150 | +**Objects** GitHub Issues: |
| 151 | + |
| 152 | + https://github.com/rmk135/objects/issues |
| 153 | + |
| 154 | +Your feedback is quite important! |
| 155 | + |
| 156 | + |
| 157 | +.. _PyPi: https://pypi.python.org/pypi/Objects |
| 158 | +.. _Stable version: http://objects.readthedocs.org/en/stable/ |
| 159 | +.. _Latest version: http://objects.readthedocs.org/en/latest/ |
0 commit comments