{ "info": { "author": "thuhak", "author_email": "thuhak.zhou@nio.com", "bugtrack_url": null, "classifiers": [], "description": "# \u901a\u7528\u914d\u7f6e\u6587\u4ef6\u7c7b\n\n## \u529f\u80fd\n\n- \u52a0\u8f7djson\u6216\u8005yaml\u6587\u4ef6\u4f5c\u4e3a\u53ef\u5d4c\u5957\u7684\u914d\u7f6e\u6587\u4ef6, \u6587\u4ef6\u540d\u5fc5\u987b\u4ee5.json,.yaml\u6216\u8005\u662f.yml\u7ed3\u5c3e\n- \u652f\u6301\u5b50\u6587\u4ef6\u62c6\u5206\uff0c\u9700\u8981\u5728json\u6216\u8005yaml\u4e2d\u5b9a\u4e49include\u8fd9\u4e2akey\uff0c\u503c\u4e3a\u5b50\u8def\u5f84\n- \u914d\u7f6e\u5b9e\u4f8b\u7684\u4f1a\u968f\u7740\u914d\u7f6e\u6587\u4ef6\u7684\u6539\u53d8\u800c\u53d8\u66f4,\u5982\u679c\u60f3\u7981\u7528\u8fd9\u4e2a\u529f\u80fd\uff0c\u9700\u8981\u53ef\u4ee5\u4f20\u9012\u53c2\u6570refresh=False\n- \u652f\u6301\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6ce8\u518c\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u76d1\u63a7\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u7279\u5b9akey\uff0c\u5f53key\u53d8\u5316\u65f6\uff0c\u8c03\u7528\u5bf9\u5e94\u7684\u56de\u8c03\u51fd\u6570\u8fdb\u884c\u5904\u7406\n\n## \u5b89\u88c5\n\n```cmd\npip install myconf\n```\n\n## \u4f7f\u7528\u4e3e\u4f8b\n\n\u914d\u7f6e\u6587\u4ef6\n```json\n{\n \"foo\": {\n \"bar\": \"abced\"\n },\n \"include\": \"/tmp/conf/\"\n}\n```\n\n### \u4e00\u822c\u60c5\u51b5\n\n```python\nfrom myconf import Conf\nimport time\n\nconfig = Conf('/testconf/test.yml')\n\nwhile True:\n print(config)\n time.sleep(1)\n\n```\n\n- \u66f4\u6539\u914d\u7f6e\u6587\u4ef6\u4ee5\u540e\uff0cconfig\u4e5f\u4f1a\u968f\u7740\u6539\u53d8\n- \u9700\u8981\u6ce8\u610fmutable\u548cimutable\u7684\u533a\u522b\u3002\u5982\u679c\u4f7f\u7528\u7d22\u5f15\u628aconfig\u4e2d\u7684\u67d0\u4e2a\u4e0d\u53ef\u53d8\u7c7b\u578b(int, str\u7b49)\u7684\u503c\u8d4b\u4e88\u4e00\u4e2a\u5de6\u503c\u53d8\u91cf\uff0c\u90a3\u4e48\u8fd9\u4e2a\u53d8\u91cf\u662f\u4e0d\u4f1a\u4fee\u6539\u7684.\n\n\n### \u4f7f\u7528\u56de\u8c03\n\n```python\nfrom myconf import Conf\nimport logging\n\nclass MyConf(Conf):\n def onchange_a(self, old, new, watched_item='foo.bar'):\n logging.info('foo.bar changes from {} to {}'.format(old, new))\n\n def onchange_b(self, old, new, watched_item='a.b'):\n logging.info('a.b changes from {} to {}'.format(old, new))\n\n\nconfig = MyConf('/testconf/test.yml')\n```\n\n1. \u7ee7\u627fConf\u7c7b\n2. \u5b9a\u4e49\u56de\u8c03\u51fd\u6570onchange_xx(self, old, new, watched_item=\"jmespath-expression\")\u3002\n\u51fd\u6570\u540d\u79f0\u5fc5\u987b\u4ee5onchange_\u5f00\u5934\uff0c\u5982\u679c\u6709\u591a\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u6309\u7167\u51fd\u6570\u7684\u540d\u79f0\u6392\u5e8f\u4f9d\u6b21\u6267\u884c\u3002\n\u51fd\u6570\u4e2d\u7684old\u4ee3\u8868\u4fee\u6539\u524d\u7684\u6570\u636e\uff0cnew\u4ee3\u8868\u4fee\u6539\u540e\u7684\u6570\u636e\uff0c\u8fd9\u4e24\u4e2a\u53c2\u6570\u53ef\u4ee5\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u3002\nwatched_item\u9700\u8981\u6709\u4e00\u4e2ajmespath\u8868\u8fbe\u5f0f\u4f5c\u4e3a\u9ed8\u8ba4\u503c\uff0c\u65e0\u9700\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u3002\n\u5f53\u914d\u7f6e\u4e2d\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u641c\u7d22\u51fa\u7684\u7ed3\u679c\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u6267\u884c\u56de\u8c03. jmespath\u8868\u8fbe\u5f0f\u7684\u4f7f\u7528\u53ef\u4ee5\u53c2\u8003[\u5b98\u65b9\u6587\u6863](http://jmespath.org)\n\n\n## \u6ce8\u610f\u4e8b\u9879\n\n- \u5728\u5904\u7406\u5b50\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u5982\u679c\u6709\u91cd\u590d\u7684key\uff0c\u4f1a\u4f9d\u636e\u52a0\u8f7d\u987a\u5e8f\u6267\u884c\u8986\u76d6\u3002\u4e3a\u4e86\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u9ebb\u70e6\uff0c\u4e0d\u8981\u4f7f\u7528\u91cd\u590d\u7684key\u503c\n- \u4e3a\u4e86\u7b80\u4fbf\u7684\u5b9e\u73b0\u5feb\u901f\u52a0\u8f7d\uff0c\u6570\u636e\u5b9e\u9645\u5360\u7528\u7684\u5b58\u50a8\u7a7a\u95f4\u4f1a\u6bd4\u539f\u6765\u7ffb\u500d\n- Conf\u5e76\u6ca1\u6709\u5b9e\u73b0__setitem__\u65b9\u6cd5\uff0c\u76f8\u5f53\u4e8efrozendict\uff0c\u4f46\u662f\u52a0\u8f7d\u8fdb\u6765\u7684\u5b50\u9879\u5219\u662f\u666e\u901a\u7684dict\u3002\u4e0d\u8981\u76f4\u63a5\u4fee\u6539\u8fd9\u4e9b\u503c\uff0c\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u7684\u65f6\u5019\u4f1a\u88ab\u5237\u65b0\u56de\u6765\u3002", "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/thuhak/myconf", "keywords": "configfile", "license": "", "maintainer": "", "maintainer_email": "", "name": "myconf", "package_url": "https://pypi.org/project/myconf/", "platform": "", "project_url": "https://pypi.org/project/myconf/", "project_urls": { "Homepage": "https://github.com/thuhak/myconf" }, "release_url": "https://pypi.org/project/myconf/1.1.0/", "requires_dist": null, "requires_python": "", "summary": "load json or yaml files as python dict, auto refresh when file changing, support item changing callback", "version": "1.1.0" }, "last_serial": 4868475, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "dba2f4940d37172f914c001d137a89d6", "sha256": "04cacb0b3853247c48c8f024facf6a29f2e30f15f9ef07fc24cbc4287b020b5b" }, "downloads": -1, "filename": "myconf-1.0.1.tar.gz", "has_sig": false, "md5_digest": "dba2f4940d37172f914c001d137a89d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3102, "upload_time": "2019-02-20T01:49:04", "url": "https://files.pythonhosted.org/packages/da/dc/c72b53fdb8b2cc1d1d390c7d8aa62880c377b6a7154c6885da044b7c41d7/myconf-1.0.1.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "996ed06e1258cb0f87ca66568f789bed", "sha256": "b61967b86cf9cad3fe0078fc8009e8452822ebc7d86258948ea6ff75ae3979c8" }, "downloads": -1, "filename": "myconf-1.1.0.tar.gz", "has_sig": false, "md5_digest": "996ed06e1258cb0f87ca66568f789bed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5124, "upload_time": "2019-02-26T07:08:48", "url": "https://files.pythonhosted.org/packages/88/8f/29d4ee01a46d5e5d246faf1618983a28f5a8c51bffa5a0f75906f04832ce/myconf-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "996ed06e1258cb0f87ca66568f789bed", "sha256": "b61967b86cf9cad3fe0078fc8009e8452822ebc7d86258948ea6ff75ae3979c8" }, "downloads": -1, "filename": "myconf-1.1.0.tar.gz", "has_sig": false, "md5_digest": "996ed06e1258cb0f87ca66568f789bed", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5124, "upload_time": "2019-02-26T07:08:48", "url": "https://files.pythonhosted.org/packages/88/8f/29d4ee01a46d5e5d246faf1618983a28f5a8c51bffa5a0f75906f04832ce/myconf-1.1.0.tar.gz" } ] }