{ "info": { "author": "Johann Petrak", "author_email": "johann.petrak@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", "Topic :: Software Development" ], "description": "# configsimple\n\n[![PyPi version](https://img.shields.io/pypi/v/configsimple.svg)](https://pypi.python.org/pypi/configsimple/)\n[![Python compatibility](https://img.shields.io/pypi/pyversions/configsimple.svg)](https://pypi.python.org/pypi/configsimple/)\n\n\n\nConfigure a command/tall and its components via command line options, config files and environment variables.\n\nThis builds on the [ConfigArgParse](https://github.com/bw2/ConfigArgParse) package, but instead of a replacement \nfor the `ArgumentParser` class, provides its own class `ConfigSimple`\nwhich can be used to define the possible settings using \n`add_argument` and after parsing the settings, to retrieve the \nsetting values.\n\nEach `ConfigSimple` instance represents either the \"top level\" settings\n(similar to `ArgumentParser` usually for tools and programs) or a component\nsetting that belongs to a top level setting instance.\n\nThe `configsimple` package provides a default top level settings singleton, \n`configsimple.config`. \n\nHere is an example of how to define the settings\nfor the toplevel and two components, where the \ntoplevel selects the component to get used:\n\nexample/example1.py:\n```python\nfrom configsimple import topconfig, ConfigSimple, flag\n\n\nclass Component1:\n def __init__(self):\n myconf = ConfigSimple(component=\"comp1\")\n topconfig.add_config(myconf)\n myconf.add_argument(\"--foo\", default=\"22\", type=int, help=\"The FOO setting!\")\n myconf.add_argument(\"--bar\", type=flag)\n myconf.parse_args()\n print(\"Component1 foo is {}\".format(myconf.get(\"foo\")))\n\n\nclass Component2:\n def __init__(self):\n myconf = ConfigSimple(component=\"comp2\")\n topconfig.add_config(myconf)\n myconf.add_argument(\"--foo\", default=\"xyz\", type=str, help=\"The FOO setting, but a different one!\")\n myconf.parse_args()\n print(\"Component2 foo is {}\".format(myconf.get(\"foo\")))\n\n\nif __name__ == \"__main__\":\n topconfig.add_argument(\"--bar\", help=\"The BAR setting\")\n topconfig.add_argument(\"--foo\", help=\"The toplevel FOO setting\")\n topconfig.add_argument(\"--comp\", type=int, choices=[1, 2], required=True, help=\"Component number\")\n topconfig.add_argument(\"pos1\")\n topconfig.parse_args()\n print(\"Toplevel foo is {}\".format(topconfig.get(\"foo\")))\n compclass = [Component1, Component2][topconfig.get(\"comp\")-1]\n comp = compclass()\n print(\"Get the global comp1.foo: {}\".format(topconfig.get(\"comp1.foo\")))\n print(\"Get the global comp2.foo: {}\".format(topconfig.get(\"comp2.foo\")))\n print(\"Get the global comp1.bar: {}\".format(topconfig.get(\"comp1.bar\")))\n print(\"Top positional parameter pos1: {}\".format(topconfig.get(\"pos1\")))\n```\n\nOne way to run this:\n```\n$ python examples/example1.py --comp 1 1 --comp1.foo 2\nToplevel foo is None\nComponent1 foo is 2\nGet the global comp1.foo: 2\nGet the global comp2.foo: None\nGet the global comp1.bar: None\nTop positional parameter pos1: 1\n```\n\nThis selects component comp1 to get initialised which in turn will\nset the comp1.foo parameter. Note that the positional parameter\n\"pos1\" MUST be specified before any component arguments!\n\nIn order to get usage information for the component comp1 settings,\nwe cann run:\n```\n$ python examples/example1.py --comp 1 x --comp1.help\nToplevel foo is None\nusage: example1.py [--comp1.help] [--comp1.config_file COMP1.CONFIG_FILE]\n [--comp1.save_config_file CONFIG_OUTPUT_PATH]\n [--comp1.foo COMP1.FOO] [--comp1.bar COMP1.BAR]\n\noptional arguments:\n --comp1.help Show help for the 'comp1' component\n --comp1.config_file COMP1.CONFIG_FILE\n Specify a file from which to load settings for\n component 'comp1'\n --comp1.save_config_file CONFIG_OUTPUT_PATH\n Specify a file to which to save specified settings.\n --comp1.foo COMP1.FOO\n The FOO setting!\n --comp1.bar COMP1.BAR\n```\nThis shows the help information as soon as the parameters are getting\nparsed in component comp1. For this to work, the required\ntop level arguments have to be provided. \n\nAnother and maybe better way to do this, especially when all possible\ncomponents are known in advance is similar to this:\n\n```python\nfrom configsimple import topconfig, flag\n\n\nclass Component1:\n @staticmethod\n def configsimple(config=None, component=\"comp1\"):\n myconf = config or topconfig.get_config(component=component)\n myconf.add_argument(\"--sub1.sub2.foo\", default=\"22\", type=int, help=\"The FOO setting!\")\n myconf.add_argument(\"--sub1.sub3.sub4.bar\", type=flag)\n return myconf\n\n def __init__(self):\n cfg = Component1.configsimple()\n topconfig.add_config(cfg)\n cfg.parse_args()\n print(\"Component1 sub1.sub2.foo is {}\".format(cfg.get(\"sub1.sub2.foo\")))\n\nclass Component2:\n def configsimple(config=None, component=\"comp2\"):\n myconf = config or topconfig.get_config(component=component)\n myconf.add_argument(\"--foo\", default=\"xyz\", type=str, help=\"The FOO setting, but a different one!\")\n return myconf\n\n def __init__(self):\n myconf = Component2.configsimple()\n topconfig.add_config(myconf)\n myconf.parse_args()\n print(\"Component2 foo is {}\".format(myconf.get(\"foo\")))\n\n\nif __name__ == \"__main__\":\n topconfig.add_argument(\"--bar\", help=\"The BAR setting\")\n topconfig.add_argument(\"--foo\", help=\"The toplevel FOO setting\")\n topconfig.add_argument(\"--comp\", type=int, choices=[1, 2], required=True, help=\"Component number\")\n topconfig.add_argument(\"pos1\")\n topconfig.add_config(Component1.configsimple())\n topconfig.add_config(Component2.configsimple())\n topconfig.parse_args()\n print(\"Toplevel foo is {}\".format(topconfig.get(\"foo\")))\n compclass = [Component1, Component2][topconfig.get(\"comp\")-1]\n comp = compclass()\n print(\"Get the global comp1.foo: {}\".format(topconfig.get(\"comp1.foo\")))\n print(\"Get the global comp2.foo: {}\".format(topconfig.get(\"comp2.foo\")))\n print(\"Get the global comp1.bar: {}\".format(topconfig.get(\"comp1.bar\")))\n print(\"Get the global comp1.sub1.sub2.foo: {}\".format(topconfig.get(\"comp1.sub1.sub2.foo\")))\n print(\"Top positional parameter pos1: {}\".format(topconfig.get(\"pos1\")))\n``` \n\nHere each component has a static function that returns a component \nconfig with all arguments added. These configs can be added in the \ntop-level code and \"--help\" will then show the help for the top level\nand all added configs. \n\n\n\n\n## NOTE\n\nThis package is meant to build on and depend on [ConfigArgParse](https://github.com/bw2/ConfigArgParse) package,\nbut because of a problem in that code, a slightly modified version of\nconfigargparse.py is currently directly included. \n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/johann-petrak/configsimple", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "configsimple", "package_url": "https://pypi.org/project/configsimple/", "platform": "any", "project_url": "https://pypi.org/project/configsimple/", "project_urls": { "Homepage": "http://github.com/johann-petrak/configsimple" }, "release_url": "https://pypi.org/project/configsimple/0.4/", "requires_dist": null, "requires_python": ">=3.5", "summary": "Configure components/classes using config files, command line options etc in a simple way", "version": "0.4" }, "last_serial": 5375634, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "b514b512799d331274729de2a5fa2ad6", "sha256": "43f08010dbc85326330b1c34956c00a909c6ca973bd7bd812a6e50b2a078365c" }, "downloads": -1, "filename": "configsimple-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b514b512799d331274729de2a5fa2ad6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 17574, "upload_time": "2019-06-06T15:05:25", "url": "https://files.pythonhosted.org/packages/9c/e6/32822e5d7a9e1a9c3dcb832e2b3fa45531a36932f5e71e8356d86cc0064a/configsimple-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d9ded150c1b693351251b49f0b97c41c", "sha256": "d17c9ca7ddc6695b97187785d90729be493747a2c43955f97730d7b815a0c64c" }, "downloads": -1, "filename": "configsimple-0.1.tar.gz", "has_sig": false, "md5_digest": "d9ded150c1b693351251b49f0b97c41c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 16911, "upload_time": "2019-06-06T15:05:28", "url": "https://files.pythonhosted.org/packages/6d/49/9f8d155c42b58df25f450ef4ef1a44d5d9db1eb63b544a993f854e9cda29/configsimple-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "48fa1bb5fc6855452c406786690c99bf", "sha256": "600181ef1a231935e0a6ecaccee7405a369fd43bfbfa5a9a62cd8fd32f4f580e" }, "downloads": -1, "filename": "configsimple-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "48fa1bb5fc6855452c406786690c99bf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 18429, "upload_time": "2019-06-07T13:37:24", "url": "https://files.pythonhosted.org/packages/80/48/10ca54afa972a138592218cf5a6696170975540ed68f4bc859bcfdf71238/configsimple-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7db90576e469b21f232099e384c5ff82", "sha256": "c7ea3d2eb5ae57a96f555077fc8b0d5455afb62ee277065636bb0d42cab9ed9c" }, "downloads": -1, "filename": "configsimple-0.2.tar.gz", "has_sig": false, "md5_digest": "7db90576e469b21f232099e384c5ff82", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 18254, "upload_time": "2019-06-07T13:37:25", "url": "https://files.pythonhosted.org/packages/cc/04/200a072d153a0298e8cb6c5a781f9009d77ad2c61583a61d1e3b71990864/configsimple-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "d84eaeba1b9cc8e0e89d387f6ba6ef42", "sha256": "15be28ea2aef53467b82751300aaf09970bdf579ba50f317c05b7558887ed116" }, "downloads": -1, "filename": "configsimple-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "d84eaeba1b9cc8e0e89d387f6ba6ef42", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 19102, "upload_time": "2019-06-07T14:47:41", "url": "https://files.pythonhosted.org/packages/ea/23/b1c1d9e87fed2636ad5a279ae968a76b5b1fb7a8cce4e1e8607d7d7ac062/configsimple-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "52d3436ce0bb9d1d578ce7b98f223e57", "sha256": "f604193d22ee207aef2a7bc4e515dd1d205d4c2f7a279eec859aa7cc28ca6b4a" }, "downloads": -1, "filename": "configsimple-0.3.tar.gz", "has_sig": false, "md5_digest": "52d3436ce0bb9d1d578ce7b98f223e57", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 19429, "upload_time": "2019-06-07T14:47:43", "url": "https://files.pythonhosted.org/packages/09/51/2f67bf067c87a7b29e396bb8002eb291827d17c48b6b84481e70c83f8452/configsimple-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "146800baceeee93f1d95cf4dbd9d59a5", "sha256": "c3342c97b45af23f73088436daa9d817bb1ea6b91ebc6940bbf7acc3e69d57cc" }, "downloads": -1, "filename": "configsimple-0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "146800baceeee93f1d95cf4dbd9d59a5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 22288, "upload_time": "2019-06-08T15:39:13", "url": "https://files.pythonhosted.org/packages/48/f6/b973833146f9045298750de2d0b40ddf9087927dbab0fb19113b8b1a1175/configsimple-0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "943de2c9984dd2a5c5ee670f77c6eba3", "sha256": "9c36654e47e90f63616be36dc8191b5a273c0ee04dd6c69b67b4dfee4b75c6cb" }, "downloads": -1, "filename": "configsimple-0.4.tar.gz", "has_sig": false, "md5_digest": "943de2c9984dd2a5c5ee670f77c6eba3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 20274, "upload_time": "2019-06-08T15:39:15", "url": "https://files.pythonhosted.org/packages/6d/d9/0f427dad5d82bd9fc93a4a27344fadd3a765d8001f22e2d00ca8d17f88b7/configsimple-0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "146800baceeee93f1d95cf4dbd9d59a5", "sha256": "c3342c97b45af23f73088436daa9d817bb1ea6b91ebc6940bbf7acc3e69d57cc" }, "downloads": -1, "filename": "configsimple-0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "146800baceeee93f1d95cf4dbd9d59a5", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 22288, "upload_time": "2019-06-08T15:39:13", "url": "https://files.pythonhosted.org/packages/48/f6/b973833146f9045298750de2d0b40ddf9087927dbab0fb19113b8b1a1175/configsimple-0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "943de2c9984dd2a5c5ee670f77c6eba3", "sha256": "9c36654e47e90f63616be36dc8191b5a273c0ee04dd6c69b67b4dfee4b75c6cb" }, "downloads": -1, "filename": "configsimple-0.4.tar.gz", "has_sig": false, "md5_digest": "943de2c9984dd2a5c5ee670f77c6eba3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 20274, "upload_time": "2019-06-08T15:39:15", "url": "https://files.pythonhosted.org/packages/6d/d9/0f427dad5d82bd9fc93a4a27344fadd3a765d8001f22e2d00ca8d17f88b7/configsimple-0.4.tar.gz" } ] }