Repository: pandas-dev/pandas
File: web/pandas_web.py (Python)

Code before:

    shutil.rmtree(target_path, ignore_errors=True)
    os.makedirs(target_path, exist_ok=True)

    sys.stderr.write("Generating context...\n")
    context = get_context(config_fname, target_path=target_path)
    sys.stderr.write("Context generated\n")

    templates_path = os.path.join(source_path, context["main"]["templates_path"])
    jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_path))

    for fname in get_source_files(source_path):
        if os.path.normpath(fname) in context["main"]["ignore"]:
            continue

        sys.stderr.write(f"Processing {fname}\n")
        dirname = os.path.dirname(fname)
        os.makedirs(os.path.join(target_path, dirname), exist_ok=True)

        extension = os.path.splitext(fname)[-1]
        if extension in (".html", ".md"):
            with open(os.path.join(source_path, fname), encoding="utf-8") as f:
                content = f.read()
            if extension == ".md":
                if "pdeps/" in fname:
                    from markdown.extensions.toc import TocExtension

                    body = markdown.markdown(
                        content,
                        extensions=[
                            # Ignore the title of the PDEP in the table of contents
                            TocExtension(
                                title="Table of Contents",
                                toc_depth="2-3",
                                permalink=" #",
                            ),
                            "tables",
                            "fenced_code",
                            "meta",
                            "footnotes",
                            "codehilite",
                        ],
                    )
                else:
                    body = markdown.markdown(
                        content, extensions=context["main"]["markdown_extensions"]
                    )
                # Apply Bootstrap's table formatting manually
                # Python-Markdown doesn't let us config table attributes by hand
                body = body.replace("<table>", '<table class="table table-bordered">')
                content = extend_base_template(body, context["main"]["base_template"])

Review comment (suggestion):
Because of the use of `TocExtension` below, we can't use the usual yaml. Not sure if there is a work around or a better approach here.

Code after:
    config_fname = os.path.join(source_path, "config.yml")

    shutil.rmtree(target_path, ignore_errors=True)
    os.makedirs(target_path, exist_ok=True)

    sys.stderr.write("Generating context...\n")
    context = get_context(config_fname, target_path=target_path)
    sys.stderr.write("Context generated\n")

    templates_path = os.path.join(source_path, context["main"]["templates_path"])
    jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(templates_path))

    for fname in get_source_files(source_path):
        if os.path.normpath(fname) in context["main"]["ignore"]:
            continue

        sys.stderr.write(f"Processing {fname}\n")
        dirname = os.path.dirname(fname)
        os.makedirs(os.path.join(target_path, dirname), exist_ok=True)

        extension = os.path.splitext(fname)[-1]
        if extension in (".html", ".md"):
            with open(os.path.join(source_path, fname), encoding="utf-8") as f:
                content = f.read()
            if extension == ".md":
                if "pdeps/" in fname:
                    from markdown.extensions.toc import TocExtension

                    body = markdown.markdown(
                        content,
                        extensions=[
                            # Ignore the title of the PDEP in the table of contents
                            TocExtension(
                                title="Table of Contents",
                                toc_depth="2-3",
                                permalink=" #",
                            ),
                            "tables",
                            "fenced_code",
                            "meta",
                            "footnotes",
                            "codehilite",
                        ],
                    )
                else:
                    body = markdown.markdown(
                        content, extensions=context["main"]["markdown_extensions"]
                    )
                # Apply Bootstrap's table formatting manually
                # Python-Markdown doesn't let us config table attributes by hand
                body = body.replace("<table>", '<table class="table table-bordered">')