human
Write me a the Python code you requested given the following:
Complete the below
def bundle_models(models):

    ''''Create a bundle of `models`.'
    '''
assistant
#Here is the Python code you requested.
    custom_models = {}
    for cls in models:
        impl = getattr(cls, '__implementation__', None)
        if (impl is not None):
            model = CustomModel(cls)
            custom_models[model.full_name] = model
    if (not custom_models):
        return None
    ordered_models = sorted(custom_models.values(), key=(lambda model: model.full_name))
    exports = []
    modules = []
    def read_json(name):
        with io.open(join(bokehjs_dir, 'js', (name + '.json')), encoding='utf-8') as f:
            return json.loads(f.read())
    bundles = ['bokeh', 'bokeh-api', 'bokeh-widgets', 'bokeh-tables', 'bokeh-gl']
    known_modules = set(sum([read_json(name) for name in bundles], []))
    custom_impls = {}
    dependencies = []
    for model in ordered_models:
        dependencies.extend(list(model.dependencies.items()))
    if dependencies:
        dependencies = sorted(dependencies, key=(lambda name_version: name_version[0]))
        _run_npmjs((['install', '--no-progress'] + [((name + '@') + version) for (name, version) in dependencies]))
    for model in ordered_models:
        impl = model.implementation
        compiled = nodejs_compile(impl.code, lang=impl.lang, file=impl.file)
        if ('error' in compiled):
            raise CompilationError(compiled.error)
        custom_impls[model.full_name] = compiled
    extra_modules = {}
    def resolve_modules(to_resolve, root):
        resolved = {}
        for module in to_resolve:
            if module.startswith(('./', '../')):
                def mkpath(module, ext=''):
                    return abspath((join(root, *module.split('/')) + ext))
                if module.endswith(exts):
                    path = mkpath(module)
                    if (not exists(path)):
                        raise RuntimeError(('no    such    module:    %s' % module))
                else:
                    for ext in exts:
                        path = mkpath(module, ext)
                        if exists(path):
                            break
              ...