def _get_class_names_in_tools_package(self, root, tools_package_name):
     path = os.path.join(root, tools_package_name)
     generator = documentationtools.yield_all_classes(
         code_root=path,
         include_private_objects=True,
         )
     return tuple(sorted(generator, key=lambda x: x.__name__))
예제 #2
0
def list_all_functions(modules=None):
    r'''Lists all public functions defined in `modules`.

    ::

        >>> all_functions = documentationtools.list_all_functions(
        ...     modules='abjad',
        ...     )

    '''
    from abjad import abjad_configuration
    from abjad.tools import documentationtools
    all_functions = set()
    paths = []
    if modules is None:
        paths.append(abjad_configuration.abjad_directory)
    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__)
    for path in paths:
        for x in documentationtools.yield_all_classes(code_root=path):
            all_functions.add(x)
    return list(sorted(all_functions, key=lambda x:
                       (x.__module__, x.__name__)))
예제 #3
0
def list_all_functions(modules=None):
    r'''Lists all public functions defined in `modules`.

    ::

        >>> all_functions = documentationtools.list_all_functions(
        ...     modules='abjad',
        ...     )

    '''
    from abjad import abjad_configuration
    from abjad.tools import documentationtools
    all_functions = set()
    paths = []
    if modules is None:
        paths.append(abjad_configuration.abjad_directory)
    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__)
    for path in paths:
        for x in documentationtools.yield_all_classes(code_root=path):
            all_functions.add(x)
    return list(sorted(
        all_functions,
        key=lambda x: (x.__module__, x.__name__)
        ))
예제 #4
0
 def _get_class_names_in_tools_package(self, root, tools_package_name):
     path = os.path.join(root, tools_package_name)
     generator = documentationtools.yield_all_classes(
         code_root=path,
         include_private_objects=True,
     )
     return tuple(sorted(generator, key=lambda x: x.__name__))
예제 #5
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':
         generator = documentationtools.yield_all_classes(
             code_root=path,
             include_private_objects=True,
             )
     elif kind == 'function':
         generator = documentationtools.yield_all_functions(
             code_root=path,
             include_private_objects=True,
             )
     return tuple(sorted(generator, key=lambda x: x.__name__))
예제 #6
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':
         generator = documentationtools.yield_all_classes(
             code_root=path,
             include_private_objects=True,
         )
     elif kind == 'function':
         generator = documentationtools.yield_all_functions(
             code_root=path,
             include_private_objects=True,
         )
     return tuple(sorted(generator, key=lambda x: x.__name__))
예제 #7
0
def list_all_classes(modules=None, ignored_classes=None):
    r'''Lists all public classes defined in `path`.

    ..  container:: example

        ::

            >>> all_classes = abjad.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:
        for x in documentationtools.yield_all_classes(code_root=path):
            all_classes.add(x)
    if ignored_classes:
        ignored_classes = set(ignored_classes)
        all_classes.difference_update(ignored_classes)
    return list(sorted(
        all_classes,
        key=lambda x: (x.__module__, x.__name__)
        ))
예제 #8
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:
        for x in documentationtools.yield_all_classes(code_root=path):
            all_classes.add(x)
    if ignored_classes:
        ignored_classes = set(ignored_classes)
        all_classes.difference_update(ignored_classes)
    return list(sorted(
        all_classes,
        key=lambda x: (x.__module__, x.__name__)
        ))
def get_developer_script_classes():
    r'''Returns a list of all developer script classes.
    '''
    from abjad.tools import abjadbooktools
    from abjad.tools import developerscripttools
    tools_package_paths = []
    tools_package_paths.extend(abjadbooktools.__path__)
    tools_package_paths.extend(developerscripttools.__path__)
    script_classes = []
    for tools_package_path in tools_package_paths:
        generator = documentationtools.yield_all_classes(
            code_root=tools_package_path,
            root_package_name='abjad',
        )
        for developer_script_class in generator:
            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__))
예제 #10
0
 def list_commandline_script_classes():
     r'''Returns a list of all developer script classes.
     '''
     import abjad.cli
     import abjad.book
     tools_package_paths = []
     tools_package_paths.extend(abjad.book.__path__)
     tools_package_paths.extend(abjad.cli.__path__)
     script_classes = []
     base_class = abjad.cli.CommandlineScript
     for tools_package_path in tools_package_paths:
         generator = documentationtools.yield_all_classes(
             code_root=tools_package_path,
             root_package_name='abjad',
         )
         for class_ in generator:
             if (issubclass(class_, base_class) and class_ is not base_class
                     and not inspect.isabstract(class_)):
                 script_classes.append(class_)
     return list(sorted(script_classes, key=lambda x: x.__name__))
예제 #11
0
def get_developer_script_classes():
    r'''Returns a list of all developer script classes.
    '''
    from abjad.tools import abjadbooktools
    from abjad.tools import developerscripttools
    tools_package_paths = []
    tools_package_paths.extend(abjadbooktools.__path__)
    tools_package_paths.extend(developerscripttools.__path__)
    script_classes = []
    for tools_package_path in tools_package_paths:
        generator = documentationtools.yield_all_classes(
            code_root=tools_package_path,
            root_package_name='abjad',
            )
        for developer_script_class in generator:
            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__))
예제 #12
0
 def list_commandline_script_classes():
     r'''Returns a list of all developer script classes.
     '''
     from abjad.tools import abjadbooktools
     from abjad.tools import commandlinetools
     tools_package_paths = []
     tools_package_paths.extend(abjadbooktools.__path__)
     tools_package_paths.extend(commandlinetools.__path__)
     script_classes = []
     base_class = commandlinetools.CommandlineScript
     for tools_package_path in tools_package_paths:
         generator = documentationtools.yield_all_classes(
             code_root=tools_package_path,
             root_package_name='abjad',
             )
         for class_ in generator:
             if (
                 issubclass(class_, base_class) and
                 class_ is not base_class and
                 not inspect.isabstract(class_)
                 ):
                 script_classes.append(class_)
     return list(sorted(script_classes, key=lambda x: x.__name__))
예제 #13
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.yield_all_functions(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.yield_all_classes(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.yield_all_functions(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.yield_all_classes(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]))
예제 #14
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.yield_all_functions(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.yield_all_classes(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.yield_all_functions(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.yield_all_classes(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]))