Skip to content

Instantly share code, notes, and snippets.

@joannapurosto
Created December 19, 2018 14:51
Show Gist options
  • Save joannapurosto/0a825491c042c968d614ef06ae0807a4 to your computer and use it in GitHub Desktop.
Save joannapurosto/0a825491c042c968d614ef06ae0807a4 to your computer and use it in GitHub Desktop.
Example for notebook blog
from IPython.core.magic import Magics, magics_class, cell_magic
import os
@magics_class
class ValohaiMagics(Magics):
@cell_magic
def valohai(self, line='', cell=None):
path = os.path.expanduser('~/%s/execute.py' % project)
with open(path, 'w+') as f:
f.write(cell)
path = os.path.expanduser('~/%s/valohai.yaml' % project)
with open(path, 'w+') as f:
f.write('- step:\r\n')
f.write(' name: jupyter_execution\r\n')
f.write(' image: %s\r\n' % docker)
f.write(' command: python execute.py\r\n')
print('Starting execution in Valohai...')
!vh execution run --adhoc jupyter_execution
!vh execution logs --stream latest
ip = get_ipython()
ip.register_magics(ValohaiMagics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment