Example #1
0
def document(members, args, exclusion_list, file, fp, indent):
    for member in members:
        add = True
        if member['name'] in exclusion_list:
            add = False
        if args.undoc is False and len(member['docstring']) == 0:
            add = False
        if args.private is False and member['scope'] != 'public':
            add = False
        if not add:
            continue

        doc = SwiftFileIndex.documentation(
            member,
            indent=indent,
            location=args.location,
            nodocstring=args.undoc,
            noindex=args.noindex
        )
        for line in doc:
            content = indent + line + "\n"
            fp.write(content)

        if args.members:
            document_member(member, args, exclusion_list, file, fp, indent)
        fp.write('\n')
Example #2
0
def main():
    args = parser.parse_args()
    source_path = os.path.abspath(args.source_path)
    file_index = SwiftFileIndex([source_path])

    try:
        os.makedirs(args.documentation_path)
    except FileExistsError:
        pass

    # check for overwrite
    for file, members in file_index.by_file().items():
        destfile = get_dest_file(file, args.source_path,
                                 args.documentation_path)
        if os.path.exists(destfile) and not args.overwrite:
            print("""ERROR: {} already exists, to overwrite existing
                     documentation use the '--overwrite' flag""".format(file))
            exit(1)

    exclusion_list = []
    if args.exclusion_list:
        exclusion_list = open(args.exclusion_list, 'r').readlines()

    for file, members in file_index.by_file().items():
        destfile = get_dest_file(file, args.source_path,
                                 args.documentation_path)
        print("Writing documentation for '{}'...".format(
            os.path.relpath(file, source_path)))
        try:
            os.makedirs(os.path.dirname(destfile))
        except FileExistsError:
            pass
        with open(destfile, "w") as fp:
            heading = 'Documentation for {}'.format(
                os.path.relpath(file, source_path))
            fp.write(('=' * len(heading)) + '\n')
            fp.write(heading + '\n')
            fp.write(('=' * len(heading)) + '\n\n\n')
            if args.autodocumenter:
                auto_document(members, args, exclusion_list, fp)
            else:
                document(members, args, exclusion_list, file, fp, '')
Example #3
0
def main():
    args = parser.parse_args()
    source_path = os.path.abspath(args.source_path)
    file_index = SwiftFileIndex([source_path])

    try:
        os.makedirs(args.documentation_path)
    except FileExistsError:
        pass

    # check for overwrite
    for file, members in file_index.by_file().items():
        destfile = get_dest_file(file, args.source_path, args.documentation_path)
        if os.path.exists(destfile) and not args.overwrite:
            print("""ERROR: {} already exists, to overwrite existing
                     documentation use the '--overwrite' flag""".format(file))
            exit(1)

    exclusion_list = []
    if args.exclusion_list:
        exclusion_list = open(args.exclusion_list, 'r').readlines()

    for file, members in file_index.by_file().items():
        destfile = get_dest_file(file, args.source_path, args.documentation_path)
        print("Writing documentation for '{}'...".format(os.path.relpath(file, source_path)))
        try:
            os.makedirs(os.path.dirname(destfile))
        except FileExistsError:
            pass
        with open(destfile, "w") as fp:
            heading = 'Documentation for {}'.format(os.path.relpath(file, source_path))
            fp.write(('=' * len(heading)) + '\n')
            fp.write(heading + '\n')
            fp.write(('=' * len(heading)) + '\n\n\n')
            if args.autodocumenter:
                auto_document(members, args, exclusion_list, fp)
            else:
                document(members, args, exclusion_list, file, fp, '')
Example #4
0
def document(members, args, exclusion_list, file, fp, indent):
    for member in members:
        add = True
        if member['name'] in exclusion_list:
            add = False
        if args.undoc is False and len(member['docstring']) == 0:
            add = False
        if args.private is False and member['scope'] != 'public':
            add = False
        if not add:
            continue

        doc = SwiftFileIndex.documentation(member,
                                           indent=indent,
                                           location=args.location,
                                           nodocstring=args.undoc,
                                           noindex=args.noindex)
        for line in doc:
            content = indent + line + "\n"
            fp.write(content)

        if args.members:
            document_member(member, args, exclusion_list, file, fp, indent)
        fp.write('\n')
Example #5
0
def build_index(app):
    global file_index
    file_index = SwiftFileIndex(app.config.swift_search_path)
