def add_test_yaml_files(cls): """Add in dodgy yaml files in an extra nbextensions dir.""" cls.jupyter_dirs['dodgy'] = { 'nbexts': os.path.join(cls.jupyter_dirs['root'], 'dodgy', 'nbext') } dodgy_nbext_dir_path = cls.jupyter_dirs['dodgy']['nbexts'] if not os.path.exists(dodgy_nbext_dir_path): os.makedirs(dodgy_nbext_dir_path) cls.config.NotebookApp.setdefault('extra_nbextensions_path', []).append(dodgy_nbext_dir_path) # an invalid yaml file yaml_path_invalid = os.path.join(dodgy_nbext_dir_path, 'nbext_invalid_yaml.yaml') with io.open(yaml_path_invalid, 'w') as f: f.write('not valid yaml!: [') # various test yaml files test_yamls = { # we use str() because otherwise python2 will write # !!python/unicode in the yaml, and pyyaml SafeLoader will refuse # to reconstruct the objects :( boo! 'not_an_nbext': [ str('valid yaml'), str("doesn't always"), str('make for a valid nbext yaml, right?'), 3423509 ], 'missing_key': { str('Main'): True }, 'invalid_type': { str('Main'): str('main.js'), str('Type'): str('blahblahblah') }, 'dummy': { str('Main'): str('dummy.js'), str('Type'): str('Jupyter Notebook Extension'), str('Description'): str('This is a dumb dummy description'), str('Compatibility'): str('4.x 5.x'), }, } for fname, yaml_obj in test_yamls.items(): yaml_path = os.path.join(dodgy_nbext_dir_path, fname + '.yaml') with io.open(yaml_path, 'w') as f: yaml.dump(yaml_obj, f, default_flow_style=False) # a yaml file which shadows an existing nbextension. nbdir = os.path.join( os.path.dirname(jupyter_nbextensions_configurator.__file__), 'static') nbexts = ( jupyter_nbextensions_configurator.get_configurable_nbextensions( [nbdir], as_dict=True)) src = random.choice(list(nbexts.values()))['yaml_path'] dst = os.path.join(dodgy_nbext_dir_path, os.path.relpath(src, start=nbdir)) dst_dir = os.path.dirname(dst) if not os.path.exists(dst_dir): os.makedirs(dst_dir) shutil.copy(src, dst)
def add_test_yaml_files(cls): """Add in dodgy yaml files in an extra nbextensions dir.""" cls.jupyter_dirs['dodgy'] = { 'nbexts': os.path.join(cls.jupyter_dirs['root'], 'dodgy', 'nbext')} dodgy_nbext_dir_path = cls.jupyter_dirs['dodgy']['nbexts'] if not os.path.exists(dodgy_nbext_dir_path): os.makedirs(dodgy_nbext_dir_path) cls.config.NotebookApp.setdefault( 'extra_nbextensions_path', []).append(dodgy_nbext_dir_path) # an invalid yaml file yaml_path_invalid = os.path.join( dodgy_nbext_dir_path, 'nbext_invalid_yaml.yaml') with io.open(yaml_path_invalid, 'w') as f: f.write('not valid yaml!: [') # various test yaml files test_yamls = { # we use str() because otherwise python2 will write # !!python/unicode in the yaml, and pyyaml SafeLoader will refuse # to reconstruct the objects :( boo! 'not_an_nbext': [ str('valid yaml'), str("doesn't always"), str('make for a valid nbext yaml, right?'), 3423509], 'missing_key': {str('Main'): True}, 'invalid_type': { str('Main'): str('main.js'), str('Type'): str('blahblahblah') }, 'dummy': { str('Main'): str('dummy.js'), str('Type'): str('Jupyter Notebook Extension'), str('Description'): str('This is a dumb dummy description'), str('Compatibility'): str('4.x 5.x'), }, } for fname, yaml_obj in test_yamls.items(): if fname != 'dummy': nt.assert_not_is_instance( jupyter_nbextensions_configurator._process_nbextension_spec(yaml_obj), # noqa: E501 dict) yaml_path = os.path.join(dodgy_nbext_dir_path, fname + '.yaml') with io.open(yaml_path, 'w') as f: yaml.dump(yaml_obj, f, default_flow_style=False) # a yaml file which shadows an existing nbextension. nbdir = os.path.join( os.path.dirname(jupyter_nbextensions_configurator.__file__), 'static') nbexts = ( jupyter_nbextensions_configurator.get_configurable_nbextensions( [nbdir], as_dict=True)) src = random.choice(list(nbexts.values()))['yaml_path'] dst = os.path.join( dodgy_nbext_dir_path, os.path.relpath(src, start=nbdir)) dst_dir = os.path.dirname(dst) if not os.path.exists(dst_dir): os.makedirs(dst_dir) shutil.copy(src, dst)
def _jupyter_nbextension_paths(): """Magically-named function for jupyter extension installations.""" nbextension_dirs = [ os.path.join(os.path.dirname(__file__), 'nbextensions')] specs = jupyter_nbextensions_configurator.get_configurable_nbextensions( nbextension_dirs=nbextension_dirs) return [dict( section=nbext['Section'], # src is a directory in which we assume the require file resides. # the path is relative to the package directory src=os.path.join( 'nbextensions', os.path.dirname(nbext['require']) ), # directory in the `nbextension/` namespace dest=os.path.dirname(nbext['require']), # _also_ in the `nbextension/` namespace require=nbext['require'], ) for nbext in specs]
def add_dodgy_yaml_files(cls): """Add in dodgy yaml files in an extra nbextensions dir.""" cls.jupyter_dirs['dodgy'] = { 'nbexts': os.path.join(cls.jupyter_dirs['root'], 'dodgy', 'nbext')} dodgy_nbext_dir_path = cls.jupyter_dirs['dodgy']['nbexts'] os.makedirs(dodgy_nbext_dir_path) cls.config.NotebookApp.setdefault( 'extra_nbextensions_path', []).append(dodgy_nbext_dir_path) # an invalid yaml file yaml_path_invalid = os.path.join( dodgy_nbext_dir_path, 'nbext_invalid_yaml.yaml') with io.open(yaml_path_invalid, 'w') as f: f.write('not valid yaml!: [') # a yaml file which isn't a dict dodgy_yamls = { 'not_an_nbext': ['valid yaml', "doesn't always", 'make for a valid nbext yaml, right?', 3423509], 'missing_key': {'Main': True}, 'invalid_type': {'Main': 'main.js', 'Type': 'blahblahblah'} } for fname, yaml_obj in dodgy_yamls.items(): yaml_path = os.path.join(dodgy_nbext_dir_path, fname + '.yaml') with io.open(yaml_path, 'w') as f: yaml.dump(yaml_obj, f) # a yaml file which shadows an existing nbextension. nbdir = os.path.join( os.path.dirname(jupyter_nbextensions_configurator.__file__), 'static') nbexts = ( jupyter_nbextensions_configurator.get_configurable_nbextensions( [nbdir], as_dict=True)) src = random.choice(list(nbexts.values()))['yaml_path'] dst = os.path.join( dodgy_nbext_dir_path, os.path.relpath(src, start=nbdir)) dst_dir = os.path.dirname(dst) if not os.path.exists(dst_dir): os.makedirs(dst_dir) shutil.copy(src, dst)
log.info('---- installing nbextensions into {}'.format(nbext_dir)) do_symlink = hasattr(os, 'symlink') and os.name not in ('nt', 'dos') log.info( '---- {}using symlinks for install'.format('' if do_symlink else 'not ')) jupyter_contrib_nbextensions.install.toggle_install_files( True, logger=log, nbextensions_dir=nbext_dir, overwrite=True, symlink=do_symlink, ) log.info('-------- finished nbextensions install') log.info('Writing Sphinx doc file {}'.format(destination)) log.info('looking for nbextensions in {}...'.format(nbext_dir)) nbextensions = sorted(get_configurable_nbextensions([nbext_dir], log=log), key=lambda a: a['Name'].lower()) header = """ .. This is an automatically generated file. Do not modify by hand. List of provided nbextensions ============================= .. toctree:: :maxdepth: 1 """ with open(destination, 'w') as f:
log.info('---- installing nbextensions into {}'.format(nbext_dir)) do_symlink = hasattr(os, 'symlink') and os.name not in ('nt', 'dos') log.info('---- {}using symlinks for install'.format( '' if do_symlink else 'not ')) jupyter_contrib_nbextensions.install.toggle_install_files( True, logger=log, nbextensions_dir=nbext_dir, overwrite=True, symlink=do_symlink, ) log.info('-------- finished nbextensions install') log.info('Writing Sphinx doc file {}'.format(destination)) log.info('looking for nbextensions in {}...'.format(nbext_dir)) nbextensions = sorted( get_configurable_nbextensions([nbext_dir], log=log), key=lambda a: a['Name'].lower()) header = """ .. This is an automatically generated file. Do not modify by hand. List of provided nbextensions ============================= .. toctree:: :maxdepth: 1 """ with open(destination, 'w') as f: