{ "info": { "author": "Eugene Van den Bulke", "author_email": "eugene.vandenbulke@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Topic :: Software Development :: Libraries" ], "description": "=========\nconstants\n=========\n\n\nThe problem?\n============\n\nMost applications use constants. Many constants take different values based\non the environment the application is executed in.\n\nThink database credentials over development, testing, staging, production or\nstock market execution over development, testing, paper, production ...\n\n\nA solution\n==========\n\nShamelessly inspired by the app_constants_ gem, ``constants`` aims to solve that\nproblem (and that problem only).\n\n.ini file\n---------\n\n``constants`` uses the .ini file format to specify the application constants\nvalues in each environment. DEFAULT values are available in every environment\nunless specifically overridden in a section.\n\n::\n\n [DEFAULT]\n something = a_default_value\n all = 1\n a_string = 0350\n\n [a_section]\n something = a_section_value\n just_for_me = 5.0\n flag = False\n minutes = 365 * 24 * 60\n\nTo find out more about ini files and sections, check the Python standard\nlibrary configparser_ documention.\n\nThe default file is ``constants.ini`` in the current working directory. but\nyou can use any filename you want cf. Instantiation_.\n\nEnvironment\n-----------\n\nDefine the environment the application will run in. The default environment\nvariable to store that value is __CONSTANTS__, but you can use any variable\nname you want cf. Instantiation_.\n\nMost platform have a way to do that, in bash:\n\n::\n\n export __CONSTANTS__=a_section\n\n.. _Instantiation:\n\nInstantiation\n-------------\n\n>>> import constants\n>>> consts = constants.Constants()\n\nOn instantiation, constants looks for an environement variable named\n__CONSTANTS__ whose value is used to find out which section of the\nconstants.ini file should be used.\n\nConstants' constructor takes two (2) optional parameters. ``variable``\nlet's you specify the name of the environment variable and ``filename``\nthe absolute path to the .ini file containing the constants definitions.\n\n>>> consts = Constants(variable='AN_ENVIRONMENT_VARIABLE',\n... filename='constants.cfg') # doctest: +SKIP\n\nValues\n------\n\nTo access the values, the instance can be used like a dictionary (getitem).\n\n>>> consts['something']\n'a_section_value'\n\nValues are cast into integer, float or boolean when pertinent.\n\n>>> consts['all']\n1\n>>> consts.a_string\n'0350'\n>>> consts.flag\nFalse\n\nExpressions are evaluated.\n\n>>> consts.minutes\n525600\n\nValues can also be accessed using the . operator (getattr)\n\n>>> consts.all\n1\n\n.. _Warning:\n\nWarning\n-------\n\n\"We are responsible adults\" yet, inspired by Matthew Wilson's suggestion_ to\nraise an exception when an attempt is made to *change a constant*, ``constants``\nissues warnings_ ...\n\n>>> import warnings\n\n>>> with warnings.catch_warnings(record=True) as warning:\n... # reassigning the constant all\n... consts.all = 2\n\n>>> warning[0].message\nUserWarning('all changed to 2',)\n\n... and *changes the constant* anyway.\n\n>>> consts.all\n2\n\nIt does so with the dict like assignment as well.\n\n>>> with warnings.catch_warnings(record=True) as warning:\n... consts['something'] = 'a_new_value'\n\n>>> warning[0].message\nUserWarning('something changed to a_new_value',)\n\n>>> consts['something']\n'a_new_value'\n\nLogging\n-------\n\n``constants`` aims to be a good logging_ citizen, grafting a logger to the\nlogging tree.\n\nAll calls to the logger methods expose an extra logRecord key called ``method``.\n\nWith the logging level set to INFO, it logs one and only one useful message.\n\n>>> import sys\n>>> import logging\n>>> logging.basicConfig(level=logging.INFO,\n... stream=sys.stdout,\n... format='%(levelname)s %(name)s.%(method)s %(message)s')\n>>> consts = constants.Constants() # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS\nINFO constants.load\nvariable: __CONSTANTS__,\nfilename: constants.ini,\nenvironment: a_section,\nconstants: {...}\n\nAt DEBUG level it becomes a tad *noisier*.\n\n>>> logging.root.setLevel(logging.DEBUG)\n>>> debug_me = consts.just_for_me # doctest: +ELLIPSIS\nDEBUG constants.__getattr__ begin (..., 'just_for_me') {}\nDEBUG constants.__getitem__ begin (..., 'just_for_me') {}\nDEBUG constants.cast begin ('5.0',) {}\nDEBUG constants.cast end 5.0\nDEBUG constants.__getitem__ end 5.0\nDEBUG constants.__getattr__ end 5.0\n\nInstallation\n============\n\n``constants`` is available on PyPI_ ...\n\n::\n\n pip install constants\n\n... and can be forked on GitHub_.\n\n.. _app_constants: https://github.com/leonardoborges/app_constants\n.. _configparser: http://docs.python.org/library/configparser.html\n.. _PyPI: http://pypi.python.org/pypi/constants\n.. _GitHub: https://github.com/3kwa/constants\n.. _suggestion: https://twitter.com/mw44118/status/256022281409658881\n.. _warnings: http://docs.python.org/library/warnings.html\n.. _logging: http://docs.python.org/library/logging.html", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/3kwa/constants", "keywords": null, "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "constants", "package_url": "https://pypi.org/project/constants/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/constants/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/3kwa/constants" }, "release_url": "https://pypi.org/project/constants/0.6.0/", "requires_dist": null, "requires_python": null, "summary": "The simple way to deal with environment constants.", "version": "0.6.0" }, "last_serial": 751545, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "c93560471155b9bf22570b611b36dfea", "sha256": "e9a778fb18ba5d455e63050f715f62a86ca9df92942eae6f4eedbc432eb80b2c" }, "downloads": -1, "filename": "constants-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c93560471155b9bf22570b611b36dfea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1605, "upload_time": "2012-10-10T08:34:02", "url": "https://files.pythonhosted.org/packages/2f/12/ceda09d226f5b0543a045a36bb85555899d0d5fe97becc5c53236e66d832/constants-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "5ebef3f5cb33e08d923a54d7eb5badfc", "sha256": "c4c25b17cfe70de968928ba760e7d16321689418073f7dbf752994e0d0c0a806" }, "downloads": -1, "filename": "constants-0.1.1.tar.gz", "has_sig": false, "md5_digest": "5ebef3f5cb33e08d923a54d7eb5badfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2832, "upload_time": "2012-10-10T10:55:52", "url": "https://files.pythonhosted.org/packages/80/df/955d6d5a2c87d39f940c3eaa385768de7da27f4e0de6f38bafbd33b96ec5/constants-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "5c720a810007add6612a7e406b58f658", "sha256": "4f0a05d06a6711e4db55385942773c3a948c2c245a5a15de2fdd32e337160dd9" }, "downloads": -1, "filename": "constants-0.2.0.tar.gz", "has_sig": false, "md5_digest": "5c720a810007add6612a7e406b58f658", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3147, "upload_time": "2012-10-11T11:35:14", "url": "https://files.pythonhosted.org/packages/cb/bb/6fe1f99484808e04ff3a19d2a2c8bc130d47e61144588c62bf6daf536a90/constants-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "08c4d8c4d9808b075b718e96bf8f1dda", "sha256": "e672b684404737f25a141e9d0e11f4b01ded2aaf4434031ea957422ec3fcfafb" }, "downloads": -1, "filename": "constants-0.3.0.tar.gz", "has_sig": false, "md5_digest": "08c4d8c4d9808b075b718e96bf8f1dda", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3899, "upload_time": "2012-10-13T12:20:59", "url": "https://files.pythonhosted.org/packages/1a/0a/17b2d9c5d8cd144da30487e6f4cb379a89a9613bd6072ba84ba884399f31/constants-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "5ac879af1e16c1b5fc5dde9928280e70", "sha256": "44cbbde8da446bf75cf6d72238ca92cb6896b6212a66cf864a352448a1a9a53b" }, "downloads": -1, "filename": "constants-0.4.0.tar.gz", "has_sig": false, "md5_digest": "5ac879af1e16c1b5fc5dde9928280e70", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4993, "upload_time": "2012-10-14T04:34:45", "url": "https://files.pythonhosted.org/packages/62/f7/97b8dd60f36370be84e50a8bb51ff7be6e90af1305a1195012bdb93c2a01/constants-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "21c81c85b7e91ca0a9cb542071dc2f19", "sha256": "0ea82756496a6e9854c4486d5d090fdc23102d2a4ebfd7bc1c0f81588b255aa6" }, "downloads": -1, "filename": "constants-0.4.1.tar.gz", "has_sig": false, "md5_digest": "21c81c85b7e91ca0a9cb542071dc2f19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5023, "upload_time": "2012-10-14T11:11:58", "url": "https://files.pythonhosted.org/packages/11/00/7690e29ec300f51a840411a7bd335aff81a58141d74fed2deb4bd68401af/constants-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "d53c9c6ad2a897261f141a4fc5aa2e31", "sha256": "e6cce771b3006b1b8c0609ce0e16d2fb71729d589cd8b8c0c291bb34cc817fd4" }, "downloads": -1, "filename": "constants-0.4.2.tar.gz", "has_sig": false, "md5_digest": "d53c9c6ad2a897261f141a4fc5aa2e31", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5016, "upload_time": "2012-10-16T10:55:41", "url": "https://files.pythonhosted.org/packages/5c/8c/48519260dbf5edaf74384857040af7916b125ac27d6f0f1085050aefcab5/constants-0.4.2.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "d8b60f508ca54b239ab7f7943d5ae6db", "sha256": "ccb1d13044d2033f0527b767ab00205e319398197b28e6d5ac28f20319ecffc9" }, "downloads": -1, "filename": "constants-0.5.0.tar.gz", "has_sig": false, "md5_digest": "d8b60f508ca54b239ab7f7943d5ae6db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5025, "upload_time": "2012-10-30T11:01:24", "url": "https://files.pythonhosted.org/packages/2f/37/9bf90f82067c21bcdbf0732f2fd1cfbfacc79819845b52f34cfd3f614d03/constants-0.5.0.tar.gz" } ], "0.6.0": [ { "comment_text": "", "digests": { "md5": "b34ca231054875ad440e9de1aa5774d6", "sha256": "0b65d6927b66bfbefdfbca9ef4d66645d266e7ae148ff91659b76f4c7f9bf9b1" }, "downloads": -1, "filename": "constants-0.6.0.tar.gz", "has_sig": false, "md5_digest": "b34ca231054875ad440e9de1aa5774d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5148, "upload_time": "2012-11-15T10:38:17", "url": "https://files.pythonhosted.org/packages/2b/70/74db98e155407b11c446faaf4886830e2119425c786fbd5208397becbb16/constants-0.6.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b34ca231054875ad440e9de1aa5774d6", "sha256": "0b65d6927b66bfbefdfbca9ef4d66645d266e7ae148ff91659b76f4c7f9bf9b1" }, "downloads": -1, "filename": "constants-0.6.0.tar.gz", "has_sig": false, "md5_digest": "b34ca231054875ad440e9de1aa5774d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5148, "upload_time": "2012-11-15T10:38:17", "url": "https://files.pythonhosted.org/packages/2b/70/74db98e155407b11c446faaf4886830e2119425c786fbd5208397becbb16/constants-0.6.0.tar.gz" } ] }