예제 #1
0
def verify_everything_documented(app, exception):  # pragma: no cover
    if exception:
        return

    bad = False
    app.info(console.white("checking that all REST API types are included in the documentation"))
    documented_types = app.env.domaindata['api']['types']
    for ty in wsme.types.Base.__subclasses__():
        if not ty.__module__.startswith('relengapi.') or '.test_' in ty.__module__:
            continue
        tyname = typename(ty)
        if tyname not in documented_types:
            app.warn(console.red("Type '%s' is not documented" % (tyname,)))
            bad = True

    app.info(console.white("checking that all API endpoints are included in the documentation"))
    all_endpoints = set(ep for ep, func in current_app.view_functions.items()
                        if hasattr(func, '__apidoc__'))
    documented_endpoints = app.env.domaindata['api']['endpoints']
    for undoc in all_endpoints - documented_endpoints:
        app.warn(console.red("Endpoint '%s' is not documented" % (undoc,)))
        bad = True

    if bad:
        raise RuntimeError("missing API documentation")
예제 #2
0
파일: builder.py 프로젝트: Lemma1/MINAMI
 def init(self):
     I18nBuilder.init(self)
     errors = False
     if not self.config.omegat_project_path:
         self.info(red("'omegat_project_path' should not be empty."))
         self.info(red("    -> Please check conf.py"))
         raise RuntimeError("lack setting")
예제 #3
0
 def process_result(self, result):
     uri, docname, lineno, status, info, code = result
     if status == 'unchecked':
         return
     if status == 'working' and info != 'new':
         return
     if lineno:
         self.info('(line %4d) ' % lineno, nonl=1)
     if status == 'ignored':
         self.info(darkgray('-ignored- ') + uri)
     elif status == 'local':
         self.info(darkgray('-local-   ') + uri)
         self.write_entry('local', docname, lineno, uri)
     elif status == 'working':
         self.info(darkgreen('ok        ')  + uri)
     elif status == 'broken':
         self.info(red('broken    ') + uri + red(' - ' + info))
         self.write_entry('broken', docname, lineno, uri + ': ' + info)
         if self.app.quiet:
             self.warn('broken link: %s' % uri,
                       '%s:%s' % (self.env.doc2path(docname), lineno))
     elif status == 'redirected':
         text, color = {
             301: ('permanently', darkred),
             302: ('with Found', purple),
             303: ('with See Other', purple),
             307: ('temporarily', turquoise),
             0:   ('with unknown code', purple),
         }[code]
         self.write_entry('redirected ' + text, docname, lineno,
                          uri + ' to ' + info)
         self.info(color('redirect  ') + uri + color(' - ' + text + ' to '  + info))
예제 #4
0
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = purple(PROMPT_PREFIX + "%s [%s]: " % (text, default))
        else:
            prompt = purple(PROMPT_PREFIX + text + ": ")
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        if not isinstance(x, unicode):
            # for Python 2.x, try to get a Unicode string out of it
            if x.decode("ascii", "replace").encode("ascii", "replace") != x:
                if TERM_ENCODING:
                    x = x.decode(TERM_ENCODING)
                else:
                    print turquoise(
                        "* Note: non-ASCII characters entered "
                        "and terminal encoding unknown -- assuming "
                        "UTF-8 or Latin-1."
                    )
                    try:
                        x = x.decode("utf-8")
                    except UnicodeDecodeError:
                        x = x.decode("latin1")
        try:
            x = validator(x)
        except ValidationError, err:
            print red("* " + str(err))
            continue
        break
예제 #5
0
파일: quickstart.py 프로젝트: certik/sphinx
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = purple(PROMPT_PREFIX + '%s [%s]: ' % (text, default))
        else:
            prompt = purple(PROMPT_PREFIX + text + ': ')
        x = term_input(prompt)
        if default and not x:
            x = default
        if not isinstance(x, unicode):
            # for Python 2.x, try to get a Unicode string out of it
            if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
                if TERM_ENCODING:
                    x = x.decode(TERM_ENCODING)
                else:
                    print turquoise('* Note: non-ASCII characters entered '
                                    'and terminal encoding unknown -- assuming '
                                    'UTF-8 or Latin-1.')
                    try:
                        x = x.decode('utf-8')
                    except UnicodeDecodeError:
                        x = x.decode('latin1')
        try:
            x = validator(x)
        except ValidationError, err:
            print red('* ' + str(err))
            continue
        break
예제 #6
0
파일: conf.py 프로젝트: boyska/larigira
def run_apidoc(_):
    cur_dir = os.path.abspath(os.path.dirname(__file__))
    proj_dir = os.path.abspath(os.path.join(cur_dir, '..', '..'))
    modules = ['larigira']
    exclude_files = [os.path.abspath(os.path.join(proj_dir, excl))
                     for excl in ('larigira/rpc.py', 'larigira/dbadmin/')]
    output_path = os.path.join(cur_dir, 'api')
    cmd_path = 'sphinx-apidoc'
    if hasattr(sys, 'real_prefix'):  # Are we in a virtualenv?
        # assemble the path manually
        cmd_path = os.path.abspath(os.path.join(sys.prefix,
                                                'bin',
                                                'sphinx-apidoc'))
    if not os.path.exists(cmd_path):
        print(red("No apidoc available!"), file=sys.stderr)
        return
    for module in modules:
        try:
            subprocess.check_call([cmd_path,
                                   '--force',
                                   '-o', output_path,
                                   module
                                   ] + exclude_files,
                                  cwd=proj_dir
                                 )
        except subprocess.CalledProcessError:
            print(red("APIdoc failed for module {}".format(module)))
예제 #7
0
def summarize_failing_examples(app, exception):
    """Collects the list of falling examples and prints them with a traceback.

    Raises ValueError if there where failing examples.
    """
    if exception is not None:
        return

    # Under no-plot Examples are not run so nothing to summarize
    if not app.config.sphinx_gallery_conf['plot_gallery']:
        return

    gallery_conf = app.config.sphinx_gallery_conf
    failing_examples = set(gallery_conf['failing_examples'].keys())
    expected_failing_examples = set(
        os.path.normpath(os.path.join(app.srcdir, path))
        for path in gallery_conf['expected_failing_examples'])

    examples_expected_to_fail = failing_examples.intersection(
        expected_failing_examples)
    if examples_expected_to_fail:
        logger.info("Examples failing as expected:", color='brown')
        for fail_example in examples_expected_to_fail:
            logger.info('%s failed leaving traceback:', fail_example)
            logger.info(gallery_conf['failing_examples'][fail_example])

    examples_not_expected_to_fail = failing_examples.difference(
        expected_failing_examples)
    fail_msgs = []
    if examples_not_expected_to_fail:
        fail_msgs.append(red("Unexpected failing examples:"))
        for fail_example in examples_not_expected_to_fail:
            fail_msgs.append(fail_example + ' failed leaving traceback:\n' +
                             gallery_conf['failing_examples'][fail_example] +
                             '\n')

    examples_not_expected_to_pass = expected_failing_examples.difference(
        failing_examples)
    # filter from examples actually run
    filename_pattern = gallery_conf.get('filename_pattern')
    examples_not_expected_to_pass = [
        src_file for src_file in examples_not_expected_to_pass
        if re.search(filename_pattern, src_file)]
    if examples_not_expected_to_pass:
        fail_msgs.append(red("Examples expected to fail, but not failing:\n") +
                         "Please remove these examples from\n" +
                         "sphinx_gallery_conf['expected_failing_examples']\n" +
                         "in your conf.py file"
                         "\n".join(examples_not_expected_to_pass))

    if fail_msgs:
        raise ValueError("Here is a summary of the problems encountered when "
                         "running the examples\n\n" + "\n".join(fail_msgs) +
                         "\n" + "-" * 79)
예제 #8
0
def summarize_failing_examples(app, exception):
    """Collects the list of falling examples during build and prints them with the traceback

    Raises ValueError if there where failing examples
    """
    if exception is not None:
        return

    # Under no-plot Examples are not run so nothing to summarize
    if not app.config.sphinx_gallery_conf['plot_gallery']:
        return

    gallery_conf = app.config.sphinx_gallery_conf
    failing_examples = set(gallery_conf['failing_examples'].keys())
    expected_failing_examples = set([os.path.normpath(os.path.join(app.srcdir, path))
                                     for path in
                                     gallery_conf['expected_failing_examples']])

    examples_expected_to_fail = failing_examples.intersection(
        expected_failing_examples)
    if examples_expected_to_fail:
        logger.info("Examples failing as expected:", color='brown')
        for fail_example in examples_expected_to_fail:
            logger.info('%s failed leaving traceback:', fail_example)
            logger.info(gallery_conf['failing_examples'][fail_example])

    examples_not_expected_to_fail = failing_examples.difference(
        expected_failing_examples)
    fail_msgs = []
    if examples_not_expected_to_fail:
        fail_msgs.append(red("Unexpected failing examples:"))
        for fail_example in examples_not_expected_to_fail:
            fail_msgs.append(fail_example + ' failed leaving traceback:\n' +
                             gallery_conf['failing_examples'][fail_example] +
                             '\n')

    examples_not_expected_to_pass = expected_failing_examples.difference(
        failing_examples)
    # filter from examples actually run
    filename_pattern = gallery_conf.get('filename_pattern')
    examples_not_expected_to_pass = [src_file
                                     for src_file in examples_not_expected_to_pass
                                     if re.search(filename_pattern, src_file)]
    if examples_not_expected_to_pass:
        fail_msgs.append(red("Examples expected to fail, but not failing:\n") +
                         "Please remove these examples from\n" +
                         "sphinx_gallery_conf['expected_failing_examples']\n" +
                         "in your conf.py file"
                         "\n".join(examples_not_expected_to_pass))

    if fail_msgs:
        raise ValueError("Here is a summary of the problems encountered when "
                         "running the examples\n\n" + "\n".join(fail_msgs) +
                         "\n" + "-" * 79)
예제 #9
0
    def process_result(self, result: Tuple[str, str, int, str, str, int]) -> None:
        uri, docname, lineno, status, info, code = result

        filename = self.env.doc2path(docname, None)
        linkstat = dict(filename=filename, lineno=lineno,
                        status=status, code=code, uri=uri,
                        info=info)
        if status == 'unchecked':
            self.write_linkstat(linkstat)
            return
        if status == 'working' and info == 'old':
            self.write_linkstat(linkstat)
            return
        if lineno:
            logger.info('(line %4d) ', lineno, nonl=True)
        if status == 'ignored':
            if info:
                logger.info(darkgray('-ignored- ') + uri + ': ' + info)
            else:
                logger.info(darkgray('-ignored- ') + uri)
            self.write_linkstat(linkstat)
        elif status == 'local':
            logger.info(darkgray('-local-   ') + uri)
            self.write_entry('local', docname, filename, lineno, uri)
            self.write_linkstat(linkstat)
        elif status == 'working':
            logger.info(darkgreen('ok        ') + uri + info)
            self.write_linkstat(linkstat)
        elif status == 'broken':
            if self.app.quiet or self.app.warningiserror:
                logger.warning(__('broken link: %s (%s)'), uri, info,
                               location=(filename, lineno))
            else:
                logger.info(red('broken    ') + uri + red(' - ' + info))
            self.write_entry('broken', docname, filename, lineno, uri + ': ' + info)
            self.write_linkstat(linkstat)
        elif status == 'redirected':
            try:
                text, color = {
                    301: ('permanently', purple),
                    302: ('with Found', purple),
                    303: ('with See Other', purple),
                    307: ('temporarily', turquoise),
                    308: ('permanently', purple),
                }[code]
            except KeyError:
                text, color = ('with unknown code', purple)
            linkstat['text'] = text
            logger.info(color('redirect  ') + uri + color(' - ' + text + ' to ' + info))
            self.write_entry('redirected ' + text, docname, filename,
                             lineno, uri + ' to ' + info)
            self.write_linkstat(linkstat)
예제 #10
0
    def check(self, node, docname):
        uri = node['refuri']

        if '#' in uri:
            uri = uri.split('#')[0]

        if uri in self.good:
            return

        lineno = None
        while lineno is None and node:
            node = node.parent
            lineno = node.line

        if uri[0:5] == 'http:' or uri[0:6] == 'https:':
            self.info(uri, nonl=1)

            if uri in self.broken:
                (r, s) = self.broken[uri]
            elif uri in self.redirected:
                (r, s) = self.redirected[uri]
            else:
                (r, s) = self.resolve(uri)

            if r == 0:
                self.info(' - ' + darkgreen('working'))
                self.good.add(uri)
            elif r == 2:
                self.info(' - ' + red('broken: ') + s)
                self.write_entry('broken', docname, lineno, uri + ': ' + s)
                self.broken[uri] = (r, s)
                if self.app.quiet:
                    self.warn('broken link: %s' % uri,
                              '%s:%s' % (self.env.doc2path(docname), lineno))
            else:
                self.info(' - ' + purple('redirected') + ' to ' + s)
                self.write_entry('redirected', docname, lineno,
                                 uri + ' to ' + s)
                self.redirected[uri] = (r, s)
        elif len(uri) == 0 or uri[0:7] == 'mailto:' or uri[0:4] == 'ftp:':
            return
        else:
            self.warn(uri + ' - ' + red('malformed!'))
            self.write_entry('malformed', docname, lineno, uri)
            if self.app.quiet:
                self.warn('malformed link: %s' % uri,
                          '%s:%s' % (self.env.doc2path(docname), lineno))
            self.app.statuscode = 1

        if self.broken:
            self.app.statuscode = 1
예제 #11
0
파일: linkcheck.py 프로젝트: 89sos98/main
    def check(self, node, docname):
        uri = node['refuri']

        if '#' in uri:
            uri = uri.split('#')[0]

        if uri in self.good:
            return

        lineno = None
        while lineno is None and node:
            node = node.parent
            lineno = node.line

        if uri[0:5] == 'http:' or uri[0:6] == 'https:':
            self.info(uri, nonl=1)

            if uri in self.broken:
                (r, s) = self.broken[uri]
            elif uri in self.redirected:
                (r, s) = self.redirected[uri]
            else:
                (r, s) = self.resolve(uri)

            if r == 0:
                self.info(' - ' + darkgreen('working'))
                self.good.add(uri)
            elif r == 2:
                self.info(' - ' + red('broken: ') + s)
                self.write_entry('broken', docname, lineno, uri + ': ' + s)
                self.broken[uri] = (r, s)
                if self.app.quiet:
                    self.warn('broken link: %s' % uri,
                              '%s:%s' % (self.env.doc2path(docname), lineno))
            else:
                self.info(' - ' + purple('redirected') + ' to ' + s)
                self.write_entry('redirected', docname,
                                 lineno, uri + ' to ' + s)
                self.redirected[uri] = (r, s)
        elif len(uri) == 0 or uri[0:7] == 'mailto:' or uri[0:4] == 'ftp:':
            return
        else:
            self.warn(uri + ' - ' + red('malformed!'))
            self.write_entry('malformed', docname, lineno, uri)
            if self.app.quiet:
                self.warn('malformed link: %s' % uri,
                          '%s:%s' % (self.env.doc2path(docname), lineno))
            self.app.statuscode = 1

        if self.broken:
            self.app.statuscode = 1
예제 #12
0
def purge_module_apidoc(sphinx, exception):
    # Short out if not supposed to run
    if not sphinx.config.clean_autogenerated_docs:
        return

    try:
        sphinx.info(bold('cleaning autogenerated docs... '), nonl=True)
        _doc_modules_path.ensure(dir=True)
        _doc_modules_path.remove(rec=True)
        sphinx.info(message='done')
    except Exception as ex:
        sphinx.info(red('failed to clean autogenerated docs'))
        sphinx.info(red(type(ex).__name__) + ' ', nonl=True)
        sphinx.info(str(ex))