Example #6
0
    def document(self, item, indent=''):
        member_list = self.options.members if isinstance(
            self.options.members, list) else []
        raw_member_list = set([
            x.replace("/", ",") for x in self.options.raw_members
        ]) if isinstance(self.options.raw_members, set) else []

        if self.options.only_with_members:
            if len(
                    list([
                        x for x in item['members'].index
                        if x['name'] in self.options.only_with_members
                    ])) <= 0:
                return

        if self.options.only_with_raw_members:
            contains = False
            for member in item['members'].index:
                if len(
                        list([
                            x for x in [
                                x.replace("/", ",")
                                for x in self.options.only_with_raw_members
                            ] if x in member['raw']
                        ])) > 0:
                    contains = True
            if not contains: return

        # Don't document everything if a specific type was requested
        if self.objtype != 'swift':
            if item['type'] != self.objtype:
                return

        doc = SwiftFileIndex.documentation(item,
                                           indent=self.content_indent,
                                           location=('file-location'
                                                     in self.options),
                                           nodocstring=('nodocstring'
                                                        in self.options),
                                           noindex=('noindex' in self.options))
        for line in doc:
            content = indent + line
            self.add_line(content, '<autodoc>')

        # only document members when asked to
        if 'members' not in self.options and 'raw-members' not in self.options:
            return

        exclude_list = self.options.exclude_members if isinstance(
            self.options.exclude_members, set) else []
        for member in item['members'].index:
            add = False
            if (not member_list and not raw_member_list):
                add = True
            if member['name'] in member_list:
                add = True
            if len(list([x
                         for x in raw_member_list if x in member['raw']])) > 0:
                add = True
            if member['name'] in exclude_list:
                add = False
            if 'undoc-members' in self.options and len(
                    member['docstring']) == 0:
                add = False
            if 'private-members' not in self.options and member[
                    'scope'] != 'public':
                add = False
            if add:
                loc = item['file'] if 'file-location' in self.options else None
                doc = SwiftObjectIndex.documentation(
                    member,
                    indent=self.content_indent,
                    location=loc,
                    nodocstring=('nodocstring' in self.options),
                    noindex=('noindex' in self.options
                             or 'noindex-members' in self.options))
                for line in doc:
                    content = indent + self.content_indent + line
                    self.add_line(content, '<autodoc>')

        if 'recursive-members' in self.options:
            for child in item['children']:
                self.document(child, indent=indent + self.content_indent)
Example #7
0
    def document(self, item, indent=''):
        member_list = self.options.members if isinstance(self.options.members, list) else []
        raw_member_list = set(map(lambda x: x.replace("/",","),self.options.raw_members)) if isinstance(self.options.raw_members, set) else []

        if self.options.only_with_members:
            if len(list(filter(lambda x: x['name'] in self.options.only_with_members, item['members'].index))) <= 0:
                return

        if self.options.only_with_raw_members:
            contains = False
            for member in item['members'].index:
                if len(list(filter(lambda x: x in member['raw'], map(lambda x: x.replace("/",","),self.options.only_with_raw_members))))>0:
                    contains = True
            if not contains: return


        # Don't document everything if a specific type was requested
        if self.objtype != 'swift':
            if item['type'] != self.objtype:
                return


        doc = SwiftFileIndex.documentation(
            item,
            indent=self.content_indent,
            location=('file-location' in self.options),
            nodocstring=('nodocstring' in self.options),
            noindex=('noindex' in self.options)
        )
        for line in doc:
            content = indent + line
            self.add_line(content, '<autodoc>')

        # only document members when asked to
        if 'members' not in self.options and 'raw-members' not in self.options:
            return

        exclude_list = self.options.exclude_members if isinstance(self.options.exclude_members, set) else []
        for member in item['members'].index:
            add = False
            if (not member_list and not raw_member_list):
                add = True
            if member['name'] in member_list:
                add = True
            if len(list(filter(lambda x: x in member['raw'], raw_member_list)))>0:
                add = True
            if member['name'] in exclude_list:
                add = False
            if 'undoc-members' in self.options and len(member['docstring']) == 0:
                add = False
            if 'private-members' not in self.options and member['scope'] != 'public':
                add = False
            if add:
                loc = item['file'] if 'file-location' in self.options else None
                doc = SwiftObjectIndex.documentation(
                    member,
                    indent=self.content_indent,
                    location=loc,
                    nodocstring=('nodocstring' in self.options),
                    noindex=('noindex' in self.options or 'noindex-members' in self.options)
                )
                for line in doc:
                    content = indent + self.content_indent + line
                    self.add_line(content, '<autodoc>')

        if 'recursive-members' in self.options:
            for child in item['children']:
                self.document(child, indent=indent + self.content_indent)