# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['registerer']

package_data = \
{'': ['*']}

setup_kwargs = {
    'name': 'registerer',
    'version': '0.3.0',
    'description': 'Everything you need to implement maintainable and easy to use registry patterns in your project.',
    'long_description': '# Registerer\n[![](https://img.shields.io/pypi/v/registerer.svg)](https://pypi.python.org/pypi/registerer/)\n[![](https://github.com/danialkeimasi/python-registerer/workflows/tests/badge.svg)](https://github.com/danialkeimasi/python-registerer/actions)\n[![](https://img.shields.io/github/license/danialkeimasi/python-registerer.svg)](https://github.com/danialkeimasi/python-registerer/blob/master/LICENSE)\n\nEverything you need to implement maintainable and easy to use registry patterns in your project.\n# Installation\n\n```sh\npip install registerer\n```\n\n\n## Examples\n\n### Register a Function With Validator\n\n```python\nimport registerer\n\ndatabase_registry = registerer.Registerer(\n    validators=[registerer.RegistryValidator(lambda item: not getattr(item, "fail", False))]\n)\n\n# success:\n@database_registry.register("sqlite")\ndef sqlite_database_connection(name: str):\n    return f"sqlite connection {name}"\n\n\n# failure:\n# registerer.exceptions.RegistrationError: custom validation failed when registering postgres_database_connection\n@database_registry.register("postgres", fail=True)\ndef postgres_database_connection(name: str):\n    return f"postgres connection {name}"\n\n\ndef main():\n    print(database_registry["postgres"]("personal"))  # postgres connection personal\n\n\nif __name__ == "__main__":\n    main()\n\n```\n\n### Register a Function\n\n```python\n# Register functions:\n\nfrom registerer import Registerer\n\ndatabase_registry = Registerer()\n\n\n@database_registry.register\ndef sqlite():\n    return "sqlite connection"\n\n\n@database_registry.register("postgres")\ndef postgres_backup():\n    return "postgres connection"\n\n\ndef main():\n    print(database_registry["sqlite"]())  # sqlite connection\n    print(database_registry["postgres"]())  # postgres connection\n\n\nif __name__ == "__main__":\n    main()\n\n```\n\n### Register a Class With Custom Validator\n\n```python\nimport registerer\n\n\nclass Animal:\n    is_wild: bool = None\n\n\ndomestic_animals_registry = registerer.Registerer(\n    Animal,\n    max_size=4,\n    validators=[\n        registerer.RegistryValidator(\n            lambda item: not item.is_wild,\n            error="only domestic animals allowed.",  # Optional\n        ),\n    ],\n)\n\n\n# success:\n@domestic_animals_registry.register("cow")\nclass Cow(Animal):\n    is_wild = False\n\n\n# failure:\n# raises registerer.exceptions.RegistrationError: Lion is wild, only domestic animals are allowed to register.\n@domestic_animals_registry.register("lion")\nclass Lion(Animal):\n    is_wild = True\n\n```\n\n### Register a Class\n\n```python\n# Register classes with the same interface,\n# enforce the type check and enjoy the benefits of type hints:\n\n\nfrom registerer import Registerer\n\n\nclass Animal:\n    def talk(self) -> None:\n        raise NotImplementedError\n\n\n# create a registry that requires registered items to implement the Animal interface:\nanimal_registry = Registerer(Animal)\n\n\n@animal_registry.register("dog")\nclass Dog(Animal):\n    def talk(self) -> None:\n        return "woof"\n\n\ndef main():\n    print(animal_registry["dog"])  # <class \'__main__.Dog\'>\n    print(animal_registry["dog"]())  # <__main__.Dog object at 0x7f108ad37d60>\n    print(animal_registry["dog"]().talk())  # woof\n\n\nif __name__ == "__main__":\n    main()\n\n```\n\n## Reference\n\n\n### <kbd>module</kbd> `registerer.registry`\n\n\n\n\n\n\n---\n\n#### <kbd>class</kbd> `Registerer`\nA utility that can be used to create a registry object to register class or functions. \n\n### <kbd>method</kbd> `Registerer.__init__`\n\n```python\n__init__(\n    parent_item: Optional[Type[~Type]] = None,\n    max_size: int = None,\n    validators: Optional[List] = None\n)\n```\n\n\n\n**Args:**\n \n - <b>`parent_item`</b>:  The class of parent. Defaults to None. \n - <b>`max_size`</b>:  allowed size of registered items. Defaults to None. \n - <b>`validators`</b>:  validate each item on register. Defaults to None. \n\n\n---\n\n###### <kbd>property</kbd> Registerer.items\n\nget actual registered items (classes or functions) \n\n\n\n---\n\n##### <kbd>method</kbd> `Registerer.is_registered`\n\n```python\nis_registered(slug: str) → bool\n```\n\nis the slug registered? \n\n---\n\n##### <kbd>method</kbd> `Registerer.register`\n\n```python\nregister(*args, **kwargs)\n```\n\nregister a class or item to the registry \n\n**example:**\n \n\n```python\n# register the item with it\'s name\n@registry.register\nclass Foo:\n     pass\n\nassert registry["Foo"] == Foo\n\n\n# register the item with a custom name\n@registry.register("bar")\nclass Bar:\n     pass\n\nassert registry["bar"] == Bar\n\n\n# register the item with a custom name and also add some other attributes to it.\n# it is more useful when registering functions.\n@db_registry.register("postgresql", env="prod")\ndef postgresql_connection:\n     pass\n\nassert registry["postgresql"] == postgresql_connection\nassert postgresql_connection.env == "prod"\n\n``` \n\n---\n\n##### <kbd>method</kbd> `Registerer.validate`\n\n```python\nvalidate(item: ~Type)\n```\n\nvalidate the item during registration. \n\n\n\n**Args:**\n \n - <b>`item`</b> (Type):  item want to register. \n\n\n\n**Raises:**\n \n - <b>`RegistrationError`</b>:  can\'t register this item. \n\n\n\n\n\n\n### <kbd>module</kbd> `registerer.validators`\n\n\n\n\n\n\n---\n\n#### <kbd>class</kbd> `RegistryValidator`\na utility for custom validation with the Registerer. you can subclass this and override the on_register method, and raise an exception if you must. \n\n\n\n**examples:**\n \n\n```python\n\n\n### <kbd>method</kbd> `RegistryValidator.__init__`\n\n```python\n__init__(validator, error: str = None) → None\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n### <kbd>module</kbd> `registerer.exceptions`\n\n\n\n\n\n\n---\n\n#### <kbd>class</kbd> `RegistrationError`\nErrors that occurs on registering new item. \n\n\n\n\n\n---\n\n#### <kbd>class</kbd> `ItemAlreadyRegistered`\nYou\'ve registered a item with duplicate identifier. \n\n\n\n\n\n---\n\n#### <kbd>class</kbd> `ItemNotRegistered`\nYou\'ve tried to get a item that is not registered. \n\n\n\n\n\n\n\n',
    'author': 'Danial Keimasi',
    'author_email': 'danialkeimasi@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/danialkeimasi/python-registerer',
    'packages': packages,
    'package_data': package_data,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
