Name | clickset JSON |
Version |
1.1.0
JSON |
| download |
home_page | https://gitlab.com/selcouth/clickset |
Summary | In-class settings configurable via both click and confuse libraries |
upload_time | 2024-01-06 04:41:35 |
maintainer | |
docs_url | None |
author | David Morris |
requires_python | >=3.10,<4.0 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ClickSet
ClickSet is a thin wrapper around the `click` and `confuse` libraries, combining
them both into a simple property-like interface for use with python classes.
```python
from clickset import Setting
from clickset import ClickParams
from clickset import get_config
import confuse
import click
class MyClass:
verbose = Setting(
# confuse storage path
'general.verbose',
# click boolean option
option = ClickParams(
'--verbose/--quiet',
help = 'Verbose or Quiet Output'
)
)
def my_func(self):
# Get the value of a Setting
print(f"verbose status: {self.verbose}")
# Set the value of the property ... in memory only!
self.verbose = False
assert self.verbose == False
@click.command
# Load all options set in classes
@Setting.options
def main(**kw):
# Get the default global confuse configuration singleton
config = get_config()
foo = MyClass()
print(f"verbose: {foo.verbose}")
assert foo.verbose == kw['verbose']
assert foo.verbose == config['general']['verbose'].get()
# confuse/click values can also be obtained directly from classes
# ... NOTE: The value here is read-only!
assert MyClass.verbose.get() == kw['verbose']
# confuse/click values can also be obtained without a class
verbose = Setting(
# confuse storage path
'general.verbose',
# click boolean option
option = ClickParams(
'--verbose/--quiet',
help = 'Verbose or Quiet Output'
)
)
assert verbose == MyClass.verbose.get()
assert verbose == foo.verbose
main(['--verbose'])
```
# Design Concepts
This library is built around the following design concept:
- Define app configuration in the class where it is used
- Link command line options to configuration file entries
- Permit multiple configuration files covering different purposes
- Provide a persistent application state storage mechanism
- Provide a simple interface which covers common use scenarios
- Provide as much access as possible to underlying libraries
These design concepts led me to utilizing two base libraries to provide
functionality:
- **confuse**: Provides configurable values to an application by providing multiple
sources (memory, command line arguments, YAML files, etc.) in a priority based
list.
- **click**: Provides a command line interface which is easily extended with
additional funcitonality.
While both of these libraries are very powerful tools in their own right, they
both force their relevant settings into a central location. In order to keep
all configuration settings in the location they are used, this library combines
`confuse` and `click` into a single class called `Setting`. The resulting class
has the following features:
- All data is stored using confuse
- Command line parameters provided by click are inserted into the confuse data
store
- Data is accessed in the same mechanism as a python `property`
- Values can be overridden on a per-instance basis (same as setting a
`property`)
- click/confuse values can obtained direclty using `Setting(...).get()` in order
to easily obtain configured values outside of class restrictions (see the
example above)
While this design is highly flexible, there are noteworthy drawbacks which must
be considered:
- `click` parameter definitions and `confuse` data stores must be defined as global
singletons.
- Generally this is acceptable as both configuration files and command line
interfaces have one instance per application.
- Multiple singletons can be created for both `confuse` and `click` in order
to provide design flexibility.
- Command line options are *always* generated if the relevant class has been
imported. This means that care must be taken with inactive code to ensure it
is not imported by the main application.
- This is generally a small risk if one is following good coding practices by
importing only files which are used in a module.
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/selcouth/clickset",
"name": "clickset",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "David Morris",
"author_email": "gypsysoftware@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/fb/f5/cfd0199b137125c6b505939679be9039c71b307b28c2f8e58bca2b8028a4/clickset-1.1.0.tar.gz",
"platform": null,
"description": "# ClickSet\n\nClickSet is a thin wrapper around the `click` and `confuse` libraries, combining\nthem both into a simple property-like interface for use with python classes.\n\n```python\nfrom clickset import Setting\nfrom clickset import ClickParams\nfrom clickset import get_config\nimport confuse\nimport click\n\nclass MyClass:\n verbose = Setting(\n # confuse storage path\n 'general.verbose',\n\n # click boolean option\n option = ClickParams(\n '--verbose/--quiet',\n help = 'Verbose or Quiet Output'\n )\n )\n\n def my_func(self):\n # Get the value of a Setting\n print(f\"verbose status: {self.verbose}\")\n\n # Set the value of the property ... in memory only!\n self.verbose = False\n assert self.verbose == False\n\n@click.command\n# Load all options set in classes\n@Setting.options\ndef main(**kw):\n # Get the default global confuse configuration singleton\n config = get_config()\n foo = MyClass()\n print(f\"verbose: {foo.verbose}\")\n assert foo.verbose == kw['verbose']\n assert foo.verbose == config['general']['verbose'].get()\n\n # confuse/click values can also be obtained directly from classes\n # ... NOTE: The value here is read-only!\n assert MyClass.verbose.get() == kw['verbose']\n\n # confuse/click values can also be obtained without a class\n verbose = Setting(\n # confuse storage path\n 'general.verbose',\n\n # click boolean option\n option = ClickParams(\n '--verbose/--quiet',\n help = 'Verbose or Quiet Output'\n )\n )\n assert verbose == MyClass.verbose.get()\n assert verbose == foo.verbose\n\nmain(['--verbose'])\n```\n\n# Design Concepts\n\nThis library is built around the following design concept:\n\n- Define app configuration in the class where it is used\n- Link command line options to configuration file entries\n- Permit multiple configuration files covering different purposes\n- Provide a persistent application state storage mechanism\n- Provide a simple interface which covers common use scenarios\n- Provide as much access as possible to underlying libraries\n\nThese design concepts led me to utilizing two base libraries to provide\nfunctionality:\n\n- **confuse**: Provides configurable values to an application by providing multiple\n sources (memory, command line arguments, YAML files, etc.) in a priority based\n list.\n- **click**: Provides a command line interface which is easily extended with\n additional funcitonality.\n\nWhile both of these libraries are very powerful tools in their own right, they\nboth force their relevant settings into a central location. In order to keep\nall configuration settings in the location they are used, this library combines\n`confuse` and `click` into a single class called `Setting`. The resulting class\nhas the following features:\n\n- All data is stored using confuse\n- Command line parameters provided by click are inserted into the confuse data\n store\n- Data is accessed in the same mechanism as a python `property`\n- Values can be overridden on a per-instance basis (same as setting a\n `property`)\n- click/confuse values can obtained direclty using `Setting(...).get()` in order\n to easily obtain configured values outside of class restrictions (see the\n example above)\n\nWhile this design is highly flexible, there are noteworthy drawbacks which must\nbe considered:\n\n- `click` parameter definitions and `confuse` data stores must be defined as global\n singletons.\n - Generally this is acceptable as both configuration files and command line\n interfaces have one instance per application.\n - Multiple singletons can be created for both `confuse` and `click` in order\n to provide design flexibility.\n- Command line options are *always* generated if the relevant class has been\n imported. This means that care must be taken with inactive code to ensure it\n is not imported by the main application.\n - This is generally a small risk if one is following good coding practices by\n importing only files which are used in a module.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "In-class settings configurable via both click and confuse libraries\u001b",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://gitlab.com/selcouth/clickset",
"Repository": "https://gitlab.com/selcouth/clickset"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c8da80fa0414466953b54e697d289e9c20d923511dbd822666bd06f12799ba88",
"md5": "34269152847fd6fb3e2b81fe8db76332",
"sha256": "d445e9389d38219725a10cd3fa0ee10381d6f34d0389869e920725ea8d47a2b0"
},
"downloads": -1,
"filename": "clickset-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "34269152847fd6fb3e2b81fe8db76332",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 8927,
"upload_time": "2024-01-06T04:41:33",
"upload_time_iso_8601": "2024-01-06T04:41:33.139207Z",
"url": "https://files.pythonhosted.org/packages/c8/da/80fa0414466953b54e697d289e9c20d923511dbd822666bd06f12799ba88/clickset-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fbf5cfd0199b137125c6b505939679be9039c71b307b28c2f8e58bca2b8028a4",
"md5": "4eabc91177303f920ddf9eb339ab71aa",
"sha256": "629ae628bcd80d383b2fbeca77ba34710cad9186280bce41ad56b781cfab5999"
},
"downloads": -1,
"filename": "clickset-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "4eabc91177303f920ddf9eb339ab71aa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 7847,
"upload_time": "2024-01-06T04:41:35",
"upload_time_iso_8601": "2024-01-06T04:41:35.094765Z",
"url": "https://files.pythonhosted.org/packages/fb/f5/cfd0199b137125c6b505939679be9039c71b307b28c2f8e58bca2b8028a4/clickset-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-06 04:41:35",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "selcouth",
"gitlab_project": "clickset",
"lcname": "clickset"
}