예제 #13
0
    def process_result(self, result: CheckResult) -> None:
        filename = self.env.doc2path(result.docname, None)

        linkstat = dict(filename=filename, lineno=result.lineno,
                        status=result.status, code=result.code, uri=result.uri,
                        info=result.message)
        self.write_linkstat(linkstat)

        if result.status == 'unchecked':
            return
        if result.status == 'working' and result.message == 'old':
            return
        if result.lineno:
            logger.info('(%16s: line %4d) ', result.docname, result.lineno, nonl=True)
        if result.status == 'ignored':
            if result.message:
                logger.info(darkgray('-ignored- ') + result.uri + ': ' + result.message)
            else:
                logger.info(darkgray('-ignored- ') + result.uri)
        elif result.status == 'local':
            logger.info(darkgray('-local-   ') + result.uri)
            self.write_entry('local', result.docname, filename, result.lineno, result.uri)
        elif result.status == 'working':
            logger.info(darkgreen('ok        ') + result.uri + result.message)
        elif result.status == 'broken':
            if self.app.quiet or self.app.warningiserror:
                logger.warning(__('broken link: %s (%s)'), result.uri, result.message,
                               location=(filename, result.lineno))
            else:
                logger.info(red('broken    ') + result.uri + red(' - ' + result.message))
            self.write_entry('broken', result.docname, filename, result.lineno,
                             result.uri + ': ' + result.message)
        elif result.status == 'redirected':
            try:
                text, color = {
                    301: ('permanently', purple),
                    302: ('with Found', purple),
                    303: ('with See Other', purple),
                    307: ('temporarily', turquoise),
                    308: ('permanently', purple),
                }[result.code]
            except KeyError:
                text, color = ('with unknown code', purple)
            linkstat['text'] = text
            logger.info(color('redirect  ') + result.uri +
                        color(' - ' + text + ' to ' + result.message))
            self.write_entry('redirected ' + text, result.docname, filename,
                             result.lineno, result.uri + ' to ' + result.message)
        else:
            raise ValueError("Unknown status %s." % result.status)
예제 #14
0
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = purple('> %s [%s]: ' % (text, default))
        else:
            prompt = purple('> ' + text + ': ')
        x = raw_input(prompt)
        if default and not x:
            x = default
        if validator and not validator(x):
            print red(" * " + validator.__doc__)
            continue
        break
    d[key] = x
예제 #15
0
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = purple(PROMPT_PREFIX + '%s [%s]: ' % (text, default))
        else:
            prompt = purple(PROMPT_PREFIX + text + ': ')
        x = raw_input(prompt)
        if default and not x:
            x = default
        if validator and not validator(x):
            print red(" * " + validator.__doc__)
            continue
        break
    d[key] = x
예제 #16
0
def create_simple_redirects(graph_edges: dict) -> dict:
    """
    Ensures that a graph is a acyclic and reconnects every vertex to its leaf vertex.
    """
    redirects = {}
    broken_vertices = set()
    for vertex in graph_edges:
        if vertex in broken_vertices:
            continue

        visited = []
        while vertex in graph_edges:
            if vertex in visited:
                # Ensure graph is a DAG
                logger.error(
                    red("rediraffe: A circular redirect exists. Links involved: "
                        + " -> ".join(visited + [vertex])))
                broken_vertices.update(visited)
                break
            visited.append(vertex)
            vertex = graph_edges[vertex]

        # vertex is now a leaf
        for visited_vertex in visited:
            redirects[visited_vertex] = vertex

    if broken_vertices:
        err_msg = (
            f"rediraffe: At least 1 circular redirect detected. All involved links: "
            + ", ".join(broken_vertices))
        logger.error(err_msg)
        raise ExtensionError(err_msg)

    return redirects
예제 #17
0
def do_prompt(text, default=None, validator=nonempty):
    # type: (unicode, unicode, Callable[[unicode], Any]) -> Union[unicode, bool]
    while True:
        if default is not None:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)  # type: unicode
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if PY2:
            # for Python 2.x, try to get a Unicode string out of it
            if prompt.encode('ascii', 'replace').decode('ascii', 'replace') \
                    != prompt:
                if TERM_ENCODING:
                    prompt = prompt.encode(TERM_ENCODING)
                else:
                    print(turquoise(__('* Note: non-ASCII default value provided '
                                       'and terminal encoding unknown -- assuming '
                                       'UTF-8 or Latin-1.')))
                    try:
                        prompt = prompt.encode('utf-8')
                    except UnicodeEncodeError:
                        prompt = prompt.encode('latin1')
        prompt = purple(prompt)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        x = term_decode(x)
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    return x
예제 #18
0
 def check_missing(self):
     for mod in ModuleDocumenter.missing_modules:
         self.app.statuscode = 3
         print(ERR_MISSING.format(
             error=red(ERR),
             module=bold(mod),
         ))
예제 #19
0
def do_prompt(text: str,
              default: str = None,
              validator: Callable[[str],
                                  Any] = nonempty) -> Union[str, bool]:  # NOQA
    while True:
        if default is not None:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if USE_LIBEDIT:
            # Note: libedit has a problem for combination of ``input()`` and escape
            # sequence (see #5335).  To avoid the problem, all prompts are not colored
            # on libedit.
            pass
        elif readline:
            # pass input_mode=True if readline available
            prompt = colorize(COLOR_QUESTION, prompt, input_mode=True)
        else:
            prompt = colorize(COLOR_QUESTION, prompt, input_mode=False)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    return x
예제 #20
0
파일: quickstart.py 프로젝트: TimKam/sphinx
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default is not None:
            prompt = PROMPT_PREFIX + "%s [%s]: " % (text, default)
        else:
            prompt = PROMPT_PREFIX + text + ": "
        if PY2:
            # for Python 2.x, try to get a Unicode string out of it
            if prompt.encode("ascii", "replace").decode("ascii", "replace") != prompt:
                if TERM_ENCODING:
                    prompt = prompt.encode(TERM_ENCODING)
                else:
                    print(
                        turquoise(
                            "* Note: non-ASCII default value provided "
                            "and terminal encoding unknown -- assuming "
                            "UTF-8 or Latin-1."
                        )
                    )
                    try:
                        prompt = prompt.encode("utf-8")
                    except UnicodeEncodeError:
                        prompt = prompt.encode("latin1")
        prompt = purple(prompt)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        x = term_decode(x)
        try:
            x = validator(x)
        except ValidationError as err:
            print(red("* " + str(err)))
            continue
        break
    d[key] = x
예제 #21
0
def process_meta(app, doctree, fromdocname):
    env = app.builder.env
    env.page_to_version = defaultdict(set)
    env.version_to_page = defaultdict(set)

    # index metadata
    for pagename, metadata in iter(env.metadata.items()):
        if 'version' in metadata:
            version = metadata['version']
            env.page_to_version[pagename] = version
            env.version_to_page[version].add(pagename)

            if fromdocname == pagename:

                # Alert on outdated version
                current_version = env.config['version']
                if version != current_version:
                    text = 'This page documents version {old} and has not yet been updated for version {new}'.format(
                        old=version,
                        new=current_version,
                    )

                    if app.config['versionwarning_node']:
                        prose = nodes.paragraph(text, text)
                        warning = nodes.warning(prose, prose)
                        doctree.insert(0, warning)
                    if app.config['versionwarning_console']:
                        app.warn(
                            bold('[Version Warning: %s] ' % pagename) +
                            red(text))
예제 #22
0
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = purple(PROMPT_PREFIX + '%s [%s]: ' % (text, default))
        else:
            prompt = purple(PROMPT_PREFIX + text + ': ')
        x = term_input(prompt)
        if default and not x:
            x = default
        if not isinstance(x, str):
            # for Python 2.x, try to get a Unicode string out of it
            if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
                if TERM_ENCODING:
                    x = x.decode(TERM_ENCODING)
                else:
                    print(
                        turquoise('* Note: non-ASCII characters entered '
                                  'and terminal encoding unknown -- assuming '
                                  'UTF-8 or Latin-1.'))
                    try:
                        x = x.decode('utf-8')
                    except UnicodeDecodeError:
                        x = x.decode('latin1')
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    d[key] = x
예제 #23
0
def do_prompt(text, default=None, validator=nonempty):
    # type: (str, str, Callable[[str], Any]) -> Union[str, bool]
    while True:
        if default is not None:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if USE_LIBEDIT:
            # Note: libedit has a problem for combination of ``input()`` and escape
            # sequence (see #5335).  To avoid the problem, all prompts are not colored
            # on libedit.
            pass
        else:
            prompt = colorize(COLOR_QUESTION, prompt, input_mode=True)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        x = term_decode(x)
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    return x
예제 #24
0
 def process_result(self, result):
     uri, docname, lineno, status, info = result
     if status == 'unchecked':
         return
     if status == 'working' and info != 'new':
         return
     if lineno:
         self.info('(line %3d) ' % lineno, nonl=1)
     if status == 'ignored':
         self.info(uri + ' - ' + darkgray('ignored'))
     elif status == 'local':
         self.info(uri + ' - ' + darkgray('local'))
         self.write_entry('local', docname, lineno, uri)
     elif status == 'working':
         self.info(uri + ' - ' + darkgreen('working'))
     elif status == 'broken':
         self.info(uri + ' - ' + red('broken: ') + info)
         self.write_entry('broken', docname, lineno, uri + ': ' + info)
         if self.app.quiet:
             self.warn('broken link: %s' % uri,
                       '%s:%s' % (self.env.doc2path(docname), lineno))
     elif status == 'redirected':
         self.info(uri + ' - ' + purple('redirected') + ' to ' + info)
         self.write_entry('redirected', docname, lineno,
                          uri + ' to ' + info)
예제 #25
0
def process_meta(app, doctree, fromdocname):
    env = app.builder.env
    env.page_to_version = defaultdict(set)
    env.version_to_page = defaultdict(set)

    # index metadata
    for pagename, metadata in env.metadata.iteritems():
        if 'version' in metadata:
            version = metadata['version']
            env.page_to_version[pagename] = version
            env.version_to_page[version].add(pagename)

            if fromdocname == pagename:

                # Alert on outdated version
                current_version = env.config['version']
                if version != current_version:
                    text = 'This page documents version {old}. The latest version is {new}'.format(
                        old=version,
                        new=current_version,
                    )

                    if app.config['versionwarning-node']:
                        prose = nodes.paragraph(text, text)
                        warning = nodes.warning(prose, prose)
                        doctree.insert(0, warning)
                    if app.config['versionwarning-console']:
                        app.warn(bold('[Version Warning: %s] ' % pagename) + red(text))
예제 #26
0
def do_prompt(text, default=None, validator=nonempty):
    # type: (unicode, unicode, Callable[[unicode], Any]) -> Union[unicode, bool]
    while True:
        if default is not None:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)  # type: unicode
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if USE_LIBEDIT:
            # Note: libedit has a problem for combination of ``input()`` and escape
            # sequence (see #5335).  To avoid the problem, all prompts are not colored
            # on libedit.
            pass
        else:
            prompt = colorize(COLOR_QUESTION, prompt, input_mode=True)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        x = term_decode(x)
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    return x
예제 #27
0
 def check_missing(self):
     for mod in ModuleDocumenter.missing_modules:
         self.app.statuscode = 3
         print(ERR_MISSING.format(
             error=red(ERR),
             module=bold(mod),
         ))
예제 #28
0
파일: quickstart.py 프로젝트: nvmanh/plant
def do_prompt(d, key, text, default=None, validator=nonempty):
    # type: (Dict, unicode, unicode, unicode, Callable[[unicode], Any]) -> None
    while True:
        if default is not None:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)  # type: unicode
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if PY2:
            # for Python 2.x, try to get a Unicode string out of it
            if prompt.encode('ascii', 'replace').decode('ascii', 'replace') \
                    != prompt:
                if TERM_ENCODING:
                    prompt = prompt.encode(TERM_ENCODING)
                else:
                    print(turquoise('* Note: non-ASCII default value provided '
                                    'and terminal encoding unknown -- assuming '
                                    'UTF-8 or Latin-1.'))
                    try:
                        prompt = prompt.encode('utf-8')
                    except UnicodeEncodeError:
                        prompt = prompt.encode('latin1')
        prompt = purple(prompt)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        x = term_decode(x)
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    d[key] = x
예제 #29
0
def handle_exception(app: Sphinx,
                     args: Any,
                     exception: BaseException,
                     stderr: IO = sys.stderr) -> None:  # NOQA
    if isinstance(exception, bdb.BdbQuit):
        return

    if args.pdb:
        print(red(__('Exception occurred while building, starting debugger:')),
              file=stderr)
        traceback.print_exc()
        pdb.post_mortem(sys.exc_info()[2])
    else:
        print(file=stderr)
        if args.verbosity or args.traceback:
            traceback.print_exc(None, stderr)
            print(file=stderr)
        if isinstance(exception, KeyboardInterrupt):
            print(__('Interrupted!'), file=stderr)
        elif isinstance(exception, SystemMessage):
            print(red(__('reST markup error:')), file=stderr)
            print(terminal_safe(exception.args[0]), file=stderr)
        elif isinstance(exception, SphinxError):
            print(red('%s:' % exception.category), file=stderr)
            print(str(exception), file=stderr)
        elif isinstance(exception, UnicodeError):
            print(red(__('Encoding error:')), file=stderr)
            print(terminal_safe(str(exception)), file=stderr)
            tbpath = save_traceback(app)
            print(red(
                __('The full traceback has been saved in %s, if you want '
                   'to report the issue to the developers.') % tbpath),
                  file=stderr)
        elif isinstance(exception,
                        RuntimeError) and 'recursion depth' in str(exception):
            print(red(__('Recursion error:')), file=stderr)
            print(terminal_safe(str(exception)), file=stderr)
            print(file=stderr)
            print(__('This can happen with very large or deeply nested source '
                     'files. You can carefully increase the default Python '
                     'recursion limit of 1000 in conf.py with e.g.:'),
                  file=stderr)
            print('    import sys; sys.setrecursionlimit(1500)', file=stderr)
        else:
            print(red(__('Exception occurred:')), file=stderr)
            print(format_exception_cut_frames().rstrip(), file=stderr)
            tbpath = save_traceback(app)
            print(red(
                __('The full traceback has been saved in %s, if you '
                   'want to report the issue to the developers.') % tbpath),
                  file=stderr)
            print(__('Please also report this if it was a user error, so '
                     'that a better error message can be provided next time.'),
                  file=stderr)
            print(__('A bug report can be filed in the tracker at '
                     '<https://github.com/sphinx-doc/sphinx/issues>. Thanks!'),
                  file=stderr)
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if sys.version_info < (3, 0):
            # for Python 2.x, try to get a Unicode string out of it
            if prompt.encode('ascii', 'replace').decode('ascii', 'replace') \
                    != prompt:
                if TERM_ENCODING:
                    prompt = prompt.encode(TERM_ENCODING)
                else:
                    print turquoise(
                        '* Note: non-ASCII default value provided '
                        'and terminal encoding unknown -- assuming '
                        'UTF-8 or Latin-1.')
                    try:
                        prompt = prompt.encode('utf-8')
                    except UnicodeEncodeError:
                        prompt = prompt.encode('latin1')
        prompt = purple(prompt)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        if not isinstance(x, unicode):
            # for Python 2.x, try to get a Unicode string out of it
            if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
                if TERM_ENCODING:
                    x = x.decode(TERM_ENCODING)
                else:
                    print turquoise(
                        '* Note: non-ASCII characters entered '
                        'and terminal encoding unknown -- assuming '
                        'UTF-8 or Latin-1.')
                    try:
                        x = x.decode('utf-8')
                    except UnicodeDecodeError:
                        x = x.decode('latin1')
        try:
            x = validator(x)
        except ValidationError, err:
            print red('* ' + str(err))
            continue
        break
