Whatwhen
whatwhen is a higher-level topological sort, a useful algorithm to resolve dependencies and calculate a workable execution order for functions and other things.
Basic topological sorting:
tasks = [
{
'name: 'drive',
'dependencies': ['car'],
}, {
'name': 'car',
'dependencies': ['wheels', 'gas'],
}, {
'name': 'wheels',
'dependencies': 'rubber',
}, {
'name': 'gas',
}, {
'name': 'rubber',
},
]
whatwhen.sort(items)
Topological sorting using contracts (needs and provisions):
tasks = [
{
'name': 'drive',
'needs': ['car', 'gas'],
}, {
'name': 'fill tank',
'provides': ['gas'],
}, {
'name': 'rent a car',
'provides': ['car'],
'dependencies': ['money'],
}, {
'name': 'money'
}
]
whatwhen.sort(items)
Needs and provisions are useful when you don’t know exactly what function (or system or module or whatever) is going to provide the necessary data or preconditions, but you do know what that data or those preconditions are. This might happen in large systems or systems over which you don’t have full control.
In addition to dictionaries, the metadata on tasks can also be added to functions:
def one():
pass
def two():
pass
one.dependencies = ['two']
whatwhen.sort([one, two])
Whatwhen will return the original functions (or dictionaries) in sorted order, rather than just a sorted list of node names, so it’s slightly easier to work with than a raw topological sort.
Whatwhen lets the tarjan module do most of the heavy lifting, so there’s really only about 40 lines of wrapper code to this module. It’s up to you to decide whether you’d rather build on top of WhatWhen or plain Tarjan.
Metadata
Release files for whatwhen 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| whatwhen-0.1.1.tar.gz | 2.8 kB | Without provenance | Details for whatwhen-0.1.1.tar.gz |
Release files / whatwhen-0.1.1.tar.gz
| Download URL | whatwhen-0.1.1.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
508081a7f0ab8177ec3ad54ba2722b39cf6c6007a8565dfdb2b331dff065688a
|
|
BLAKE2b-256 checksum How to use checksums |
e6c7fb750b0fd3181f5426db11f4b1e52d7717945d0937f0f860dfef28b33601
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for whatwhen 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.