Random useful stuff
Project description
trickkiste
trickkiste is a collection of convenience functionality I use quite often that
are too small to give them their own project on the one side but prone to
changes due to changes to the Python ecosystem to just copy&paste them and leave
them as they are.
So they are here now, enjoy.
Beware: most of this is not part of any standard library for a reason. That reason might be there are better built in solutions which are harder (but more flexible) to use or I just didn't find them back then. In most cases you're advised to build them your own (to avoid dependencies and bugs).
Content
Here is an overview of what's in here, see the docstings for a better description (some even have a doctest!):
misc
-
throw(BaseException): functionalraisefor closed expressions -
md5from(Path): convenient wrapper returning an MD5 file checksum -
cwd(Path): path changing context manager -
process_output(cmd): short form for 'run a command and return it's output as one string' -
asyncify: decorator turning a sync method or function into an async one -
async_chain: likechainbut async -
async_filter: likefilterbut async -
date_str(timestamp, [datefmt]): convenience wrapper forstrftime -
def date_from(timestamp: float | str): : convenience wrapper forstrptime -
dur_str(seconds, [fixed]): short human readable representation of a duration -
age_str(now, age, [fixed]): likedur_strbut with an age context -
parse_age(string: str): inverse ofage_str -
smart_split(string: str, delimiter: str = ","): likesplitbut parenthesis aware! -
multi_replace(string: str, *substitutions: tuple[str, str]): short form for chaingingreplace -
compact_dict(mapping, [maxlen], [delim]): create a short one-string map -
def split_params(string: str): inverse ofcompact_dict
logging
apply_common_logging_cli_args(ArgumentParser): enrich a given parser to recognize default stuff like--verbose, etc.setup_logging: sets up arichenhanced logger with useful stuff like call stack and posix thread idloggingfilters: internally used bysetup_loggingbut can be re-used of coursemarkup_escape_filter: escapes (accidental) markup elements in the messagethread_id_filter: adds the (posix) thread idcallstack_filter: adds a short call stacklogger_name_filter: adds the logger name (richedition)logger_funcname_filter: adds the function name (richedition)logger_levelname_filter: adds the level name (richedition)
Textual stuff / TuiBaseApp
TuiBaseApp: liketextual.Appbut with convenience stuff mostly regarding loggingRichLogHandler: a logging handler for atextualwidgetLockingRichLog: locks your log view scroll position until you scroll to the bottomHeatBar: a colorful heat bar widget for things like CPU monitoring
std_suppress
std_suppress (with it's own shell entry point suppress) can be prefixed
to a command and acts like adding >/dev/null 2>&1 but will print the output
if the command needs 'longer than expected' something bad happens (i.e.
nonzero exit).
Use it in scripts where you don't need the output to spam your log but you still
want to know if something unusual happend.
License
See License.md.
Contribution
Initialize
git clone https://github.com/frans-fuerst/trickkiste --recurse-submodules
cd trickkiste
uv run pre-commit install
Manually run checks and fixes
Depending on your workflow / IDE you might want to stay in charge over what's
being executed in order to check and fix code validity. For a number of
scenarios there is a bunch of scripts located in the dev submodule which just
wrap manual calls to what would be done by pre-commit. Some actually run
pre-commit for consistency, some don't in order to stay flexible regarding
command line arguments, e.g. for unit-testing using pytest.
run all checks which would be executed on commit, but on unstaged stuff, too
dev/check-validity
do this in a loop (convenience wrapper around inotifywait)
dev/watchandcheck
run all checks separately
dev/check-python-doctests
dev/check-python-formatting
dev/check-python-linting
dev/check-python-systemtests
dev/check-python-typing
dev/check-python-unittests
dev/check-shellscripts
dev/check-yaml-linting
apply fixes for automatically fixable stuff
dev/fix-python-formatting
dev/fix-python-linting
Version bump and publishing
uv version --bump <patch|minor|major>
uv lock --upgrade
uv build
# do manual tests here
git commit -m"Bump version [..]"
git push
uv publish --token <TOKEN>
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trickkiste-0.3.3.tar.gz.
File metadata
- Download URL: trickkiste-0.3.3.tar.gz
- Upload date:
- Size: 38.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e945c4d763c0cf856d859d6e1be36b5f1d4a4b8a5e756163085da892a5035ae
|
|
| MD5 |
424eccda0b2535849806080191486a1f
|
|
| BLAKE2b-256 |
7c0408204a741b9b2b38b1b6ccd5f013587e3c28e0c4d2b0654fe57962e02662
|
File details
Details for the file trickkiste-0.3.3-py3-none-any.whl.
File metadata
- Download URL: trickkiste-0.3.3-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f60dc205887a0633c844629472e97988579260c20c836835ec09e3b291ece0a
|
|
| MD5 |
34c7048221856c7854fb2377ff95fe92
|
|
| BLAKE2b-256 |
e9bf45fe5e9a1239ba8f38670ed333a809041c519d74504133d6d639d3eeb625
|