ipython profile updatesยค
when i want to write, i really want to write! i don't want to import
modules i know i should have access to. i only care about this in interactive computing circumstances. i need to satisfy my compulsion to write new things, and avoid the old things. a revision stage after this initial burst will formalize the reuse of the module.
we're going to supply ourselves with better literate programming interfaces by defining a custom ipython configuration file that is loaded by default. once the configuration is applied we have a superior literate and functional programming vocabulary than we are normally offered.
%%
programmatically discover the default `ipython profile location` which is where we need to write or update our configuration at.
config = !ipython profile locate
config = pathlib.Path(*config, "ipython_config.py")
config_source
contains the lines of code we want to write to our configuration.
def config_source():
source = """from nobook.utils import Index, Series, DataFrame, doctest
import midgy, anyio, pyperclip, importnb
from pathlib import Path
from IPython.display import *
from dataclasses import dataclass, field
from toolz.curried import *
with importnb.Notebook(): from __llm_workflow import load_ipython_extension
load_ipython_extension(get_ipython())
del load_ipython_extension
[get_ipython().user_ns.setdefault(k, v) for k, v in __import__("sys").modules.items() if "." not in k]
# allow relative imports
get_ipython().user_ns["__path__"] = [""]
get_ipython().user_ns["__package__"] = __name__ = "__main__"
from midgy.language.python import HTML, Css, Script
print("my config loaded")
"""
c.InteractiveShellApp.exec_lines = source.splitlines()
%%
write the `config_source` to disc
config.write_text(textwrap.dedent(
"".join(inspect.getsourcelines(config_source)[0][1:])
))
when we restart our kernel we should have some new variables
that we can use by default.
* i always want my pandas dataframes because i use them as first class citizens
>>> assert all((Index, Series, DataFrame))
* we loaded in all the modules we know about from `sys` modules. this enriched namespace makes it easier to continue flowing thoughts.
>>> assert all((pathlib,))
* `toolz` is the shit for functional programming, especially the curried versions. we want them to shred faster.
>>> assert all((operator, compose, pipe))
all these modifications make it possible run this without any imports. we start with imports, but could remove them after our configuration was defined properly.