<commit_before># vim:ts=4:sts=4:sw=4:expandtab

import os
from   sphinx.application import Sphinx
import sphinx.ext.autodoc
import shutil
import sys

from satori.ars.model import *

from sphinx.addnodes import desc_parameter, desc_returns
from sphinx.domains.python import PythonDomain, PyClassmember
from docutils.statemachine import ViewList
from sphinx.util.docfields import DocFieldTransformer

class PyRichMethod(PyClassmember):
    def handle_signature(self, sig, signode):
        ret = super(PyRichMethod, self).handle_signature(sig, signode)
        for child in signode.traverse(desc_parameter):
            t = child[0]
            del child[0]
            l = ViewList()
            l.append(t.astext(), '<AA>')
            self.state.nested_parse(l, 0, child)
            DocFieldTransformer(self).transform_all(child)
        for child in signode.traverse(desc_returns):
            t = child[0]
            del child[0]
            l = ViewList()
            l.append(t.astext(), '<AA>')
            self.state.nested_parse(l, 0, child)
            DocFieldTransformer(self).transform_all(child)
        return ret

PythonDomain.directives['richmethod'] = PyRichMethod


def prepare_doc(obj, indent):
    doc = obj.__dict__.get('__doc__', None)

    if doc is None:
        return ''

    return '\n'.join(' ' * indent + docline for docline in doc.split('\n'))


def T(text):
    lines = text.split('\n')

    if lines:
        del lines[0]

    if not lines:
        return ''

    counter = 0
    while (len(lines[0]) > counter) and (lines[0][counter] == ' '):
        counter += 1

    return '\n'.join(line[counter:] for line in lines[1:]) + '\n'

def reference_type(type):
    if isinstance(type, ArsAtomicType):
        return {
            ArsBoolean: ':py:class:`bool`',
            ArsInt8:    ':py:class:`byte`',
            ArsInt16:   ':py:class:`i16`',
            ArsInt32:   ':py:class:`i32`',
            ArsInt64:   ':py:class:`i64`',
            ArsFloat:   ':py:class:`double`',
            ArsString:  ':py:class:`string`',
            ArsVoid:    ':py:class:`void`',
        }[type]
    elif isinstance(type, ArsList):
        return 'list<{0}>'.format(reference_type(type.element_type))
    elif isinstance(type, ArsMap):
        return 'map<{0}, {1}>'.format(reference_type(type.key_type), reference_type(type.value_type))
    elif isinstance(type, ArsNamedType):
        return ':py:class:`{0}`'.format(type.name)<commit_msg>Changed list<> and map<> to display as classes.<commit_after># vim:ts=4:sts=4:sw=4:expandtab

import os
from   sphinx.application import Sphinx
import sphinx.ext.autodoc
import shutil
import sys

from satori.ars.model import *

from sphinx.addnodes import desc_parameter, desc_returns
from sphinx.domains.python import PythonDomain, PyClassmember
from docutils.statemachine import ViewList
from sphinx.util.docfields import DocFieldTransformer

class PyRichMethod(PyClassmember):
    def handle_signature(self, sig, signode):
        ret = super(PyRichMethod, self).handle_signature(sig, signode)
        for child in signode.traverse(desc_parameter):
            t = child[0]
            del child[0]
            l = ViewList()
            l.append(t.astext(), '<pyrichmethod>')
            self.state.nested_parse(l, 0, child)
            DocFieldTransformer(self).transform_all(child)
        for child in signode.traverse(desc_returns):
            t = child[0]
            del child[0]
            l = ViewList()
            l.append(t.astext(), '<pyrichmethod>')
            self.state.nested_parse(l, 0, child)
            DocFieldTransformer(self).transform_all(child)
        return ret

PythonDomain.directives['richmethod'] = PyRichMethod


def prepare_doc(obj, indent):
    doc = obj.__dict__.get('__doc__', None)

    if doc is None:
        return ''

    return '\n'.join(' ' * indent + docline for docline in doc.split('\n'))


def T(text):
    lines = text.split('\n')

    if lines:
        del lines[0]

    if not lines:
        return ''

    counter = 0
    while (len(lines[0]) > counter) and (lines[0][counter] == ' '):
        counter += 1

    return '\n'.join(line[counter:] for line in lines[1:]) + '\n'

def reference_type(type):
    if isinstance(type, ArsAtomicType):
        return {
            ArsBoolean: ':py:class:`bool`',
            ArsInt8:    ':py:class:`byte`',
            ArsInt16:   ':py:class:`i16`',
            ArsInt32:   ':py:class:`i32`',
            ArsInt64:   ':py:class:`i64`',
            ArsFloat:   ':py:class:`double`',
            ArsString:  ':py:class:`string`',
            ArsVoid:    ':py:class:`void`',
        }[type]
    elif isinstance(type, ArsList):
        return ':py:class:`list`<{0}>'.format(reference_type(type.element_type))
    elif isinstance(type, ArsMap):
        return ':py:class:`map`<{0}, {1}>'.format(reference_type(type.key_type), reference_type(type.value_type))
    elif isinstance(type, ArsNamedType):
        return ':py:class:`{0}`'.format(type.name)
{'fraction_non_alphanumeric': 0.13803435876947662, 'fraction_numerical': 0.01278465840990811, 'mean_word_length': 2.739357729648992, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '2343350', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1598, 'n_words': 342}