Utility functions around state changes.
*Latest release 20240622*:
Changes to accomodate dropping BaseCommandOptions.runstate.
## Function `delta(old, new, keys=None)`
Return a mapping representing differences between the mappings
`old` and `new` for the specified `keys`.
If `keys` is not specified, the union of the keys of `old`
and `new` is used.
The returned mapping has a key for each changed value.
If the key does not exist in `new` the value is the `MISSING`
sentinel object otherwise it is `new[key]`.
Values are compared using `==`; if that raises `TypeError`
the values are considered not equal.
Example:
>>> d1 = {1: 2, 3: 4, 5: 6}
>>> d2 = {1: 2, 3: 44, 7: 8}
>>> diff = delta(d1, d2)
>>> diff # doctest: +ELLIPSIS
{3: 44, 5: <object object at ...>, 7: 8}
>>> diff[5] is MISSING
True
## Function `monitor(get_state, keys=None, *, ifunchanged=False, interval=0.3, runstate: Optional[cs.resources.RunState] = <function uses_runstate.<locals>.<lambda> at 0x1072e81f0>)`
A generator yielding 3-tuples of `(old,new,delta(old,new,keys))`
at poll intervals of `interval` seconds.
Parameters:
* `get_state`: a callable which polls the current state,
returning a mapping
* `keys`: an optional iterable of keys of interest;
if omitted, all the old and new mapping keys are examined
* `ifunchanged`: optional flag, default `False`;
if true yield a tuple on every poll instead of only when a
state change is seen
* `interval`: an optional interpoll `time.sleep` period,
default `0.3`s
* `runstate`: an optional `RunState`, whose `cancelled`
attribute will be polled for loop termination
# Release Log
*Release 20240622*:
Changes to accomodate dropping BaseCommandOptions.runstate.
*Release 20240316*:
Fixed release upload artifacts.
*Release 20240214*:
Initial PyPI release.
Raw data
{
"_id": null,
"home_page": null,
"name": "cs.delta",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python2, python3",
"author": null,
"author_email": "Cameron Simpson <cs@cskk.id.au>",
"download_url": "https://files.pythonhosted.org/packages/a2/47/6dc89b36b64bc7d8522e46bfecd2ba815fa7a2420d59f72e8e95005bc99b/cs.delta-20240622.tar.gz",
"platform": null,
"description": "Utility functions around state changes.\n\n*Latest release 20240622*:\nChanges to accomodate dropping BaseCommandOptions.runstate.\n\n## Function `delta(old, new, keys=None)`\n\nReturn a mapping representing differences between the mappings\n`old` and `new` for the specified `keys`.\nIf `keys` is not specified, the union of the keys of `old`\nand `new` is used.\n\nThe returned mapping has a key for each changed value.\nIf the key does not exist in `new` the value is the `MISSING`\nsentinel object otherwise it is `new[key]`.\nValues are compared using `==`; if that raises `TypeError`\nthe values are considered not equal.\n\nExample:\n\n >>> d1 = {1: 2, 3: 4, 5: 6}\n >>> d2 = {1: 2, 3: 44, 7: 8}\n >>> diff = delta(d1, d2)\n >>> diff # doctest: +ELLIPSIS\n {3: 44, 5: <object object at ...>, 7: 8}\n >>> diff[5] is MISSING\n True\n\n## Function `monitor(get_state, keys=None, *, ifunchanged=False, interval=0.3, runstate: Optional[cs.resources.RunState] = <function uses_runstate.<locals>.<lambda> at 0x1072e81f0>)`\n\nA generator yielding 3-tuples of `(old,new,delta(old,new,keys))`\nat poll intervals of `interval` seconds.\n\nParameters:\n* `get_state`: a callable which polls the current state,\n returning a mapping\n* `keys`: an optional iterable of keys of interest;\n if omitted, all the old and new mapping keys are examined\n* `ifunchanged`: optional flag, default `False`;\n if true yield a tuple on every poll instead of only when a\n state change is seen\n* `interval`: an optional interpoll `time.sleep` period,\n default `0.3`s\n* `runstate`: an optional `RunState`, whose `cancelled`\n attribute will be polled for loop termination\n\n# Release Log\n\n\n\n*Release 20240622*:\nChanges to accomodate dropping BaseCommandOptions.runstate.\n\n*Release 20240316*:\nFixed release upload artifacts.\n\n*Release 20240214*:\nInitial PyPI release.\n\n",
"bugtrack_url": null,
"license": "GNU General Public License v3 or later (GPLv3+)",
"summary": "Utility functions around state changes.",
"version": "20240622",
"project_urls": {
"MonoRepo Commits": "https://bitbucket.org/cameron_simpson/css/commits/all",
"Monorepo Git Mirror": "https://github.com/cameron-simpson/css",
"Monorepo Hg/Mercurial Mirror": "https://hg.sr.ht/~cameron-simpson/css",
"Source": "https://github.com/cameron-simpson/css/blob/main/lib/python/cs/delta.py"
},
"split_keywords": [
"python2",
" python3"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "783543833ba1260d305d0c0a14310b79a78ee695ffa9287befa96a38095a2fe1",
"md5": "886c96beb7e6f7b31995abc08d54c254",
"sha256": "6add845557e1280f0246406eb6a66c30cf67c1dfa29ed0e375c46688418950fc"
},
"downloads": -1,
"filename": "cs.delta-20240622-py3-none-any.whl",
"has_sig": false,
"md5_digest": "886c96beb7e6f7b31995abc08d54c254",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3744,
"upload_time": "2024-06-22T09:48:58",
"upload_time_iso_8601": "2024-06-22T09:48:58.501326Z",
"url": "https://files.pythonhosted.org/packages/78/35/43833ba1260d305d0c0a14310b79a78ee695ffa9287befa96a38095a2fe1/cs.delta-20240622-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a2476dc89b36b64bc7d8522e46bfecd2ba815fa7a2420d59f72e8e95005bc99b",
"md5": "709f482fa66b0102c6756f7a4f61692d",
"sha256": "1611f0027b954d39412caae87e2075996727948e770bcee86eb0b197b8b665df"
},
"downloads": -1,
"filename": "cs.delta-20240622.tar.gz",
"has_sig": false,
"md5_digest": "709f482fa66b0102c6756f7a4f61692d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3428,
"upload_time": "2024-06-22T09:49:00",
"upload_time_iso_8601": "2024-06-22T09:49:00.237671Z",
"url": "https://files.pythonhosted.org/packages/a2/47/6dc89b36b64bc7d8522e46bfecd2ba815fa7a2420d59f72e8e95005bc99b/cs.delta-20240622.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-22 09:49:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cameron-simpson",
"github_project": "css",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "cs.delta"
}