def generate_docs():
    index_top = """.. _source_documentation:

=============================
OpenMDAO Source Documentation
=============================

.. toctree::
   :maxdepth: 3
   :glob:


"""

    package_top = """
.. toctree::
    :maxdepth: 3

"""

    package_bottom = """
Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
"""

    ref_sheet_bottom = """
   :members:
   :undoc-members:
   :show-inheritance:

.. toctree::
   :maxdepth: 2
"""


    # need to set up the srcdocs directory structure, relative to docs.
    dir = os.path.dirname(__file__)
    if os.path.isdir(os.path.join(dir, "srcdocs")):
        import shutil
        shutil.rmtree(os.path.join(dir, "srcdocs"))
    os.mkdir(os.path.join(dir, "srcdocs"))
    os.mkdir(os.path.join(dir, "srcdocs", "packages"))


    # look for directories in the openmdao level, one up from docs
    # those directories will be the openmdao packages
    # auto-generate the top-level index.rst file for srcdocs, based on
    # openmdao packages:
    IGNORE_LIST = ['docs', 'test', 'config', 'devtools', '__pycache__']
    # to improve the order that the user sees in the source docs, put
    # the important packages in this list explicitly. Any new ones that
    # get added will show up at the end.
    packages = ['core', 'components', 'drivers', 'solvers', 'recorders',
                'surrogate_models', 'util', 'units']
    # Everything in dir that isn't discarded is appended as a source package.
    for listing in os.listdir(os.path.join(dir, "..")):
        if os.path.isdir(os.path.join("..", listing)):
            if listing not in IGNORE_LIST and listing not in packages:
                packages.append(listing)

    # begin writing the 'srcdocs/index.rst' file at top level.
    index_filename = os.path.join(dir, "srcdocs", "index.rst")
    index = open(index_filename, "w")
    index.write(index_top)

    # auto-generate package header files (e.g. 'openmdao.core.rst')
    for package in packages:
        # a package is e.g. openmdao.core, that contains source files
        # a sub_package, is a src file, e.g. openmdao.core.component
        sub_packages = []
        package_filename = os.path.join(dir, "srcdocs", "packages",
                                        "openmdao." + package + ".rst")
        package_name = "openmdao." + package

        # the sub_listing is going into each package dir and listing what's in it
        for sub_listing in sorted(os.listdir(os.path.join("..", package))):
            # don't want to catalog files twice, nor use init files nor test dir
            if (os.path.isdir(sub_listing) and sub_listing != "test") or \
               (sub_listing.endswith(".py") and not sub_listing.startswith('_')):
                # just want the name of e.g. dataxfer not dataxfer.py
                sub_packages.append(sub_listing.rsplit('.')[0])

        if len(sub_packages) > 0:
            # continue to write in the top-level index file.
            # only document non-empty packages to avoid errors
            # (e.g. at time of writing, doegenerators, drivers, are empty dirs)

            #specifically don't use os.path.join here.  Even windows wants the
            #stuff in the file to have fwd slashes.
            index.write("   packages/openmdao." + package + "\n")

            # make subpkg directory (e.g. srcdocs/packages/core) for ref sheets
            package_dirname = os.path.join(dir, "srcdocs", "packages", package)
            os.mkdir(package_dirname)

            # create/write a package index file: (e.g. "srcdocs/packages/openmdao.core.rst")
            package_file = open(package_filename, "w")
            package_file.write(package_name + "\n")
            package_file.write("-" * len(package_name) + "\n")
            package_file.write(package_top)

            for sub_package in sub_packages:
                SKIP_SUBPACKAGES = ['nn_interpolators']
                # this line writes subpackage name e.g. "core/component.py"
                # into the corresponding package index file (e.g. "openmdao.core.rst")
                if sub_package not in SKIP_SUBPACKAGES:
                    #specifically don't use os.path.join here.  Even windows wants the
                    #stuff in the file to have fwd slashes.
                    package_file.write("    " + package + "/" + sub_package + "\n")

                    # creates and writes out one reference sheet (e.g. core/component.rst)
                    ref_sheet_filename = os.path.join(package_dirname, sub_package + ".rst")
                    ref_sheet = open(ref_sheet_filename, "w")
                    # get the meat of the ref sheet code done
                    filename = sub_package + ".py"
                    ref_sheet.write(".. index:: " + filename + "\n\n")
                    ref_sheet.write(".. _" + package_name + "." + filename + ":\n\n")
                    ref_sheet.write(filename + "\n")
                    ref_sheet.write("+" * len(filename) + "\n\n")
                    ref_sheet.write(".. automodule:: " + package_name + "." + sub_package)
                    # finish and close each reference sheet.
                    ref_sheet.write(ref_sheet_bottom)
                    ref_sheet.close()

            # finish and close each package file
            package_file.write(package_bottom)
            package_file.close()

    # finish and close top-level index file
    index.close()
dataset/ETHPy150Open OpenMDAO/OpenMDAO/openmdao/docs/conf.py/generate_docs/original