nteract / scrapbook

A library for recording and reading data in notebooks.
https://nteract-scrapbook.readthedocs.io
BSD 3-Clause "New" or "Revised" License
281 stars 26 forks source link

Consider dynamically importing IPython in scrapbook.api.glue #48

Closed schrockn closed 5 years ago

schrockn commented 5 years ago

Hello!

Right now scrapbook (and papermill) incurs a fairly significant cost at import time (2 seconds) because of the transitive dependency on IPython. It would be great if this were incurred only if the the code is actually executed. We are looking at things like unit test performance and larger codebases.

Totally understand if this is not super-high priority!

MSeal commented 5 years ago

That's completely reasonable idea. It's be pretty easy to implement.

It was also raised this week that papermill doesn't even need the dependency at all now that scrapbook has the ipython specific items.

schrockn commented 5 years ago

Cool. Btw, I tried to do this quick on a fork but ran into some issues with mocks etc. Specifically @mock.patch("scrapbook.api.ip_display") in test_api.py. Don't have time to dig in today!

MSeal commented 5 years ago

Likely you need to change that to @mock.patch("IPython.display"), or if that fails the second option in https://stackoverflow.com/questions/41873928/how-can-i-mock-a-module-that-is-imported-from-a-function-and-not-present-in-sys?rq=1 is probably the best option.

MSeal commented 5 years ago

Will perform a release something soon to pick up the change.