GithubHelp home page GithubHelp logo

Comments (4)

MSeal avatar MSeal commented on July 26, 2024 1

I think papermill is a more established place for adding execution hooks in managed execution patterns, yeah. Keeping nbclient simple and low level makes it easier to understand and less opinionated about how you execute notebook code.

Want me to transfer this issue to papermill to continue the discussion about making it easier to add these particular hook patterns?

from nbclient.

MSeal avatar MSeal commented on July 26, 2024

I think you could do this in papermill by extending https://github.com/nteract/papermill/blob/master/papermill/engines.py#L231-L285 and calling a post-execution hook. Course you'd need to run code in the kernel to support it properly. Maybe a hook that saves the final line of each cell as a scrap on the notebook?

def cell_complete(self, cell, cell_index=None, **kwargs):
    post_cell = """
    result = _
    try:
      import scrapbook as sb
    except ImportError:
      print("scrapbook not installed, no outcomes saved")
    else:
      try:
        if result:
          sb.glue(f"__result_{cell_index}", result)
      except sb.ScrapbookException:
        print("Could not save result of cell {cell_index}")
    """
    self.execute_cell(post_cell, -1)
    self.super(cell, cell_index, **kwargs)

I think we'd want to expose call-backs for cell-complete and other events to the engine in papermill so you can just register an engine that supported it.

from nbclient.

choldgraf avatar choldgraf commented on July 26, 2024

yes! that is the kind of pattern that I had in mind. You think papermill would be a better home for this kind of functionality than nbclient?

Agreed that the nicer way to handle this for our use-case (since I am still not sure what the "right" UX is here) is to just make it possible to extend the back that papermill uses along w/ access to the kernel

from nbclient.

choldgraf avatar choldgraf commented on July 26, 2024

happy to do so, thanks for the explanation

from nbclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.