예제 #31
0
 def init(self):
     Builder.init(self)
     errors = False
     if not self.config.omegat_translated_path:
         self.info(red("'omegat_translated_path' should not be empty."))
         errors = True
     if not self.config.omegat_project_path:
         self.info(red("'omegat_project_path' should not be empty."))
         errors = True
     if self.config.omegat_translated_path not in self.config.locale_dirs:
         self.info(red("'omegat_translated_path' should be in locale_dirs."))
         errors = True
     if not self.config.language:
         self.info(red("'language' should be set."))
         errors = True
     if errors:
         self.info(red("    -> Please check conf.py"))
         raise RuntimeError("lack setting")
예제 #32
0
 def visit_abjad_input_block(self, node):
     try:
         #print()
         message = bold(red('Found abjad_input_block.'))
         self.builder.warn(message, (self.builder.current_docname, node.line))
         #print(stringtools.normalize(node.pformat()))
     except:
         traceback.print_exc()
     raise nodes.SkipNode
예제 #33
0
def default_role_error(
    name, rawtext, text, lineno, inliner, options=None, content=None
):
    msg = (
        "Default role used (`single backticks`) at line %s: %s. Did you mean "
        "to use two backticks for ``code``, or miss an underscore for a "
        "`link`_ ?" % (lineno, rawtext)
    )
    raise SphinxError(red(msg))
예제 #34
0
    def _find_misspellings(self, docname, doctree):

        excluded = Matcher(self.config.spelling_exclude_patterns)
        if excluded(self.env.doc2path(docname, None)):
            return
        # Build the document-specific word filter based on any good
        # words listed in spelling directives. If we have no such
        # words, we want to push an empty list of filters so that we
        # can always safely pop the filter stack when we are done with
        # this document.
        doc_filters = []
        good_words = self.env.spelling_document_words.get(docname)
        if good_words:
            logger.info('Extending local dictionary for %s', docname)
            doc_filters.append(filters.IgnoreWordsFilterFactory(good_words))
        self.checker.push_filters(doc_filters)

        for node in doctree.traverse(docutils.nodes.Text):
            if (node.tagname == '#text' and node.parent
                    and node.parent.tagname in self.TEXT_NODES):

                # Figure out the line number for this node by climbing the
                # tree until we find a node that has a line number.
                lineno = None
                parent = node
                seen = set()
                while lineno is None:
                    # logger.info('looking for line number on %r' % node)
                    seen.add(parent)
                    parent = node.parent
                    if parent is None or parent in seen:
                        break
                    lineno = parent.line

                # Check the text of the node.
                misspellings = self.checker.check(node.astext())
                for word, suggestions, context_line in misspellings:
                    msg_parts = ['Spell check', red(word)]
                    if self.format_suggestions(suggestions) != '':
                        msg_parts.append(self.format_suggestions(suggestions))
                    msg_parts.append(context_line)
                    msg = ': '.join(msg_parts) + '.'
                    loc = (docname, lineno) if lineno else docname
                    if self.config.spelling_warning:
                        logger.warning(msg, location=loc)
                    elif self.config.spelling_verbose:
                        logger.info(msg, location=loc)
                    yield "%s:%s: (%s) %s %s\n" % (
                        self.env.doc2path(docname, None),
                        lineno,
                        word,
                        self.format_suggestions(suggestions),
                        context_line,
                    )

        self.checker.pop_filters()
        return
예제 #35
0
 def visit_abjad_thumbnail_block_latex(self, node):
     try:
         print()
         message = bold(red('Found abjad_thumbnail_block.'))
         self.builder.warn(message, (self.builder.current_docname, node.line))
         print(systemtools.TestManager.clean_string(node.pformat()))
     except:
         traceback.print_exc()
     raise nodes.SkipNode
예제 #36
0
 def init(self):
     Builder.init(self)
     errors = False
     if not self.config.omegat_translated_path:
         self.info(red("'omegat_translated_path' should not be empty."))
         errors = True
     if not self.config.omegat_project_path:
         self.info(red("'omegat_project_path' should not be empty."))
         errors = True
     if self.config.omegat_translated_path not in self.config.locale_dirs:
         self.info(red("'omegat_translated_path' should be in locale_dirs."))
         errors = True
     if not self.config.language:
         self.info(red("'language' should be set."))
         errors = True
     if errors:
         self.info(red("    -> Please check conf.py"))
         raise RuntimeError("lack setting")
예제 #37
0
 def write(self, *ignored):
     
     self.init_document_data()
     
     if self.config.pdf_verbosity > 1:
         rst2pdf.log.log.setLevel(logging.DEBUG)
     elif self.config.pdf_verbosity > 0:
         rst2pdf.log.log.setLevel(logging.INFO)
 
     for entry in self.document_data:
         try:
             docname, targetname, title, author = entry[:4]
             # Custom options per document
             if len(entry)>4 and isinstance(entry[4],dict): 
                 opts=entry[4]
             else:
                 opts={}
             self.info("processing " + targetname + "... ", nonl=1)
             
             class dummy:
                 extensions=self.config.pdf_extensions
                 
             createpdf.add_extensions(dummy())
             
             self.page_template=opts.get('pdf_page_template',self.config.pdf_page_template)
             
             docwriter = PDFWriter(self,
                             stylesheets=opts.get('pdf_stylesheets',self.config.pdf_stylesheets),
                             language=opts.get('pdf_language',self.config.pdf_language),
                             breaklevel=opts.get('pdf_break_level',self.config.pdf_break_level),
                             breakside=opts.get('pdf_breakside',self.config.pdf_breakside),
                             fontpath=opts.get('pdf_font_path',self.config.pdf_font_path),
                             fitmode=opts.get('pdf_fit_mode',self.config.pdf_fit_mode),
                             compressed=opts.get('pdf_compressed',self.config.pdf_compressed),
                             inline_footnotes=opts.get('pdf_inline_footnotes',self.config.pdf_inline_footnotes),
                             splittables=opts.get('pdf_splittables',self.config.pdf_splittables),
                             default_dpi=opts.get('pdf_default_dpi',self.config.pdf_default_dpi),
                             page_template=self.page_template,
                             invariant=opts.get('pdf_invariant',self.config.pdf_invariant),
                             srcdir=self.srcdir,
                             config=self.config
                             )
             
             tgt_file = path.join(self.outdir, targetname + self.out_suffix)
             destination = FileOutput(destination=open(tgt_file,'wb'), encoding='utf-8')
             doctree = self.assemble_doctree(docname,title,author, 
                 appendices=opts.get('pdf_appendices', self.config.pdf_appendices) or [])
             doctree.settings.author=author
             doctree.settings.title=title
             self.info("done")
             self.info("writing " + targetname + "... ", nonl=1)
             docwriter.write(doctree, destination)
             self.info("done")
         except Exception, e:
             rst2pdf.log.log.error(str(e))
             print_exc()
             self.info(red("FAILED"))
예제 #38
0
 def visit_abjad_input_block(self, node):
     try:
         print()
         message = bold(red('Found abjad_input_block.'))
         self.builder.warn(message, (self.builder.current_docname, node.line))
         print(systemtools.TestManager.clean_string(node.pformat()))
     except:
         traceback.print_exc()
     raise nodes.SkipNode
예제 #39
0
 def visit_abjad_input_block(self, node):
     try:
         #print()
         message = bold(red('Found abjad_input_block.'))
         self.builder.warn(message,
                           (self.builder.current_docname, node.line))
         #print(stringtools.normalize(node.pformat()))
     except:
         traceback.print_exc()
     raise nodes.SkipNode
