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

modules = \
['varname']
install_requires = \
['executing']

setup_kwargs = {
    'name': 'varname',
    'version': '0.5.2',
    'description': 'Dark magics about variable names in python.',
    'long_description': '![varname][7]\n\n[![Pypi][3]][4] [![Github][5]][6] [![PythonVers][8]][4] ![Building][10]\n[![Docs and API][9]][15] [![Codacy][12]][13] [![Codacy coverage][14]][13]\n[![Chat on gitter][17]][18]\n\nDark magics about variable names in python\n\n[Change Log][16] | [API][15]\n\n## Installation\n```shell\npip install varname\n```\n\n## Features\n\n- Fetching variable names from inside the function/class call using `varname`\n- Fetching variable names directly using `nameof`\n- A value wrapper to store the variable name that a value is assigned to using `Wrapper`\n- Detecting next immediate attribute name using `will`\n- Shortcut for `collections.namedtuple`\n- Injecting `__varname__` to objects\n\n## Credits\n\nThanks goes to these awesome people/projects:\n\n<table>\n  <tr>\n    <td align="center" style="min-width: 75px">\n      <a href="https://github.com/alexmojaki">\n        <img src="https://avatars0.githubusercontent.com/u/3627481?s=400&v=4" width="50px;" alt=""/>\n        <br /><sub><b>@alexmojaki</b></sub>\n      </a>\n    </td>\n    <td align="center" style="min-width: 75px">\n      <a href="https://github.com/alexmojaki/executing">\n        <img src="https://via.placeholder.com/50?text=executing" width="50px;" alt=""/>\n        <br /><sub><b>executing</b></sub>\n      </a>\n    </td>\n  </tr>\n</table>\n\nSpecial thanks to [@HanyuuLu][2] to give up the name `varname` in pypi for this project.\n\n## Usage\n\n### Retrieving the variable names from inside a function call/class instantiation\n\n- From insdie a function call\n    ```python\n    from varname import varname\n    def function():\n        return varname()\n\n    func = function()  # func == \'func\'\n    ```\n\n-  `varname` calls being buried deeply\n\n    ```python\n    def function():\n        # I know that at which stack this will be called\n        return varname(caller=3)\n\n    def function1():\n        return function()\n\n    def function2():\n        return function1()\n\n    func = function2()  # func == \'func\'\n    ```\n\n- Retrieving instance name of a class\n\n    ```python\n    class Foo:\n        def __init__(self):\n            self.id = varname()\n\n        def copy(self):\n            # also able to fetch inside a method call\n            copied = Foo() # copied.id == \'copied\'\n            copied.id = varname() # assign id to whatever variable name\n            return copied\n\n    k = Foo()   # k.id == \'k\'\n\n    k2 = k.copy() # k2.id == \'k2\'\n    ```\n\n- Some unusual use\n\n    ```python\n    func = [function()]    # func == [\'func\']\n\n    func = [function(), function()] # func == [\'func\', \'func\']\n\n    func = function(), function()   # func = (\'func\', \'func\')\n\n    func = func1 = function()  # func == func1 == \'func\'\n    # a warning will be printed\n    # since you may not want func1 to be \'func\'\n\n    x = func(y = func())  # x == \'x\'\n\n    # get part of the name\n    func_abc = function()[-3:]  # func_abc == \'abc\'\n\n    # function alias supported now\n    function2 = function\n    func = function2()  # func == \'func\'\n\n    a = lambda: 0\n    a.b = function() # a.b == \'b\'\n\n    # Since v0.1.3\n    # We can ask varname to raise exceptions\n    # if it fails to detect the variable name\n    def get_name(raise_exc):\n        return varname(raise_exc=raise_exc)\n\n    a = {}\n    a[\'b\'] = get_name(True) # VarnameRetrievingError\n    a[\'b\'] = get_name(False) # None\n    ```\n\n### Value wrapper\n\n```python\nfrom varname import Wrapper\n\nfoo = Wrapper(True)\n# foo.name == \'foo\'\n# foo.value == True\nbar = Wrapper(False)\n# bar.name == \'bar\'\n# bar.value == False\n\ndef values_to_dict(*args):\n    return {val.name: val.value for val in args}\n\nmydict = values_to_dict(foo, bar)\n# {\'foo\': True, \'bar\': False}\n```\n\n### Getting variable names directly\n\n```python\nfrom varname import varname, nameof\n\na = 1\nnameof(a) # \'a\'\n\nb = 2\nnameof(a, b) # (\'a\', \'b\')\n\ndef func():\n    return varname() + \'_suffix\'\n\nf = func() # f == \'f_suffix\'\nnameof(f)  # \'f\'\n\n# get full names of (chained) attribute calls\nfunc.a = func\nnameof(func.a, full=True) # \'func.a\'\n\nfunc.a.b = 1\nnameof(func.a.b, full=True) # \'func.a.b\'\n```\n\n### Detecting next immediate attribute name\n```python\nfrom varname import will\nclass AwesomeClass:\n    def __init__(self):\n        self.will = None\n\n    def permit(self):\n        self.will = will(raise_exc=False)\n        if self.will == \'do\':\n            # let self handle do\n            return self\n        raise AttributeError(\'Should do something with AwesomeClass object\')\n\n    def do(self):\n        if self.will != \'do\':\n            raise AttributeError("You don\'t have permission to do")\n        return \'I am doing!\'\n\nawesome = AwesomeClass()\nawesome.do() # AttributeError: You don\'t have permission to do\nawesome.permit() # AttributeError: Should do something with AwesomeClass object\nawesome.permit().do() == \'I am doing!\'\n```\n\n### Shortcut for `collections.namedtuple`\n```python\n# instead of\nfrom collections import namedtuple\nName = namedtuple(\'Name\', [\'first\', \'last\'])\n\n# we can do:\nfrom varname import namedtuple\nName = namedtuple([\'first\', \'last\'])\n```\n\n### Injecting `__varname__`\n\n```python\nfrom varname import inject\n\nclass MyList(list):\n    pass\n\na = inject(MyList())\nb = inject(MyList())\n\na.__varname__ == \'a\'\nb.__varname__ == \'b\'\n\na == b\n\n# other methods not affected\na.append(1)\nb.append(1)\na == b\n```\n\n## Reliability and limitations\n`varname` is all depending on `executing` package to look for the node.\nThe node `executing` detects is ensured to be the correct one (see [this][19]).\n\nIt partially works with environments where other AST magics apply, including\n`pytest`, `ipython`, `macropy`, `birdseye`, `reticulate` with `R`, etc. Neither\n`executing` nor `varname` is 100% working with those environments. Use\nit at your own risk.\n\nFor example:\n\n- This will not work with `pytest`:\n  ```python\n  a = 1\n  assert nameof(a) == \'a\'\n\n  # do this instead\n  name_a = nameof(a)\n  assert name_a == \'a\'\n  ```\n\n- `R` with `reticulate`.\n\n[1]: https://github.com/pwwang/python-varname\n[2]: https://github.com/HanyuuLu\n[3]: https://img.shields.io/pypi/v/varname?style=flat-square\n[4]: https://pypi.org/project/varname/\n[5]: https://img.shields.io/github/tag/pwwang/python-varname?style=flat-square\n[6]: https://github.com/pwwang/python-varname\n[7]: logo.png\n[8]: https://img.shields.io/pypi/pyversions/python-varname?style=flat-square\n[9]: https://img.shields.io/github/workflow/status/pwwang/python-varname/Build%20Docs?label=docs&style=flat-square\n[10]: https://img.shields.io/github/workflow/status/pwwang/python-varname/Build%20and%20Deploy?style=flat-square\n[12]: https://img.shields.io/codacy/grade/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square\n[13]: https://app.codacy.com/manual/pwwang/python-varname/dashboard\n[14]: https://img.shields.io/codacy/coverage/ed851ff47b194e3e9389b2a44d6f21da?style=flat-square\n[15]: https://pwwang.github.io/python-varname/api/varname\n[16]: https://pwwang.github.io/python-varname/CHANGELOG/\n[17]: https://img.shields.io/gitter/room/pwwang/python-varname?style=flat-square\n[18]: https://gitter.im/python-varname/community\n[19]: https://github.com/alexmojaki/executing#is-it-reliable\n',
    'author': 'pwwang',
    'author_email': 'pwwang@pwwang.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/pwwang/python-varname',
    'py_modules': modules,
    'install_requires': install_requires,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
