예제 #1
0
 def _get_object_names(self, kind, codebase, tools_package_name):
     assert kind in ('class', 'function')
     tools_path = self._codebase_name_to_codebase_tools_path(codebase)
     path = os.path.join(tools_path, tools_package_name)
     if kind == 'class':
         crawler = documentationtools.ClassCrawler(
             path, include_private_objects=True)
     elif kind == 'function':
         crawler = documentationtools.FunctionCrawler(
             path, include_private_objects=True)
     objs = crawler()
     return tuple(sorted([x.__name__ for x in objs]))
예제 #2
0
def get_developer_script_classes():
    r'''Returns a list of all developer script classes.
    '''
    from abjad.tools import developerscripttools
    from abjad.tools import abjadbooktools

    tools_package_paths = [
        abjadbooktools.__path__[0],
        developerscripttools.__path__[0],
    ]
    script_classes = []
    for tools_package_path in tools_package_paths:
        developer_script_classes = documentationtools.ClassCrawler(
            tools_package_path, root_package_name='abjad')()
        for developer_script_class in developer_script_classes:
            if developerscripttools.DeveloperScript in \
                inspect.getmro(developer_script_class) and \
                not inspect.isabstract(developer_script_class):
                script_classes.append(developer_script_class)

    return list(sorted(script_classes, key=lambda x: x.__name__))
예제 #3
0
def list_all_classes(modules=None, ignored_classes=None):
    r'''Lists all public classes defined in `path`.

    ::

        >>> all_classes = documentationtools.list_all_classes(
        ...     modules='abjad',
        ...     )

    '''
    from abjad import abjad_configuration
    from abjad.tools import documentationtools
    all_classes = set()
    paths = []
    if modules is None:
        paths.append(abjad_configuration.abjad_directory)
    elif isinstance(modules, str):
        module = importlib.import_module(modules)
        paths.extend(module.__path__)
    elif isinstance(modules, types.ModuleType):
        paths.extend(modules.__path__)
    elif isinstance(modules, collections.Iterable):
        for module in modules:
            if isinstance(module, types.ModuleType):
                paths.extend(module.__path__)
            elif isinstance(module, str):
                module = importlib.import_module(module)
                paths.extend(module.__path__)
            else:
                raise ValueError(module)
    else:
        raise ValueError(modules)
    for path in paths:
        class_documenter = documentationtools.ClassCrawler(path, )
        for x in class_documenter():
            all_classes.add(x)
    if ignored_classes:
        ignored_classes = set(ignored_classes)
        all_classes.difference_update(ignored_classes)
    return list(all_classes)
예제 #4
0
 def _get_class_names_in_tools_package(self, root, tools_package_name):
     path = os.path.join(root, tools_package_name)
     crawler = documentationtools.ClassCrawler(path,
                                               include_private_objects=True)
     objs = crawler()
     return tuple(sorted([x.__name__ for x in objs]))
예제 #5
0
    def process_args(self, args):
        r'''Processes `args`.

        Returns none.
        '''

        #print args

        modules = {}

        if args.mode == 'docstrings':
            print('DOCS:\tMODULE:')
            for obj in documentationtools.FunctionCrawler(args.path)():
                docstring = obj.__doc__
                if not docstring:
                    modules[obj.__module__] = 0
                else:
                    lines = docstring.split('\n')
                    modules[obj.__module__] = \
                        max([len(line) for line in lines])
            for obj in documentationtools.ClassCrawler(args.path)():
                docstring = obj.__doc__
                width = 0
                if docstring:
                    lines = docstring.split('\n')
                    width = max([len(line) for line in lines])
                for attr_name in dir(obj):
                    attr = getattr(obj, attr_name)
                    attr_docstring = getattr(attr, '__doc__', None)
                    if attr_docstring:
                        lines = attr_docstring.split('\n')
                        attr_width = max([len(line) for line in lines])
                        if width < attr_width:
                            width = attr_width
                modules[obj.__module__] = width

        elif args.mode == 'code':
            print('CODE:\tMODULE:')
            for obj in documentationtools.FunctionCrawler(args.path)():
                module_path = obj.__module__
                module_obj = importlib.import_module(module_path)
                module_file_name = module_obj.__file__
                if module_file_name.endswith('.pyc'):
                    module_file_name = module_file_name[:-1]
                with open(module_file_name, 'r') as f:
                    lines = f.read().split('\n')
                    modules[obj.__module__] = \
                        max([len(line) for line in lines])
            for obj in documentationtools.ClassCrawler(args.path)():
                module_path = obj.__module__
                module_obj = importlib.import_module(module_path)
                module_file_name = module_obj.__file__
                if module_file_name.endswith('.pyc'):
                    module_file_name = module_file_name[:-1]
                with open(module_file_name, 'r') as f:
                    lines = f.read().split('\n')
                    modules[obj.__module__] = \
                        max([len(line) for line in lines])

        if args.order_by == 'm':
            order_by = lambda x: (x[0], x[1])
        else:
            order_by = lambda x: (x[1], x[0])

        if args.sort == 'descending':
            modules = sorted(list(modules.items()), key=order_by, reverse=True)
        else:
            modules = sorted(list(modules.items()), key=order_by)

        if args.greater_than is not None and 0 < args.greater_than:
            modules = [pair for pair in modules if args.greater_than < pair[1]]
        elif args.less_than is not None and 0 < args.less_than:
            modules = [pair for pair in modules if pair[1] < args.less_than]
        elif args.equal_to is not None and 0 <= args.equal_to:
            modules = [pair for pair in modules if pair[1] == args.equal_to]

        if args.limit is not None and 0 < args.limit:
            modules = modules[-args.limit:]

        for pair in modules:
            print('{}\t{}'.format(pair[1], pair[0]))