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

packages = \
['registerer']

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

setup_kwargs = {
    'name': 'registerer',
    'version': '0.5.0',
    'description': 'Everything you need to implement maintainable and easy to use registry patterns in your project.',
    'long_description': '# Registerer\n[![pypi](https://img.shields.io/pypi/v/registerer.svg)](https://pypi.python.org/pypi/registerer/)\n[![ci](https://github.com/danialkeimasi/python-registerer/workflows/tests/badge.svg)](https://github.com/danialkeimasi/python-registerer/actions)\n[![codecov](https://codecov.io/gh/danialkeimasi/python-registerer/branch/main/graph/badge.svg?token=Q5MG14RKJL)](https://codecov.io/gh/danialkeimasi/python-registerer)\n[![license](https://img.shields.io/github/license/danialkeimasi/python-registerer.svg)](https://github.com/danialkeimasi/python-registerer/blob/master/LICENSE)\n\n\nImplement maintainable and easy to use registry patterns in your project.\n\nTLDR; Write this:\n```python\nimport registerer\n\ncommand_handler_registry = registerer.Registerer()\n\n\n@command_handler_registry.register()\ndef hello(args):\n    return "hello to you too"\n\n\n@command_handler_registry.register()\ndef info(args):\n    return "how can i help you?"\n\n\n@command_handler_registry.register()\ndef play(args):\n    return "let me play a song for you"\n\n\ncommand = "info"\nargs = {}\nassert command_handler_registry[command](args) == "how can i help you?"\n```\nInstead of this, which violates the Open-Closed Principle (OCP):\n```python\n\n\ndef hello2(args):\n    return "hello to you too"\n\n\ndef info2(args):\n    return "how can i help you?"\n\n\ndef play2(args):\n    return "let me play a song for you"\n\n\ndef command_handler(command, args):\n    if command == "hello":\n        return hello2(args)\n    if command == "info":\n        return info2(args)\n    if command == "play":\n        return play2(args)\n\n\ncommand = "info"\nargs = {}\nassert command_handler(command, args) == "how can i help you?"\n```\n## Installation\n\n```sh\npip install registerer\n```\n\n## Usage\n\nIn order to use registerer, you need to instantiate from the `registerer.Registerer`.\n\nThere is several optional arguments you can pass to the `Registerer` constructor\nto manage how registry object should behave (Read more in reference section).\n\nlet\'s create a registry:\n```python\n\nimport abc\nimport typing\n\n\nclass Animal(abc.ABC):\n    slug: str\n    is_wild: bool\n\n    def walk(self):\n        pass\n\n\n# Animal class registry\nanimal_registry = registerer.Registerer(\n    parent_class=Animal,\n    max_size=5,  # only 5 items can register\n    slug_attr="slug",  # set the slug of item as attribute on it\n    validators=[\n        registerer.RegistryValidator(\n            lambda item: item.is_wild is False,  # check passed if returns True\n            error="can\'t register wild animal.",\n        ),\n    ],\n)\n\n\n```\nNow with `animal_registry` you can register your classes:\n```python\n\n\n# use the name of class as unique identifier:\n@animal_registry.register()\nclass Sheep(Animal):\n    is_wild = False\n\n    def walk(self):\n        return "sheep walks"\n\n\n# use your custom slug as unique identifier:\n@animal_registry.register("kitty")\nclass Cat(Animal):\n    is_wild = False\n\n    def walk(self):\n        return "cat walks"\n\n\nassert animal_registry["Sheep"] == Sheep\nassert animal_registry["kitty"] == Cat\n\nassert animal_registry.items == [Sheep, Cat]\nassert animal_registry._registry_dict == {"Sheep": Sheep, "kitty": Cat}\n\nassert animal_registry["Sheep"]().walk() == "sheep walks"\nassert animal_registry["kitty"]().walk() == "cat walks"\n```\nThe `register` method will also set an attribute on the registered item as `registry_slug`.\nYou can change the attribute name when creating the Registerer object.\nSo, in last example we have:\n\n```python\nassert Cat.slug == "kitty"\nassert animal_registry["kitty"].slug == "kitty"\n\n```\nif you need to add attributes on the registered item on registration (it\'s optional), you can pass kwargs to the `register` method.  \nThis is useful when registering functions. for example:\n```python\n\n# function registry\ntest_database_registry = registerer.Registerer(\n    validators=[\n        registerer.RegistryValidator(\n            lambda item: item.db_type == "test",\n        ),\n    ]\n)\n\n# use the name of function as unique identifier:\n@test_database_registry.register(db_type="test")\ndef sqlite(name: str):\n    return f"sqlite connection {name}"\n\n\n# use your custom slug as unique identifier:\n@test_database_registry.register("postgresql", db_type="test")\ndef postgresql_test(name: str):\n    return f"postgresql connection {name}"\n\n\nassert test_database_registry["sqlite"]("quera") == f"sqlite connection quera"\nassert test_database_registry["postgresql"]("quera") == f"postgresql connection quera"\n\n```\n### Exceptions\n\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/exceptions.py#L0"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n#### <kbd>module</kbd> `registerer.exceptions`\n\n\n\n\n\n\n---\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/exceptions.py#L1"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n##### <kbd>class</kbd> `RegistryCreationError`\nErrors that occurs on creating a registry object. \n\n\n\n\n\n---\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/exceptions.py#L7"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n##### <kbd>class</kbd> `RegistrationError`\nErrors that occurs on registering new item. \n\n\n\n\n\n---\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/exceptions.py#L13"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\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## Reference\n\nHere is all the things you can do with the `Registerer` class:\n\n\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/registry.py#L14"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n### <kbd>class</kbd> `Registerer`\nA utility that can be used to create a registry object to register class or functions. \n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/registry.py#L17"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n### <kbd>method</kbd> `Registerer.__init__`\n\n```python\n__init__(\n    parent_class: Optional[Type[~T]] = None,\n    slug_attr: Optional[str] = None,\n    max_size: Optional[int] = None,\n    validators: Optional[List[registerer.validators.RegistryValidator]] = None\n)\n```\n\n\n\n**Args:**\n \n - <b>`parent_class`</b>:  The class of parent.  If you set this, the registered class should be subclass of the this,  If it\'s not the register method going to raise RegistrationError.  Also by setting this you\'ll be benefit from type hints in your IDE. \n - <b>`slug_attr`</b>:  Pass the attribute name of registered item that you want to  set registry slug to or read from registered item. \n - <b>`max_size`</b>:  allowed size of registered items.  Defaults to None which means there is no limit. \n - <b>`validators`</b>:  custom validation for on registering items. \n\n\n\n**Raises:**\n \n - <b>`RegistryCreationError`</b>:  Can\'t create proper registry object. \n\n\n---\n\n##### <kbd>property</kbd> Registerer.items\n\nget actual registered items as list (classes or functions) \n\n\n\n---\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/registry.py#L60"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\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<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/registry.py#L96"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n#### <kbd>method</kbd> `Registerer.register`\n\n```python\nregister(custom_slug: Optional[str] = None, **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**Args:**\n \n - <b>`custom_slug`</b> (str):  the unique identifier for the item. \n\n\n\n**Raises:**\n \n - <b>`ItemAlreadyRegistered`</b>:  There is another item already registered with this slug. \n - <b>`RegistrationError`</b>:  can\'t register this item. \n\n---\n\n<a href="https://github.com/danialkeimasi/python-registerer/tree/main/registerer/registry.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>\n\n#### <kbd>method</kbd> `Registerer.validate`\n\n```python\nvalidate(item: Type[~T])\n```\n\nvalidate the item during registration. \n\n\n\n**Args:**\n \n - <b>`item`</b> (T):  item want to register. \n\n\n\n**Raises:**\n \n - <b>`RegistrationError`</b>:  can\'t register this item. \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.7,<4.0',
}


setup(**setup_kwargs)
