diff --git a/conservancy_beancount/cliutil.py b/conservancy_beancount/cliutil.py index 58340e72de2ebc23f38cf892ae5b085f543af305..9f960cb987082f217f8de5832f58a5fabb5d6748 100644 --- a/conservancy_beancount/cliutil.py +++ b/conservancy_beancount/cliutil.py @@ -18,6 +18,7 @@ along with this program. If not, see .""" import argparse import enum +import inspect import logging import operator import os @@ -133,6 +134,11 @@ def add_version_argument(parser: argparse.ArgumentParser) -> argparse.Action: help="Show program version and license information", ) +def is_main_script() -> bool: + """Return true if the caller is the "main" program.""" + stack = inspect.stack(context=False) + return len(stack) <= 3 and stack[-1].function.startswith('<') + def setup_logger(logger: Union[str, logging.Logger]='', loglevel: int=logging.INFO, stream: TextIO=sys.stderr,