summary refs log tree commit diff
path: root/dot_ipython/profile_default/ipython_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'dot_ipython/profile_default/ipython_config.py')
-rw-r--r--dot_ipython/profile_default/ipython_config.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/dot_ipython/profile_default/ipython_config.py b/dot_ipython/profile_default/ipython_config.py
new file mode 100644
index 0000000..07ab804
--- /dev/null
+++ b/dot_ipython/profile_default/ipython_config.py
@@ -0,0 +1,59 @@
+"""IPython config."""
+
+import datetime
+import importlib
+import sys
+
+import IPython
+from IPython.core.interactiveshell import InteractiveShell
+from IPython.core.shellapp import InteractiveShellApp
+from IPython.terminal.prompts import Prompts
+from pygments.token import Token
+from traitlets.config import Config
+
+c: Config
+c.InteractiveShell: InteractiveShell
+c.InteractiveShellApp: InteractiveShellApp
+
+
+class TimePrompt(Prompts):
+    def in_prompt_tokens(self) -> list[tuple[Token, str]]:
+        return [
+            (Token.Prompt, datetime.datetime.now().strftime("%H:%M")),
+            (Token.Prompt, " ["),
+            (Token.PromptNum, str(self.shell.execution_count)),
+            (Token.Prompt, "]: "),
+        ]
+
+    def out_prompt_tokens(self) -> list[tuple[Token, str]]:
+        return [
+            (Token.OutPrompt, datetime.datetime.now().strftime("%H:%M")),
+            (Token.OutPrompt, " ["),
+            (Token.OutPromptNum, str(self.shell.execution_count)),
+            (Token.OutPrompt, "]: "),
+        ]
+
+
+version_parts = [f"IPython {IPython.__version__}"]
+for key_library, name in (
+    ("pandas", "pd"),
+    ("numpy", "np"),
+    ("numba", "nb"),
+    ("sqlalchemy", "sa"),
+    ("pydantic", "pydantic"),
+):
+    try:
+        module = importlib.import_module(key_library)
+    except ModuleNotFoundError:
+        pass
+    else:
+        version_parts.append(f"{name} {module.__version__}")
+versions = ", ".join(version_parts)
+
+c.InteractiveShellApp.exec_lines = ["%autoreload 2"]
+c.InteractiveShellApp.extensions = ["autoreload"]
+c.InteractiveShell.history_length = 100_000
+c.InteractiveShell.history_load_length = 100_000
+c.InteractiveShell.prompts_class = TimePrompt
+c.InteractiveShell.banner1 = f"Python {sys.version.split()[0]} [{versions}]\n"
+c.InteractiveShell.banner2 = ""