diff options
author | Alen <alen@dotfiles.xyz> | 2023-09-25 21:32:05 +0400 |
---|---|---|
committer | Alen <alen@dotfiles.xyz> | 2023-09-25 21:32:05 +0400 |
commit | 4b8ed94012af1fb4f4752b5d199f79c6bcfd4c59 (patch) | |
tree | ad54d702d385e973f367cc02c9115b1948510caa /dot_ipython/profile_default/startup/00_internal.py | |
parent | 33df3ffbe31ea3b722bfeec21e6a4ebfd038aa00 (diff) |
Add basic IPython config and startup scripts
Diffstat (limited to 'dot_ipython/profile_default/startup/00_internal.py')
-rw-r--r-- | dot_ipython/profile_default/startup/00_internal.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/dot_ipython/profile_default/startup/00_internal.py b/dot_ipython/profile_default/startup/00_internal.py new file mode 100644 index 0000000..57403d8 --- /dev/null +++ b/dot_ipython/profile_default/startup/00_internal.py @@ -0,0 +1,32 @@ +"""Internal startup utils.""" + +_IPYTHON_INTERNAL_NAMES = set(locals()) +_INTERNAL_NAMES = set(locals()) + + +def _summarise_startup() -> None: + import inspect + import logging + import os + + frame = inspect.stack()[1].frame + filename = os.path.basename(frame.f_locals["__file__"]) + nice_name, _ = os.path.splitext(filename) + nice_name = nice_name.lstrip("0123456789_") + + names = sorted( + name + for name in set(frame.f_locals) - _INTERNAL_NAMES + if not name.startswith("_") + ) + + if names: + for name in names: + _INTERNAL_NAMES.add(name) + logging.getLogger("startup").setLevel(logging.INFO) + logger = logging.getLogger(f"startup.{nice_name}") + log_level = getattr(logging, os.getenv("STARTUP_LOG_LEVEL", "DEBUG")) + logger.log(log_level, "%s", ", ".join(names)) + + +_summarise_startup() |