예제 #40
0
    def _find_misspellings(self, docname, doctree):

        excluded = Matcher(self.config.spelling_exclude_patterns)
        if excluded(self.env.doc2path(docname, None)):
            return
        # Build the document-specific word filter based on any good
        # words listed in spelling directives. If we have no such
        # words, we want to push an empty list of filters so that we
        # can always safely pop the filter stack when we are done with
        # this document.
        doc_filters = []
        good_words = self.env.spelling_document_words.get(docname)
        if good_words:
            logger.info('Extending local dictionary for %s', docname)
            doc_filters.append(filters.IgnoreWordsFilterFactory(good_words))
        self.checker.push_filters(doc_filters)

        for node in doctree.traverse(docutils.nodes.Text):
            if (node.tagname == '#text' and node.parent
                    and node.parent.tagname in self.TEXT_NODES):

                # Get the location of the text being checked so we can
                # report it in the output file. Nodes from text that
                # comes in via an 'include' directive does not include
                # the full path, so convert all to relative path
                # for consistency.
                source, lineno = docutils.utils.get_source_line(node)
                source = osutil.relpath(source)

                # Check the text of the node.
                misspellings = self.checker.check(node.astext())
                for word, suggestions, context_line in misspellings:
                    msg_parts = [
                        f'{source}:{lineno}: ',
                        'Spell check',
                        red(word),
                    ]
                    if self.format_suggestions(suggestions) != '':
                        msg_parts.append(self.format_suggestions(suggestions))
                    msg_parts.append(context_line)
                    msg = ': '.join(msg_parts) + '.'
                    if self.config.spelling_warning:
                        logger.warning(msg)
                    elif self.config.spelling_verbose:
                        logger.info(msg)
                    yield "%s:%s: (%s) %s %s\n" % (
                        source,
                        lineno,
                        word,
                        self.format_suggestions(suggestions),
                        context_line,
                    )

        self.checker.pop_filters()
        return
예제 #41
0
    def write_c_coverage(self) -> None:
        output_file = path.join(self.outdir, 'c.txt')
        with open(output_file, 'w', encoding="utf-8") as op:
            if self.config.coverage_write_headline:
                write_header(op, 'Undocumented C API elements', '=')
            op.write('\n')

            for filename, undoc in self.c_undoc.items():
                write_header(op, filename)
                for typ, name in sorted(undoc):
                    op.write(' * %-50s [%9s]\n' % (name, typ))
                    if self.config.coverage_show_missing_items:
                        if self.app.quiet or self.app.warningiserror:
                            logger.warning(__('undocumented c api: %s [%s] in file %s'),
                                           name, typ, filename)
                        else:
                            logger.info(red('undocumented  ') + 'c   ' + 'api       ' +
                                        '%-30s' % (name + " [%9s]" % typ) +
                                        red(' - in file ') + filename)
                op.write('\n')
예제 #42
0
 def process_result(self, result):
     # type: (Tuple[unicode, unicode, int, unicode, unicode, int]) -> None
     uri, docname, lineno, status, info, code = result
     if status == 'unchecked':
         return
     if status == 'working' and info == 'old':
         return
     if lineno:
         logger.info('(line %4d) ', lineno, nonl=1)
     if status == 'ignored':
         if info:
             logger.info(darkgray('-ignored- ') + uri + ': ' + info)
         else:
             logger.info(darkgray('-ignored- ') + uri)
     elif status == 'local':
         logger.info(darkgray('-local-   ') + uri)
         self.write_entry('local', docname, lineno, uri)
     elif status == 'working':
         logger.info(darkgreen('ok        ') + uri + info)
     elif status == 'broken':
         self.write_entry('broken', docname, lineno, uri + ': ' + info)
         if self.app.quiet or self.app.warningiserror:
             logger.warning('broken link: %s (%s)',
                            uri,
                            info,
                            location=(self.env.doc2path(docname), lineno))
         else:
             logger.info(red('broken    ') + uri + red(' - ' + info))
     elif status == 'redirected':
         text, color = {
             301: ('permanently', darkred),
             302: ('with Found', purple),
             303: ('with See Other', purple),
             307: ('temporarily', turquoise),
             0: ('with unknown code', purple),
         }[code]
         self.write_entry('redirected ' + text, docname, lineno,
                          uri + ' to ' + info)
         logger.info(
             color('redirect  ') + uri +
             color(' - ' + text + ' to ' + info))
예제 #43
0
    def _do_write(self, output, docname, doctree):

        # Build the document-specific word filter based on any good
        # words listed in spelling directives. If we have no such
        # words, we want to push an empty list of filters so that we
        # can always safely pop the filter stack when we are done with
        # this document.
        doc_filters = []
        good_words = self.env.spelling_document_words.get(docname)
        if good_words:
            logger.info('Extending local dictionary for %s', docname)
            doc_filters.append(filters.IgnoreWordsFilterFactory(good_words))
        self.checker.push_filters(doc_filters)

        for node in doctree.traverse(docutils.nodes.Text):
            if (node.tagname == '#text' and node.parent
                    and node.parent.tagname in self.TEXT_NODES):

                # Figure out the line number for this node by climbing the
                # tree until we find a node that has a line number.
                lineno = None
                parent = node
                seen = set()
                while lineno is None:
                    # logger.info('looking for line number on %r' % node)
                    seen.add(parent)
                    parent = node.parent
                    if parent is None or parent in seen:
                        break
                    lineno = parent.line

                # Check the text of the node.
                misspellings = self.checker.check(node.astext())
                for word, suggestions, context_line in misspellings:
                    msg_parts = [docname + '.rst']
                    if lineno:
                        msg_parts.append(darkgreen(str(lineno)))
                    msg_parts.append(red(word))
                    msg_parts.append(self.format_suggestions(suggestions))
                    msg_parts.append(context_line)
                    msg = ':'.join(msg_parts)
                    logger.info(msg)
                    output.write(u"%s:%s: (%s) %s %s\n" % (
                        self.env.doc2path(docname, None),
                        lineno,
                        word,
                        self.format_suggestions(suggestions),
                        context_line,
                    ))
                    self.misspelling_count += 1

        self.checker.pop_filters()
        return
예제 #44
0
 def visit_abjad_thumbnail_block_latex(self, node):
     try:
         print()
         message = bold(red('Found abjad_thumbnail_block.'))
         self.builder.warn(message,
                           (self.builder.current_docname, node.line))
         print(datastructuretools.String.normalize(node.pformat()))
     except KeyboardInterrupt:
         sys.exit(1)
     except:
         traceback.print_exc()
     raise nodes.SkipNode
예제 #45
0
 def put(self, item: logging.LogRecord, block=True, timeout=None):
     message = item.getMessage()
     # line nos are separate records
     if ": line" in message:
         self._last_line_no = item
     # same formatting as in sphinx.builders.linkcheck
     # to avoid false positives if "broken" is in url
     if red("broken    ") in message or "broken link:" in message:
         if self._last_line_no:
             super().put(self._last_line_no, block=block, timeout=timeout)
             self._last_line_no = None
         return super().put(item, block=block, timeout=timeout)
예제 #46
0
def handle_exception(app, args, exception, stderr=sys.stderr):
    # type: (Sphinx, Any, Union[Exception, KeyboardInterrupt], IO) -> None
    if args.pdb:
        import pdb
        print(red(__('Exception occurred while building, starting debugger:')),
              file=stderr)
        traceback.print_exc()
        pdb.post_mortem(sys.exc_info()[2])
    else:
        print(file=stderr)
        if args.verbosity or args.traceback:
            traceback.print_exc(None, stderr)
            print(file=stderr)
        if isinstance(exception, KeyboardInterrupt):
            print(__('interrupted!'), file=stderr)
        elif isinstance(exception, SystemMessage):
            print(red(__('reST markup error:')), file=stderr)
            print(terminal_safe(exception.args[0]), file=stderr)
        elif isinstance(exception, SphinxError):
            print(red('%s:' % exception.category), file=stderr)
            print(terminal_safe(text_type(exception)), file=stderr)
        elif isinstance(exception, UnicodeError):
            print(red(__('Encoding error:')), file=stderr)
            print(terminal_safe(text_type(exception)), file=stderr)
            tbpath = save_traceback(app)
            print(red(__('The full traceback has been saved in %s, if you want '
                         'to report the issue to the developers.') % tbpath),
                  file=stderr)
        elif isinstance(exception, RuntimeError) and 'recursion depth' in str(exception):
            print(red(__('Recursion error:')), file=stderr)
            print(terminal_safe(text_type(exception)), file=stderr)
            print(file=stderr)
            print(__('This can happen with very large or deeply nested source '
                     'files.  You can carefully increase the default Python '
                     'recursion limit of 1000 in conf.py with e.g.:'), file=stderr)
            print(__('    import sys; sys.setrecursionlimit(1500)'), file=stderr)
        else:
            print(red(__('Exception occurred:')), file=stderr)
            print(format_exception_cut_frames().rstrip(), file=stderr)
            tbpath = save_traceback(app)
            print(red(__('The full traceback has been saved in %s, if you '
                         'want to report the issue to the developers.') % tbpath),
                  file=stderr)
            print(__('Please also report this if it was a user error, so '
                     'that a better error message can be provided next time.'),
                  file=stderr)
            print(__('A bug report can be filed in the tracker at '
                     '<https://github.com/sphinx-doc/sphinx/issues>. Thanks!'),
                  file=stderr)
