Created
February 26, 2014 23:47
-
-
Save ahmadia/9241260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
An IPython extension for specifying requirements | |
""" | |
import os | |
from subprocess import check_call | |
from IPython.core.magic import magics_class, cell_magic, Magics | |
@magics_class | |
class ThisWorks(Magics): | |
@cell_magic | |
def thisworks(self, line, cell): | |
"""Specify requirements for a notebook. | |
Usage: | |
%thisworks profile_name | |
""" | |
profile_name = line | |
if not profile_name: | |
profile_name = 'this_works' | |
profile_contents = cell | |
with open(profile_name + ".yaml", "w") as file: | |
file.write(profile_contents) | |
check_call(["hit","build",profile_name+".yaml"]) | |
ipython_path = os.path.join(profile_name, 'bin', 'ipython') | |
check_call([ipython_path, "notebook"]) | |
def load_ipython_extension(ipython): | |
ipython.register_magics(ThisWorks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment