예제 #1
0
def _linkify(match: Match, link: Callable[..., str], module: pdoc.Module,
             _is_pyident=re.compile(r'^[a-zA-Z_]\w*(\.\w+)+$').match, **kwargs):
    matched = match.group(0)
    refname = matched.strip('`')
    dobj = module.find_ident(refname)
    if isinstance(dobj, pdoc.External):
        if not _is_pyident(refname):
            return matched
        # If refname in documentation has a typo or is obsolete, warn.
        # XXX: Assume at least the first part of refname, i.e. the package, is correct.
        module_part = module.find_ident(refname.split('.')[0])
        if not isinstance(module_part, pdoc.External):
            warn('Code reference `{}` in module "{}" does not match any '
                 'documented object.'.format(refname, module.refname),
                 ReferenceWarning, stacklevel=3)
    return link(dobj, **kwargs)
예제 #2
0
파일: cli.py 프로젝트: linconvidal/pdoc
def recursive_write_files(m: pdoc.Module, ext: str, **kwargs):
    assert ext in ('.html', '.md')
    filepath = module_path(m, ext=ext)

    dirpath = path.dirname(filepath)
    if not os.access(dirpath, os.R_OK):
        os.makedirs(dirpath)

    with _open_write_file(filepath) as f:
        if ext == '.html':
            f.write(m.html(**kwargs))
        elif ext == '.md':
            f.write(m.text(**kwargs))

    for submodule in m.submodules():
        recursive_write_files(submodule, ext=ext, **kwargs)
예제 #3
0
def write_files(m: pdoc.Module, output_dir: str, **kwargs):
    f = module_path(m, output_dir, ".html")

    dirpath = os.path.dirname(f)
    if not os.access(dirpath, os.R_OK):
        os.makedirs(dirpath)

    try:
        with open(f, 'w+', encoding='utf-8') as w:
            w.write('<!--\n@' + 'generated\n-->\n' + m.html(**kwargs))
    except Exception:
        try:
            os.unlink(f)
        except Exception:
            pass
        raise

    for submodule in m.submodules():
        write_files(submodule, output_dir, **kwargs)
예제 #4
0
def write_files(m: pdoc.Module, ext: str, **kwargs):
    assert ext in ('.html', '.md')
    f = module_path(m, ext=ext)

    dirpath = path.dirname(f)
    if not os.access(dirpath, os.R_OK):
        os.makedirs(dirpath)

    try:
        with open(f, 'w+', encoding='utf-8') as w:
            if ext == '.html':
                w.write(m.html(**kwargs))
            elif ext == '.md':
                w.write(m.text(**kwargs))
    except Exception:
        try:
            os.unlink(f)
        except Exception:
            pass
        raise

    for submodule in m.submodules():
        write_files(submodule, ext=ext, **kwargs)
예제 #5
0
파일: cli.py 프로젝트: rbwinslow/pdoc
def write_html_files(m: pdoc.Module):
    f = module_html_path(m)

    dirpath = path.dirname(f)
    if not os.access(dirpath, os.R_OK):
        os.makedirs(dirpath)

    try:
        with open(f, 'w+', encoding='utf-8') as w:
            w.write(
                m.html(
                    external_links=args.external_links,
                    link_prefix=args.link_prefix,
                    source=not args.html_no_source,
                ))
    except Exception:
        try:
            os.unlink(f)
        except Exception:
            pass
        raise

    for submodule in m.submodules():
        write_html_files(submodule)
예제 #6
0
def module_path(m: pdoc.Module, ext: str):
    return path.join(args.output_dir, *re.sub(r'\.html$', ext, m.url()).split('/'))
예제 #7
0
파일: cli.py 프로젝트: rbwinslow/pdoc
def module_html_path(m: pdoc.Module):
    return path.join(args.html_dir, *m.url().split('/'))
예제 #8
0
def recursive_html(mod: pdoc.Module):
    yield mod.name, mod.html()
    for submod in mod.submodules():
        yield from recursive_html(submod)
예제 #9
0
def module_path(m: pdoc.Module, output_dir: str, ext: str):
    return os.path.join(output_dir,
                        *re.sub(r"\.html$", ext, m.url()).split("/"))