Beispiel #1
0
 def get_code(self, fullname):
     if self.path.endswith('.ipynb'):
         with open(self.path) as f:
             nb = json.load(f)
             if not validate_nb(nb):
                 raise ImportError('Could not import {path} for {fn}: not a valid ipynb file'.format(
                     path=self.path,
                     fn=fullname
                 ))
             return self.source_to_code(get_code(nb), self.path)
     else:
         return super().get_code(fullname)
Beispiel #2
0
 def get_code(self, fullname):
     if self.path.endswith('.ipynb'):
         with open(self.path) as f:
             try:
                 nb = json.load(f)
             except ValueError:
                 # This is when it isn't a valid json file
                 raise ImportError(
                     'Could not import {path} for {fn}: not a valid ipynb file'
                     .format(path=self.path, fn=fullname))
             if not validate_nb(nb):
                 # This is when it isn't the appropriate
                 # nbformet version or language
                 raise ImportError(
                     'Could not import {path} for {fn}: incorrect version or language'
                     .format(path=self.path, fn=fullname))
             return self.source_to_code(code_from_ipynb(nb), self.path)
     else:
         return super().get_code(fullname)