{ "info": { "author": "bnbdr", "author_email": "bad.32@outlook.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "argz\n'''\n========\n\nArgument parsing for the lazy.\n\nCore Concepts\n-------------\n- Simplicity over robustness\n- Your script _requires_ arguments\n- \"Consumers\" of scripts using this are devlopers themselves\n\nUsage\n-----\n```python\n# $ cat example.py\nimport json\n\ndef func(jsondict, dbg=False):\n \"\"\"\n put descriptive docstring here\n \"\"\"\n pass # use jsondict\n\nif __name__ == '__main__':\n import argz\n f = argz.route(func)\n f.jsondict.adapter = [open, json.load] # will be chained\n argz.go() # will use sys.argv as input\n```\nRunning:\n```console\n$ example.py\n\nUsage:\nexample.py jsondict [-dbg]\n\nfor detailed help, use any of (-h, /h, -?, /?, /help, --help)\n```\n```console\n$ example.py -h\n|> jsondict [-dbg]\n|\n| jsondict\n| adapter | [, ]\n| dbg\n| default | False\n| adapter | \n|\n|- - doc - -\n|\n| put descriptive docstring here\n|_ _ _ _ _ _\n```\n\n\nInstallation\n------------\nDownload the file or use pip:\n```\npip install argz\n```\n\n\nPassing Arguments: Named vs Positional\n--------------------------------------\nYou can pass any argument by name or by position.\nAn argument will be treated as named if it starts with a double dash `--`, otherwise* as positional.\n\nYou can pass a mishmash of positional and named arguments, because `argz` will keep track of which arguments are left to parse according to the order in the function's definition.\n\n\\* except for [switches](#Switches)\n\nArguments From File\n-------------------\nTo pass arguments from a file to your script you can prefix its path with `@`. This must be the first argument passed to the script. If there are multiple routes the route name must be included in the file as the first argument.\n\nCurrently `argz` does not allow a mixture of file input and command line input.\n\n\nAdapter\n-------\nA callable object that accepts the string argument and returns the 'adapted' value, which will passed later to the routed function.\n\nIf the adapter is instead a sequence, each will be chained so that the return value of the former is passed to the latter, using the last returned value as input to the routed function.\n\nTo abort the parsing process, you may raise any exception. The `message` property will be printed to the user.\n\n\nValidator\n---------\nUsed to validate the input before any adapting is done. Can be one of the following types:\n- regex string: will be used to match against the input\n- callable object: will be called with the input string. Any exception or non-truthy value will abort the parsing process and display a message to the user.\n- Any object that implements `__contains__`\n```python\ndef func(alphanum, filepath, key, novalidation):\n \"\"\"\n put descriptive docstring here\n \"\"\"\n pass\n\n# ...\nf = argz.route(func)\n\nf.alphanum.validator = '[a-zA-Z0-9]{2,}'\nf.filepath.validator = os.path.isfile\nf.key.validator = {'option1': 1, 'option2': 2}\n\nargz.go()\n```\n\nMin / Max\n---------\nYou can set a minimum and/or maximum value for an argument:\n\n```python\ndef func(count):\n \"\"\"\n put descriptive docstring here\n \"\"\"\n pass\n\n# ...\nf = argz.route(func)\nf.count.min = 1 # same for max\nargz.go()\n\n```\nThese constraints will be checked after validation and adapters have run.\nBoth values are inclusive. For example, `unsigned char` range would be:\n`min = 0; max = 0xFF`\n\n\nFallback vs Default\n-------------------\nSetting either one will deem an argument optional, however, they have one major difference:\n\n> Default is any value that will be passed to the called route **without any** parsing or validation.\n\n> Fallback is a **string** value that will pass all validations and parsing, as if it was specified via the commandline.\n\n\nIf the argument was not provieded via the commandline, `argz` will use either `fallback` or `default`. The `fallback` value takes precedence.\n\nIf a default value is specified in the function definition, `argz` will use it as the argument's default and infer a default adapter in some cases (see `SUPPORTED_INFERRED_ADAPTERS`).\n\n\nSwitches\n--------\nFunction arguments that have a default **boolean** value will be inferred as a switch. This means this argument can also be passed using a single dash without a value following it (e.g. `-dbg`). Doing so will 'switch' the default value (`False` to `True`, and vice versa)\n\nThe `dbg` argument from the `example.py` code above demonstrates this.\n\nUsing Split\n-------------------\nSetting the `split` member of an argument changes a few things:\n\n- the input will be split using that string\n- if set, `min` \\ `max` value(s) will be checked against the length of the list\n- the validator and parser(s) will be called for each item in the list **separately**\n\n\nVarargs and Kwargs:\n-------------------\nIf the function accepts them, any additional positional and named arguments will be passed in varargs/kwargs respectively.\n\nAdapter(s) and validator will be called with the entire list/dictionary, and they must return a value of the same type.\n\nAccessing function arguments\n----------------------------\nSetting arguments properties can be done in two ways:\n\n- by name:\n```python\nf = argz.route(func)\nf.myvar.min = 1\n```\n\n- by index:\n```python\nf = argz.route(func)\nf[0].min = 1\n```\n > Note: argument names are case sensitive\n\n\nParsing Flow\n--------------\nThe following graph illustrates the flow for parsing an argument (varargs\\kwargs do not support splitting the input):\n```\n +------------+ +-----------+ +-----------+\n | fallback | | input | | default |\n +-----+------+ +-----+-----+ +-----+-----+\n | | |\n +-------+-------+ |\n | |\n v |\n +----+-----+ |\n | split? | |\n +---+-+----+ |\n | | |\n | | Yes |\n +----------+ v |\n | +--------+--------+ |\nNo | | min / max len | |\n | +--------+--------+ |\n +-------+ | |\n | | +-----------+ |\n V v v | |\n +--------+----+---+ | |\n | | | |\n | validator | | |\n | + | | |\n | v | | |\n | adapter chain | | |\n | | | |\n +--------+----+---+ | |\n | | | |\n | | split? | |\n | | | |\n | +-----------+ |\n +--------+---------+ |\n | min / max check | (if not split) |\n +--------+---------+ |\n | |\n v |\n +-------+--------+ |\n | return value | <------------------+\n +----------------+\n\n```\n\nUsing Multiple Routes\n-----------\nYou can 'export' several different routes using `argz`.\nThis means that the user must choose which one they want to run:\n```python\n# $ cat example_routes.py\nfrom os.path import isfile\n\ndef entry1(filepath, dbg=False):\n pass\n\ndef entry2(count):\n pass\n\n# ...\n\nif __name__ == '__main__':\n import argz\n argz.route(entry1).validator = isfile\n argz.route(entry2).count.min = 1\n argz.go()\n```\nRunning:\n```console\n$ example_routes.py\n\nAvailable routes:\n> 'entry1' filepath [-dbg]\n> 'entry2' count\n\nfor detailed help, use any of (-h, /h, -?, /?, /help, --help)\nyou can specify the route name (e.g. -h MY_ROUTE)\n```\n```console\n$ example_routes.py -h\n|> 'entry1' filepath [-dbg]\n|\n| filepath\n| dbg\n| default | False\n| adapter | \n|_ _ _ _ _ _\n\n|> 'entry2' count\n|\n| count\n| 1 <= X\n|_ _ _ _ _ _\n```\n> Note: routes are allowed to run without arguments, so long as there is more than one route available.\n\n\nOverriding Defaults\n-------------------\nYou can specify custom doc string to print when verbose help is shown by passing `doc` argument to `route`. To completely suppress it pass an empty string.\n\nIf you use a single route that accepts an argument whose name is in `HELP_OPTIONS`, you can replace those by specifying a `custom_help_options` list when calling `go`.\n\n\nTested on\n---------\n- Python 2.7.15, windows 10\n- Python 3.7.2, windows 10\n\n\nTroubleshooting\n---------------\n\nTo enable logging:\n```bash\nset ARGZ_LOG=\n```\n`LOG_LEVEL` will be passed to `Logger.setLevel`\n\nTesting\n-------\nadded some unit-tests, run `runtests.bat`\n\nLicense\n----\nMIT\n\nTODO\n----\n- Allow mixture of file input and command-line input\n- Normalize/strip underscores ( `_` ) in argument names\n- Handle name collisions with `Route` object properties\n- Infer from type annotaitons/hints (py3 signature?)\n\nTake a look at the code:\n------------------------\n```python", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bnbdr/argz", "keywords": "argument parse args", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "argz", "package_url": "https://pypi.org/project/argz/", "platform": "", "project_url": "https://pypi.org/project/argz/", "project_urls": { "Homepage": "https://github.com/bnbdr/argz" }, "release_url": "https://pypi.org/project/argz/0.1.4/", "requires_dist": null, "requires_python": "", "summary": "Argument parsing for the lazy", "version": "0.1.4" }, "last_serial": 4947813, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "e4269ed500a12080184c6de8a1b807a8", "sha256": "b6fcb04c0c1a590375813a2df0c578d606999886d698e5377f9bb08a3840b837" }, "downloads": -1, "filename": "argz-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e4269ed500a12080184c6de8a1b807a8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14495, "upload_time": "2018-07-14T16:50:14", "url": "https://files.pythonhosted.org/packages/3e/bd/76a2781a3ad4f6d694f4a4732d82c9bb4b84575a04f252c4b9ad9a94afd8/argz-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "888f32427db0fd82ab7f3e2506eb9ca3", "sha256": "fd00a3fb8d72281fc215e3da2c77450817868655e0e6194c8ed1c068962ce7eb" }, "downloads": -1, "filename": "argz-0.1.1.tar.gz", "has_sig": false, "md5_digest": "888f32427db0fd82ab7f3e2506eb9ca3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14544, "upload_time": "2018-07-14T17:12:02", "url": "https://files.pythonhosted.org/packages/7f/99/2870cad671052f57b43f6d69c4532d1e0cd2e4c6ba318673d7f49ebdf69a/argz-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "e464e36153eaa10a26782b4f8eda7332", "sha256": "56fd7e81c66c02c0654a736c5ca5bd91dc332eb4fba15a1a17259a8fcb841b90" }, "downloads": -1, "filename": "argz-0.1.2.tar.gz", "has_sig": false, "md5_digest": "e464e36153eaa10a26782b4f8eda7332", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21415, "upload_time": "2018-08-27T16:21:05", "url": "https://files.pythonhosted.org/packages/af/37/26287087ae03cb319a904a5748e4899062fd9e1501e221183832b154ac3e/argz-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "3e102abbc925d6cc89943839f680577c", "sha256": "53190b4937a3b4d9c13126cf3d29715d4c6395620d4050c934cfc9209eaec9bb" }, "downloads": -1, "filename": "argz-0.1.3.tar.gz", "has_sig": false, "md5_digest": "3e102abbc925d6cc89943839f680577c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22426, "upload_time": "2019-01-27T16:22:06", "url": "https://files.pythonhosted.org/packages/62/68/5280deeeeb0264aa1022c7c83cb78cff3052610a0fafb974dfb043142d0a/argz-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "3d055b638b0102ff546b255ecc2c3aa7", "sha256": "dbf268b9e5dbcd67be276729f03dc74040c358ed3b9819b804c07da426c60f29" }, "downloads": -1, "filename": "argz-0.1.4.tar.gz", "has_sig": false, "md5_digest": "3d055b638b0102ff546b255ecc2c3aa7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22425, "upload_time": "2019-03-16T14:39:07", "url": "https://files.pythonhosted.org/packages/0f/65/86db39498be6b0adcee8576140e9ca3d3ebe00f129c57335494e917a3e56/argz-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3d055b638b0102ff546b255ecc2c3aa7", "sha256": "dbf268b9e5dbcd67be276729f03dc74040c358ed3b9819b804c07da426c60f29" }, "downloads": -1, "filename": "argz-0.1.4.tar.gz", "has_sig": false, "md5_digest": "3d055b638b0102ff546b255ecc2c3aa7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22425, "upload_time": "2019-03-16T14:39:07", "url": "https://files.pythonhosted.org/packages/0f/65/86db39498be6b0adcee8576140e9ca3d3ebe00f129c57335494e917a3e56/argz-0.1.4.tar.gz" } ] }