AccidentallyTheCables Utility Kit
Project description
ATCKit
AccidentallyTheCable's Utility Kit
About
This is a small kit of classes, util functions, etc that I found myself rewriting or reusing frequently, and instead of copying everywhere, they are now here.
How does it work?
Do the needfuls.... do the needful dance
Literally, import whatever you need to use..
Usage
FunctionSubscriber
A Class container for Function callback subscription via +=
or -=
. Functions can be retrieved in order of addition.
subscriber = FunctionSubscriber()
def a():
print("I am a teapot")
def b():
print("I am definitely totally not also a teapot, I swear")
subscriber += a
subscriber += b
for cb in subscriber.functions:
cb()
>> I am a teapot
>> I am definitely totally not also a teapot, I swear
This class uses the typing.Callable
type for function storage. You can extend the FunctionSubscriber
class to define the
callback function parameters, etc.
class MySubscriber(FunctionSubscriber):
"""My Function Subscriber
Callback: (bool) -> None
"""
_functions:list[Callable[[bool],None]]
def __iadd__(self,fn:Callable[[bool],None]) -> Self:
"""Inline Add. Subscribe Function
@param method \c fn Method to Subscribe
"""
return super().__iadd__(fn)
def __isub__(self,fn:Callable[[bool],None]) -> Self:
"""Inline Subtract. Unsubscribe Function
@param method \c fn Method to Unsubscribe
"""
return super().__isub__(fn)
UtilFuncs
A Class containing various static methods:
- dump_sstr: Dump Structured Data (dict) to str of specified format. Accepts JSON, YAML, TOML
- load_sfile: Load Structured Data File, automatically determining data by file extension. Accepts JSON, YAML, TOML
- scan_dir: Search a specified Path, and execute a callback function on discovered files.
- Allows exclusion of Files/Dirs via regex pattern matching
- deep_sort: Sort a Dictionary recursively, including through lists of dicts
- check_pid: Check if a process ID exists (via kill 0)
- register_signals: Register Shutdown / Restart Handlers
- Check for Shutdown via UtilFuncs.shutdown (bool)
- Check for Restart via UtilFuncs.restart (bool)
Version
A Class for version manipulation.
A Version can be created from:
- Semantic String (
"1.0.0"
) - List of Strings or Ints of a version (
["1","0","0"]
or[1,0,0]
) - Tuple of Strings or Ints of a version (
("1","0","0")
or(1,0,0)
)
Versions are comparable (>
,<
,>=
,<=
,==
,!=
)
Versions are addable and subtractable (a -= b
, a += b
)
- During subtraction, if a part goes negative, it will be set to 0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file atckit-1.4.2.tar.gz
.
File metadata
- Download URL: atckit-1.4.2.tar.gz
- Upload date:
- Size: 83.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9ff80c35d4e536c66ab40ec93e40e33355d98b9f4c1ae87f417f0f7b2ba611f |
|
MD5 | 92d219a169c43ef59628c24e60ff56eb |
|
BLAKE2b-256 | 2d097cf2ea4cecaed9e24f9976036b0bd9e273f34669bf8fc96c44cc6cb75d1b |
File details
Details for the file atckit-1.4.2-py3-none-any.whl
.
File metadata
- Download URL: atckit-1.4.2-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce8f5960cedc2d4392337c4439d1a6c54d58b7a6159b23c836d9025ccb12a7a7 |
|
MD5 | d2b9684509f77dab21d40f595b436f95 |
|
BLAKE2b-256 | dc3435576f0e7c9a45dc9077fd5525055930e399f271ecc0dcd7aa09c6953b54 |