<commit_before>from bokeh.vendor.pycco import generate_func_docs
import os
_basedir = os.path.dirname(__file__)


demo_dir = os.path.join(_basedir, "../bokeh/server/static/demos")
demo_dir = os.path.join(_basedir, "../../gh-pages-Bokeh")
detail_dir = os.path.join(demo_dir, "detail")

def page_desc(prev_infos, f):
    if len(prev_infos) > 0:
        prev_info = prev_infos[-1]
    else:
        prev_info = {}
    name_ = f.__name__
    #I need to make sure I know where to put this snippet, where I
    #want it written
    plot = f()
    embed_snippet = plot.script_direct_inject(
        detail_dir, static_path="https://s3.amazonaws.com/bokeh_docs/0.2/", embed_path="/Bokeh/detail/")
    page_info = dict(
        f=f, name=name_, embed_snippet=embed_snippet,
        detail_snippet = generate_func_docs(f, ""),
        detail_page_url="/Bokeh/detail/" + name_ + ".html",
        prev_detail_url=prev_info.get('detail_page_url', ""),
        prev_detail_name=prev_info.get('name', ""))
    if len(prev_infos) == 0:
        prev_infos = [page_info]
    else:
        prev_infos.append(page_info)

    return prev_infos

def _load_template(filename):
    import jinja2
    with open(os.path.join(_basedir, filename)) as f:
        return jinja2.Template(f.read())

def make_gallery(functions):
    page_infos = reduce(page_desc, functions, [])
    for p, p_next in [[p, page_infos[i+1]] for i, p in enumerate(page_infos[:-1])]:
        p['next_detail_url'] = p_next['detail_page_url']
        p['next_detail_name'] = p_next['name']
    t = _load_template("detail.html")
    for info in page_infos:
        fname = os.path.join(detail_dir, info['name'] + ".html")
        print " writing to ", fname
        with open(fname, "w") as f:
            f.write(t.render(info))
    with open(os.path.join(demo_dir, "index.html"), "w") as f:
        f.write(
            _load_template("gallery.html").render(page_infos=page_infos))

if __name__ == "__main__":
    from plotting.file import (
        iris, candlestick, correlation, legend,
        glucose, stocks, line, rect, glyphs, scatter)
    
    example_funcs = [
        iris.iris, candlestick.candlestick, legend.legend, 
        correlation.correlation,<commit_msg> now writing out the gallery as gallery.html<commit_after>from bokeh.vendor.pycco import generate_func_docs
import os
_basedir = os.path.dirname(__file__)


demo_dir = os.path.join(_basedir, "../bokeh/server/static/demos")
demo_dir = os.path.join(_basedir, "../../gh-pages-Bokeh")
detail_dir = os.path.join(demo_dir, "detail")

def page_desc(prev_infos, f):
    if len(prev_infos) > 0:
        prev_info = prev_infos[-1]
    else:
        prev_info = {}
    name_ = f.__name__
    #I need to make sure I know where to put this snippet, where I
    #want it written
    plot = f()
    embed_snippet = plot.script_direct_inject(
        detail_dir, static_path="https://s3.amazonaws.com/bokeh_docs/0.2/", embed_path="/Bokeh/detail/")
    page_info = dict(
        f=f, name=name_, embed_snippet=embed_snippet,
        detail_snippet = generate_func_docs(f, ""),
        detail_page_url="/Bokeh/detail/" + name_ + ".html",
        prev_detail_url=prev_info.get('detail_page_url', ""),
        prev_detail_name=prev_info.get('name', ""))
    if len(prev_infos) == 0:
        prev_infos = [page_info]
    else:
        prev_infos.append(page_info)

    return prev_infos

def _load_template(filename):
    import jinja2
    with open(os.path.join(_basedir, filename)) as f:
        return jinja2.Template(f.read())

def make_gallery(functions):
    page_infos = reduce(page_desc, functions, [])
    for p, p_next in [[p, page_infos[i+1]] for i, p in enumerate(page_infos[:-1])]:
        p['next_detail_url'] = p_next['detail_page_url']
        p['next_detail_name'] = p_next['name']
    t = _load_template("detail.html")
    for info in page_infos:
        fname = os.path.join(detail_dir, info['name'] + ".html")
        print " writing to ", fname
        with open(fname, "w") as f:
            f.write(t.render(info))
    with open(os.path.join(demo_dir, "gallery.html"), "w") as f:
        f.write(
            _load_template("gallery.html").render(page_infos=page_infos))

if __name__ == "__main__":
    from plotting.file import (
        iris, candlestick, correlation, legend,
        glucose, stocks, line, rect, glyphs, scatter)
    
    example_funcs = [
        iris.iris, candlestick.candlestick, legend.legend, 
        correlation.correlation,
{'fraction_non_alphanumeric': 0.1369832402234637, 'fraction_numerical': 0.004469273743016759, 'mean_word_length': 3.1253456221198155, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1519769', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1568, 'n_words': 314}