예제 #47
0
    def check(self, node, docname):
        uri = node["refuri"]

        if "#" in uri:
            uri = uri.split("#")[0]

        if uri in self.good:
            return

        lineno = None
        while lineno is None:
            node = node.parent
            if node is None:
                break
            lineno = node.line

        if len(uri) == 0 or uri[0:7] == "mailto:" or uri[0:4] == "ftp:":
            return

        if lineno:
            self.info("(line %3d) " % lineno, nonl=1)
        if uri[0:5] == "http:" or uri[0:6] == "https:":
            self.info(uri, nonl=1)

            if uri in self.broken:
                (r, s) = self.broken[uri]
            elif uri in self.redirected:
                (r, s) = self.redirected[uri]
            else:
                (r, s) = self.resolve(uri)

            if r == 0:
                self.info(" - " + darkgreen("working"))
                self.good.add(uri)
            elif r == 2:
                self.info(" - " + red("broken: ") + s)
                self.write_entry("broken", docname, lineno, uri + ": " + s)
                self.broken[uri] = (r, s)
                if self.app.quiet:
                    self.warn("broken link: %s" % uri, "%s:%s" % (self.env.doc2path(docname), lineno))
            else:
                self.info(" - " + purple("redirected") + " to " + s)
                self.write_entry("redirected", docname, lineno, uri + " to " + s)
                self.redirected[uri] = (r, s)
        else:
            self.info(uri + " - " + darkgray("local"))
            self.write_entry("local", docname, lineno, uri)

        if self.broken:
            self.app.statuscode = 1
예제 #48
0
파일: linkcheck.py 프로젝트: LFYG/sphinx
 def process_result(self, result):
     # type: (Tuple[unicode, unicode, int, unicode, unicode, int]) -> None
     uri, docname, lineno, status, info, code = result
     if status == 'unchecked':
         return
     if status == 'working' and info == 'old':
         return
     if lineno:
         logger.info('(line %4d) ', lineno, nonl=1)
     if status == 'ignored':
         if info:
             logger.info(darkgray('-ignored- ') + uri + ': ' + info)
         else:
             logger.info(darkgray('-ignored- ') + uri)
     elif status == 'local':
         logger.info(darkgray('-local-   ') + uri)
         self.write_entry('local', docname, lineno, uri)
     elif status == 'working':
         logger.info(darkgreen('ok        ') + uri + info)
     elif status == 'broken':
         self.write_entry('broken', docname, lineno, uri + ': ' + info)
         if self.app.quiet or self.app.warningiserror:
             logger.warning('broken link: %s (%s)', uri, info,
                            location=(self.env.doc2path(docname), lineno))
         else:
             logger.info(red('broken    ') + uri + red(' - ' + info))
     elif status == 'redirected':
         text, color = {
             301: ('permanently', darkred),
             302: ('with Found', purple),
             303: ('with See Other', purple),
             307: ('temporarily', turquoise),
             0:   ('with unknown code', purple),
         }[code]
         self.write_entry('redirected ' + text, docname, lineno,
                          uri + ' to ' + info)
         logger.info(color('redirect  ') + uri + color(' - ' + text + ' to ' + info))
예제 #49
0
def create_graph(path: Path) -> Dict[str, str]:
    """
    Convert a file containing a whitespace delimited edge list (key value pairs) to a dict. Throws error on duplicate keys.
    """
    graph_edges = {}
    broken = False
    with open(path, "r") as file:
        for line_num, line in enumerate(file, start=1):
            line = line.strip()
            if len(line) == 0 or line.startswith("#"):
                continue
            match = RE_OBJ.fullmatch(line)

            if match == None:
                logger.error(
                    red(f"rediraffe: line {line_num} of the redirects is invalid!")
                )
                broken = True
                continue

            edge_from = match.group(2) or match.group(3)
            edge_to = match.group(5) or match.group(6)
            if edge_from in graph_edges:
                # Duplicate vertices not allowed / Vertices can only have 1 outgoing edge
                logger.error(
                    red(
                        f"rediraffe: {edge_from} is redirected multiple times in the rediraffe_redirects file!"
                    )
                )
                broken = True
            graph_edges[edge_from] = edge_to
    if broken:
        err_msg = f"rediraffe: Error(s) in parsing the redirects file."
        logger.error(err_msg)
        raise ExtensionError(err_msg)
    return graph_edges
예제 #50
0
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = purple(PROMPT_PREFIX + '%s [%s]: ' % (text, default))
        else:
            prompt = purple(PROMPT_PREFIX + text + ': ')
        x = raw_input(prompt)
        if default and not x:
            x = default
        if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
            if TERM_ENCODING:
                x = x.decode(TERM_ENCODING)
            else:
                print turquoise('* Note: non-ASCII characters entered and terminal '
                                'encoding unknown -- assuming UTF-8 or Latin-1.')
                try:
                    x = x.decode('utf-8')
                except UnicodeDecodeError:
                    x = x.decode('latin1')
        if validator and not validator(x):
            print red('* ' + validator.__doc__)
            continue
        break
    d[key] = x
예제 #51
0
    def check_missing(self):
        all_settings = self.project_settings()
        documented_settings = self.documented_settings()
        self.undocumented.update(setting for setting in all_settings
                                 ^ documented_settings
                                 if not self.is_ignored_setting(setting))

        for setting in self.undocumented:
            self.app.statuscode = 2
            print(ERR_MISSING_DOC.format(
                error=red(ERR),
                name=bold(setting),
            ))
        if not self.app.statuscode:
            print(green(OK_STATUS))
예제 #52
0
    def write_doc(self, docname, doctree):
        self.checker.push_filters(self.env.spelling_document_filters[docname])

        for node in doctree.traverse(docutils.nodes.Text):
            if (node.tagname == '#text'
                    and node.parent
                    and node.parent.tagname in self.TEXT_NODES):

                # Figure out the line number for this node by climbing the
                # tree until we find a node that has a line number.
                lineno = None
                parent = node
                seen = set()
                while lineno is None:
                    #self.info('looking for line number on %r' % node)
                    seen.add(parent)
                    parent = node.parent
                    if parent is None or parent in seen:
                        break
                    lineno = parent.line

                # Check the text of the node.
                for word, suggestions in self.checker.check(node.astext()):
                    msg_parts = [docname + '.po']
                    if lineno:
                        msg_parts.append(darkgreen(str(lineno)))
                    msg_parts.append(' %s ' % red(word))
                    msg_parts.append(self.format_suggestions(suggestions))
                    msg_parts.append(node.astext())
                    msg = ':'.join(msg_parts)
                    self.info(msg)

                    if False:  # To generate simple output.txt for spell_statistic command
                        self.output.write('%s\n' % word)
                    else:
                        self.output.write(u"%s:%s: (%s) %s | %s\n" % (
                            docname + '.po',
                            lineno, word,
                            self.format_suggestions(suggestions),
                            node.astext()
                        ))

                    # We found at least one bad spelling, so set the status
                    # code for the app to a value that indicates an error.
                    self.app.statuscode = 1

        self.checker.pop_filters()
        return
