Skip to main content

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): functional raise for 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: like chain but async

  • async_filter: like filter but async

  • date_str(timestamp, [datefmt]): convenience wrapper for strftime

  • def date_from(timestamp: float | str): : convenience wrapper for strptime

  • dur_str(seconds, [fixed]): short human readable representation of a duration

  • age_str(now, age, [fixed]): like dur_str but with an age context

  • parse_age(string: str): inverse of age_str

  • smart_split(string: str, delimiter: str = ","): like split but parenthesis aware!

  • multi_replace(string: str, *substitutions: tuple[str, str]): short form for chainging replace

  • compact_dict(mapping, [maxlen], [delim]): create a short one-string map

  • def split_params(string: str): inverse of compact_dict

logging

  • apply_common_logging_cli_args(ArgumentParser): enrich a given parser to recognize default stuff like --verbose, etc.
  • setup_logging: sets up a rich enhanced logger with useful stuff like call stack and posix thread id
  • logging filters: internally used by setup_logging but can be re-used of course
    • markup_escape_filter: escapes (accidental) markup elements in the message
    • thread_id_filter: adds the (posix) thread id
    • callstack_filter: adds a short call stack
    • logger_name_filter: adds the logger name (rich edition)
    • logger_funcname_filter: adds the function name (rich edition)
    • logger_levelname_filter: adds the level name (rich edition)

Textual stuff / TuiBaseApp

  • TuiBaseApp: like textual.App but with convenience stuff mostly regarding logging
  • RichLogHandler: a logging handler for a textual widget
  • LockingRichLog: locks your log view scroll position until you scroll to the bottom
  • HeatBar: 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trickkiste-0.3.5.tar.gz (47.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trickkiste-0.3.5-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file trickkiste-0.3.5.tar.gz.

File metadata

  • Download URL: trickkiste-0.3.5.tar.gz
  • Upload date:
  • Size: 47.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for trickkiste-0.3.5.tar.gz
Algorithm Hash digest
SHA256 58925e59981494723fec664bd319121bc08a0313f5ae75ca8c8c808d7053b329
MD5 06a25d83c2cbfad6000fadc4efe993a8
BLAKE2b-256 5890c1ff9d8a1637f9d57b365d7dec00bf3528ceeabf4fca08dcd35bd8ad8366

See more details on using hashes here.

File details

Details for the file trickkiste-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: trickkiste-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for trickkiste-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 43a82e9832b722240288b7879ac588841330199b583653f5e2ec23a4c40acad6
MD5 c7f6fb44c95964b2290d2cb379104d72
BLAKE2b-256 a9a3887296daec5e1ac99e67ea2b32e62759803d955661354ad7cb4a1faf7f6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page