From d69b567bea33ce0a60d5a86b6c18160c00b16c43 Mon Sep 17 00:00:00 2001 From: Gertjan van Zwieten Date: Tue, 8 Aug 2023 13:18:13 +0200 Subject: [PATCH] log nutils version in cli.run, choose This patch adds the _util.log_version context that logs the nutils version and release name, and adds it to the context list of cli.run so that the version is shown prior to any other output. --- nutils/_util.py | 12 ++++++++++++ nutils/cli.py | 1 + 2 files changed, 13 insertions(+) diff --git a/nutils/_util.py b/nutils/_util.py index cdad48e4e..a4aa57a4c 100644 --- a/nutils/_util.py +++ b/nutils/_util.py @@ -427,6 +427,18 @@ def in_context(*args, **kwargs): return in_context_wrapper +def log_version(f): + + from . import version, version_name + + @functools.wraps(f) + def log_version(*args, **kwargs): + treelog.info(f'NUTILS {version} "{version_name.title()}"') + return f(*args, **kwargs) + + return log_version + + def log_arguments(f): '''Decorator to log a function's arguments. diff --git a/nutils/cli.py b/nutils/cli.py index 9710f2f2b..63bf33f42 100644 --- a/nutils/cli.py +++ b/nutils/cli.py @@ -23,6 +23,7 @@ def run(f, *, argv=None): util.in_context(util.log_traceback), util.in_context(util.post_mortem), warnings.via(treelog.warning), + util.log_version, util.log_arguments, util.timeit(), )