Skip to content

Add session class for printing/warning user in a way that respects their verbosity setting

finesse importer requested to merge feature/session into develop

Fixes #414 (closed).

This MR introduces an internal FinesseSession class that's kept in the datastore and persists the user's verbosity setting for the current session. Verbosity is controlled by setting finesse.session.verbosity to "info", "warn" or "quiet". You can also use finesse.session.louder() and finesse.session.quieter() to move one level up/down. The default is "info", which is already the loudest setting, and as such calls to finesse.session.louder() by default don't have any effect.

We might want to use some Python magic to shorten it to finesse.verbosity = "info". Or maybe we make it possible to do via finesse.configure().

FinesseSession supports info() and warn() methods that wrap print() and warnings.warn() calls, but which first check the user's verbosity setting. These are exposed as functions in finesse.env (used to be called finesse.environment) to make the typing a bit lighter - finesse.env.info(...) and finesse.env.warn(...) instead of finesse.session.info(...), which also avoids potential dependency cycles from trying to import the session object out of finesse. Warnings emitted throughout the code now use finesse.env.warn() instead of warnings.warn().

The warn() method compensates the stack for itself so that emitted warnings still look as if they came from the original code line.

The verbosity setting can also be set via the CLI using the -v, and -q flags for louder or quieter output. Given the default "info" level, setting -v currently has no effect. If we decide to introduce some user-debug level then this will become useful. The -q flag on the other hand avoids info messages being emitted, and -qq also hides warnings.

Log display is no longer controlled by -v and -q in the CLI. This is now --log-level.

At some point later FinesseSession can be expanded to include finer filtering controls over which warnings get emitted, as discussed in #415.

Edited by finesse importer

Merge request reports