예제 #53
0
    def check_missing(self):
        all_settings = self.project_settings()
        documented_settings = self.documented_settings()
        self.undocumented.update(
            setting for setting in all_settings ^ documented_settings
            if not self.is_ignored_setting(setting)
        )

        for setting in self.undocumented:
            self.app.statuscode = 2
            print(ERR_MISSING_DOC.format(
                error=red(ERR),
                name=bold(setting),
            ))
        if not self.app.statuscode:
            print(green(OK_STATUS))
예제 #54
0
파일: btest-sphinx.py 프로젝트: bro/btest
    def run(self):
        if self.has_run:
            return

        App.builder.info("running test %s ..." % darkgreen(self.path))

        self.rst_output = os.path.join(BTestTmp, "%s" % self.tag)
        os.environ["BTEST_RST_OUTPUT"] = self.rst_output

        self.cleanTmps()

        try:
            subprocess.check_call("btest -S %s" % self.path, shell=True)
        except (OSError, IOError, subprocess.CalledProcessError) as e:
            # Equivalent to Directive.error(); we don't have an
            # directive object here and can't pass it in because
            # it doesn't pickle.
            App.builder.warn(red("BTest error: %s" % e))
예제 #55
0
def do_prompt(d, key, text, default=None, validator=nonempty):
    while True:
        if default:
            prompt = PROMPT_PREFIX + '%s [%s]: ' % (text, default)
        else:
            prompt = PROMPT_PREFIX + text + ': '
        if sys.version_info < (3, 0):
            # for Python 2.x, try to get a Unicode string out of it
            if prompt.encode('ascii', 'replace').decode('ascii', 'replace') \
                    != prompt:
                if TERM_ENCODING:
                    prompt = prompt.encode(TERM_ENCODING)
                else:
                    print(turquoise('* Note: non-ASCII default value provided '
                                    'and terminal encoding unknown -- assuming '
                                    'UTF-8 or Latin-1.'))
                    try:
                        prompt = prompt.encode('utf-8')
                    except UnicodeEncodeError:
                        prompt = prompt.encode('latin1')
        prompt = purple(prompt)
        x = term_input(prompt).strip()
        if default and not x:
            x = default
        if not isinstance(x, str):
            # for Python 2.x, try to get a Unicode string out of it
            if x.decode('ascii', 'replace').encode('ascii', 'replace') != x:
                if TERM_ENCODING:
                    x = x.decode(TERM_ENCODING)
                else:
                    print(turquoise('* Note: non-ASCII characters entered '
                                    'and terminal encoding unknown -- assuming '
                                    'UTF-8 or Latin-1.'))
                    try:
                        x = x.decode('utf-8')
                    except UnicodeDecodeError:
                        x = x.decode('latin1')
        try:
            x = validator(x)
        except ValidationError as err:
            print(red('* ' + str(err)))
            continue
        break
    d[key] = x
예제 #56
0
    def write_doc(self, docname, doctree):
        self.checker.push_filters(self.env.spelling_document_filters[docname])

        for node in doctree.traverse(docutils.nodes.Text):
            if node.tagname == '#text' and node.parent and node.parent.tagname in TEXT_NODES:

                # Figure out the line number for this node by climbing the
                # tree until we find a node that has a line number.
                lineno = None
                parent = node
                seen = set()
                while lineno is None:
                    #self.info('looking for line number on %r' % node)
                    seen.add(parent)
                    parent = node.parent
                    if parent is None or parent in seen:
                        break
                    lineno = parent.line
                filename = self.env.doc2path(docname, base=None)

                # Check the text of the node.
                for word, suggestions in self.checker.check(node.astext()):
                    msg_parts = []
                    if lineno:
                        msg_parts.append(darkgreen('(line %3d)' % lineno))
                    msg_parts.append(red(word))
                    msg_parts.append(self.format_suggestions(suggestions))
                    msg = ' '.join(msg_parts)
                    self.info(msg)
                    self.output.write(u"%s:%s: (%s) %s\n" % (
                            self.env.doc2path(docname, None),
                            lineno, word,
                            self.format_suggestions(suggestions),
                            ))

                    # We found at least one bad spelling, so set the status
                    # code for the app to a value that indicates an error.
                    self.app.statuscode = 1

        self.checker.pop_filters()
        return
예제 #57
0
    def run(self):
        try:
            self.resolve_substitutions_refs()
            queryName = self.arguments[0]
            queryParams = self.extract_query_params()

            if ClearQuest.connection is None:
                settings = self.get_settings()
                if None in settings.values():
                    missing = [ name for name, value in settings.items() if value is None ]
                    ClearQuest.reporter.warning(console.red( #@UndefinedVariable
                        'Missing settings "%s". ' % '", "'.join(missing) +
                        'Looked in ~/.sphinxcontrib and in directive options.'
                    ))
                ClearQuest.reporter.info('Opening ClearQuest session...')
                ClearQuest.connection = ClearQuestConnection(**settings)

            ClearQuest.reporter.info('Executing ClearQuest query "%s"...' % queryName)
            columns, records = ClearQuest.connection.run_query(queryName, queryParams)
            
            if len(records) == 0:
                # No results from ClearQuest query, we fill one line with dashes
                records.append(["--"] * len(columns))
            
            col_widths = self.get_column_widths(header=columns, content=records)
            table_head = [ self.create_row(columns) ]
            table_body = [ self.create_row(line) for line in records ]

        except Exception, detail:
            if isinstance(detail, DirectiveError):
                message = detail.msg
            else:
                message = str(detail)
            error = ClearQuest.reporter.error(
                'Error with query data in "%s" directive:\n%s' % (self.name, message),
                nodes.literal_block(self.block_text, self.block_text),
                line=self.lineno
            )
            return [error]
예제 #58
0
    def write_doc(self, docname, doctree):

        nodes = iter(doctree.traverse())

        for node in nodes:

            if valid(node):
                try:
                    nodes.next()
                    nodes.next()
                except StopIteration:
                    break

            if json_block(node):
                lineno = node.line
                body = strip_leading_chars(node.astext())

                # check if the json is valid.
                if not check_json(body):
                    f = docname + '.rst'
                    msg = f + ' | [INVALID JSON] | Line ' + str(lineno)
                    self.info(red(msg))
                    self.output.write(u"%s [Invalid JSON] %s \n" % (
                        self.env.doc2path(docname, None),
                        lineno
                    ))

                # check if the indentation is consistent
                if not check_indent(body):
                    f = docname + '.rst'
                    msg = f + ' | [INDENT ERROR] | Line ' + str(lineno)
                    self.info(yellow(msg))
                    self.output.write(u"%s [INDENT] %s \n" % (
                        self.env.doc2path(docname, None),
                        lineno
                    ))

        return
예제 #59
0
 def process_result(self, result):
     uri, docname, lineno, status, info = result
     if status == 'unchecked':
         return
     if status == 'working' and info != 'new':
         return
     if lineno:
         self.info('(line %3d) ' % lineno, nonl=1)
     if status == 'ignored':
         self.info(uri + ' - ' + darkgray('ignored'))
     elif status == 'local':
         self.info(uri + ' - ' + darkgray('local'))
         self.write_entry('local', docname, lineno, uri)
     elif status == 'working':
         self.info(uri + ' - ' + darkgreen('working'))
     elif status == 'broken':
         self.info(uri + ' - ' + red('broken: ') + info)
         self.write_entry('broken', docname, lineno, uri + ': ' + info)
         if self.app.quiet:
             self.warn('broken link: %s' % uri,
                       '%s:%s' % (self.env.doc2path(docname), lineno))
     elif status == 'redirected':
         self.info(uri + ' - ' + purple('redirected') + ' to ' + info)
         self.write_entry('redirected', docname, lineno, uri + ' to ' + info)