<commit_before>import inspect
import re
import numpy as np
import os
import sys
import shutil

# Mock the paraview module to build pvmacros docs
import mock

MOCK_MODULES = ['paraview', 'paraview.simple']
for mod_name in MOCK_MODULES:
    sys.modules[mod_name] = mock.Mock()

path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, path)

import PVGeo

if os.path.exists('./suites'):
    shutil.rmtree('./suites')
os.makedirs('./suites')
if os.path.exists('./pvmacros'):
    shutil.rmtree('./pvmacros')
os.makedirs('./pvmacros')


##########
global moddoccer
moddoccer = r'''

%s
%s

.. automodule:: %s

'''
global classdoccer
classdoccer = r'''

%s
%s

.. auto%s:: %s
    :show-inheritance:
    :members:
    :undoc-members:
    :private-members:

'''
global defdoccer
defdoccer = r'''

%s
%s

.. auto%s:: %s

'''

with open('../index_base.rst', 'r') as fid:
    index = fid.read()
    fid.close()





appIndex = '''

.. toctree::
   :maxdepth: 3
   :caption: PVGeo:
'''


############
global choices
choices = ['base', 'reader', 'filter', 'writer', 'source', 'macro', 'script']
global counts
counts = [0]*len(choices)

table = r'''

Current Statistics
------------------

.. csv-table::
   :header: "Bases", "Readers", "Filters", "Writers", "Sources", "Macros"

   %d, %d, %d, %d, %d, %d

'''

# Write out all of the pages
def MakeFiles(mods, path, modname):
    appIndex = '''

.. toctree::
   :maxdepth: 3
   :caption: %s:
    ''' % modname
    for mod in mods:
        if mod[0][0:2] == '__':
            continue
        try:
            name = mod[1].__displayname__
        except AttributeError:
            name = mod[1].__name__
        feats = inspect.getmembers(mod[1])
        fname = name.replace(' ', '-')+'.rst'
        appIndex += '\n   %s/%s' % (path, fname)

        with open('./%s/%s' % (path, fname), 'w') as fid:
            fid.write(moddoccer % (name, '-'*len(name), mod[1].__name__)) # Page header is module name
            for f in feats:
                # Check for a __displayname__
                if inspect.isclass(f[1]) or inspect.isfunction(f[1]):
                    try:
                        featname = f[1].__displayname__
                    except AttributeError:
                        featname = f[1].__name__
                    # Make the auto doc rst
                    if inspect.isclass(f[1]):
                        fid.write(classdoccer % (featname, '^'*len(featname), 'class', '%s.%s' % (mod[1].__name__, f[1].__name__) ))
                    elif inspect.isfunction(f[1]):
                         fid.write(defdoccer % (featname, '^'*len(featname), 'function', '%s.%s' % (mod[1].__name__, f[1].__name__) ))
                    # Check for stats report
                    try:
                        featType = f[1].__type__
                    except AttributeError:
                        featType = None
                    if featType is not None:
                        # Count the featers
                        for i in range(len(choices)):
                            if featType in choices[i]:
                                counts[i] += 1
            fid.close()
    return appIndex

mods = inspect.getmembers(PVGeo, inspect.ismodule)
appIndex = MakeFiles(mods, 'suites', 'PVGeo')


import pvmacros
mods = inspect.getmembers(pvmacros, inspect.ismodule)
appIndex += MakeFiles(mods, 'pvmacros', 'pvmacros')

# Make the stats report table:

index += table % (counts[0], counts[1], counts[2], counts[3], counts[4], counts[5])

with open('./index.rst', 'w') as fid:
    fid.write(index + appIndex)<commit_msg>Made PVGeo easier to navigate in docs<commit_after>import inspect
import os
import sys
import shutil

# Mock the paraview module to build pvmacros docs
import mock

MOCK_MODULES = ['paraview', 'paraview.simple']
for mod_name in MOCK_MODULES:
    sys.modules[mod_name] = mock.Mock()

path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, path)

import PVGeo

if os.path.exists('./suites'):
    shutil.rmtree('./suites')
os.makedirs('./suites')
if os.path.exists('./pvmacros'):
    shutil.rmtree('./pvmacros')
os.makedirs('./pvmacros')


##########
global moddoccer
moddoccer = r'''

%s
%s

.. automodule:: %s

'''
global classdoccer
classdoccer = r'''

%s
%s

.. auto%s:: %s
    :show-inheritance:
    :members:
    :undoc-members:
    :private-members:

'''
global defdoccer
defdoccer = r'''

%s
%s

.. auto%s:: %s

'''

with open('../index_base.rst', 'r') as fid:
    index = fid.read()
    fid.close()





appIndex = '''

.. toctree::
   :maxdepth: 3
   :caption: PVGeo:
'''


############
global choices
choices = ['base', 'reader', 'filter', 'writer', 'source', 'macro', 'script']
global counts
counts = [0]*len(choices)

table = r'''

Current Statistics
------------------

.. csv-table::
   :header: "Bases", "Readers", "Filters", "Writers", "Sources", "Macros"

   %d, %d, %d, %d, %d, %d

'''

# Write out all of the pages
def MakeFiles(mods, path, modname):
    appIndex = '''

.. toctree::
   :maxdepth: 3
   :caption: %s:
    ''' % modname
    for mod in mods:
        if mod[0][0:2] == '__':
            continue
        try:
            name = mod[1].__displayname__
        except AttributeError:
            name = mod[1].__name__
        feats = inspect.getmembers(mod[1])
        fname = name.replace(' ', '-')+'.rst'
        appIndex += '\n   %s/%s' % (path, fname)

        with open('./%s/%s' % (path, fname), 'w') as fid:
            fid.write(moddoccer % (name, '-'*len(name), mod[1].__name__)) # Page header is module name
            for f in feats:
                # Check for a __displayname__
                if inspect.isclass(f[1]) or inspect.isfunction(f[1]):
                    try:
                        featname = f[1].__displayname__
                    except AttributeError:
                        featname = f[1].__name__
                    # Make the auto doc rst
                    if inspect.isclass(f[1]):
                        fid.write(classdoccer % (featname, '^'*len(featname), 'class', '%s.%s' % (mod[1].__name__, f[1].__name__) ))
                    elif inspect.isfunction(f[1]):
                         fid.write(defdoccer % (featname, '^'*len(featname), 'function', '%s.%s' % (mod[1].__name__, f[1].__name__) ))
                    # Check for stats report
                    try:
                        featType = f[1].__type__
                    except AttributeError:
                        featType = None
                    if featType is not None:
                        # Count the featers
                        for i in range(len(choices)):
                            if featType in choices[i]:
                                counts[i] += 1
            fid.close()
    return appIndex

mods = inspect.getmembers(PVGeo, inspect.ismodule)
nmods, pvt = [], []
for mod in mods:
    if mod[0][0] == '_': pvt.append(mod)
    else: nmods.append(mod)
nmods += pvt
appIndex = MakeFiles(nmods, 'suites', 'PVGeo')


import pvmacros
mods = inspect.getmembers(pvmacros, inspect.ismodule)
appIndex += MakeFiles(mods, 'pvmacros', 'pvmacros')

# Make the stats report table:

index += table % (counts[0], counts[1], counts[2], counts[3], counts[4], counts[5])

with open('./index.rst', 'w') as fid:
    fid.write(index + appIndex)
{'fraction_non_alphanumeric': 0.16560336636351297, 'fraction_numerical': 0.00814442785394326, 'mean_word_length': 2.101010101010101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4520972', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2469, 'n_words': 588}