deathbeds / importnb

notebook files as source
https://importnb.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
68 stars 5 forks source link

introduce an entry points interface for loading modules #140

Closed tonyfast closed 1 year ago

tonyfast commented 1 year ago

to me, this is a significant change to importnb because it feels like the new api surface for importing alternative documents. the new interface looks like:

with imports("ipynb", "json", "yaml", "toml"):
     import Untitled, package, mkdocs, pyproject

the context manager resolves the [project.entry-points.importnb] definitions and appends the loader associated with them to the sys.path_hooks. within the context, any of the aliased loaders are free game for python to import.

this approach allows other packages to make their loaders available to a single API. midgy, a package for using markdown files as python scripts, defines the md entry point. so with midgy installed:

with imports("md"):
     import README

code is not special

we're in the midst of adopting computational literacy as mass literacy. code is everywhere and people are eager to learn it. they are finding coding embedded in common file formats like markdown, docx, pptx, pdf, zip, ... it is in every nook and cranny of daily life. being restrictive about what is code will exhaust the enforcer.

importnb started as a way to avoid copy/pasting code from jupyter notebooks to python to test it efficacy; the redundancy in work seemed counterintuitive. as a tool, importnb allow us to hide a lot of complex logic that might hinder the literary quality of a notebook. it allowed us to use notebooks to talk about notebooks, and, as always, we had fun doing it.

ultimately, importnb became a powerful tool for tuning the literary qualities of notebooks for docs, demos, and blogs. it allowed us to tell more complex stories by encapsulating logic in different notebook documents. ultimately, importnb and these inclusive importing features exist for the sake of the story; they exist as literary devices.

the concept of importing non-python documents seems consistent with the message in computer programming for everybody. i feel like part of that mission requires a more inclusive perspective on what is code. one way to express this belief is to permit imports of othered code.

problems

tonyfast commented 1 year ago

well fuck a :duck:! in order to have entry points, we need an optional dependency for importlib.metadata for python 3.7 only. i think it still counts as no deps, at least in a few months it will be true.