skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
ipython profile updates
description
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.
cells
6 total
3 code
state
executed in order
kernel
Python [conda env:p311] *
language
python
name
conda-env-p311-py
lines of code
38
outputs
2
table of contents
{"kernelspec": {"display_name": "Python [conda env:p311] *", "language": "python", "name": "conda-env-p311-py"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}, "title": "ipython profile updates", "description": "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."}
notebook toolbar
Activate
cell ordering
1

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.

2 1 outputs.

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")
3

config_source contains the lines of code we want to write to our configuration.

4
    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]
        print("my config loaded")
        """
                
        c.InteractiveShellApp.exec_lines = source.splitlines()
5 1 outputs.

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))
6

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.