예제 #1
0
def load_style_dir(app):
    if not app.config.bibtex_styles_path:
        raise SphinxWarning('No BibTeX styles path specified.')

    styles_paths = app.config.bibtex_styles_path
    if isinstance(styles_paths, str):
        styles_paths = [styles_paths]

    html_style_name, latex_style_name = app.config.bibtex_style
    style_dir = None

    for path in styles_paths:
        dirpath = os.path.join(path, html_style_name + '.html')
        if os.path.exists(dirpath):
            style_dir = path

    if not style_dir:
        raise SphinxWarning("Style (%s) does not exist in the styles path." % \
                            html_style_name)

    # NOTE: Store style dir and not style in env since Style class cannot be pickle
    app.env.bibtex_style_dir = style_dir
    app.env.bibtex_style_name = html_style_name

    # latex reconfiguration
    app.config.latex_elements.setdefault('preamble', '')
    app.config.latex_elements['preamble'] += '\\usepackage{natbib}'

    app.config.latex_elements.setdefault('footer', '')
    app.config.latex_elements[
        'footer'] += "\\bibliographystyle{%s}" % latex_style_name
예제 #2
0
def parse_bibtex(app):
    # load bibtex path
    if not app.config.bibtex_path:
        raise SphinxWarning('No BibTeX path specified.')

    if os.path.isabs(app.config.bibtex_path):
        filepath = app.config.bibtex_path
    else:
        filepath = os.path.join(app.confdir, app.config.bibtex_path)

    if not os.path.exists(filepath):
        raise SphinxWarning("BibTeX file (%s) does not exists." % filepath)

    app.env.bibtex_path = filepath

    # parse bib
    parser = BibtexParser()

    try:
        data = parser.parse_file(filepath)
    except PybtexError as ex:
        raise SphinxWarning(ex)

    app.env.bibtex_entries = data.entries

    # latex reconfiguration
    filename = os.path.splitext(os.path.basename(filepath))[0]
    app.config.latex_elements.setdefault('footer', '')
    app.config.latex_elements['footer'] += "\\bibliography{%s}" % filename
예제 #3
0
 def filter(self, record):
     # type: (logging.LogRecord) -> bool
     if self.app.warningiserror:
         location = getattr(record, 'location', '')
         if location:
             raise SphinxWarning(location + ":" + record.msg % record.args)
         else:
             raise SphinxWarning(record.msg % record.args)
     else:
         return True
예제 #4
0
 def filter(self, record):
     # type: (logging.LogRecord) -> bool
     if getattr(record, 'skip_warningsiserror', False):
         # disabled by DisableWarningIsErrorFilter
         return True
     elif self.app.warningiserror:
         location = getattr(record, 'location', '')
         if location:
             raise SphinxWarning(location + ":" + record.msg % record.args)
         else:
             raise SphinxWarning(record.msg % record.args)
     else:
         return True
예제 #5
0
    def warn(self, message, location=None, prefix='WARNING: '):
        """Emit a warning.

        If *location* is given, it should either be a tuple of (docname, lineno)
        or a string describing the location of the warning as well as possible.

        *prefix* usually should not be changed.

        .. note::

           For warnings emitted during parsing, you should use
           :meth:`.BuildEnvironment.warn` since that will collect all
           warnings during parsing for later output.
        """
        if isinstance(location, tuple):
            docname, lineno = location
            if docname:
                location = '%s:%s' % (self.env.doc2path(docname), lineno or '')
            else:
                location = None
        warntext = location and '%s: %s%s\n' % (location, prefix, message) or \
            '%s%s\n' % (prefix, message)
        if self.warningiserror:
            raise SphinxWarning(warntext)
        self._warncount += 1
        self._log(warntext, self._warning, True)
예제 #6
0
    def warn(self, message, location=None, prefix='WARNING: ',
             type=None, subtype=None, colorfunc=darkred):
        # type: (unicode, unicode, unicode, unicode, unicode, Callable) -> None
        """Emit a warning.

        If *location* is given, it should either be a tuple of (docname, lineno)
        or a string describing the location of the warning as well as possible.

        *prefix* usually should not be changed.

        *type* and *subtype* are used to suppress warnings with :confval:`suppress_warnings`.

        .. note::

           For warnings emitted during parsing, you should use
           :meth:`.BuildEnvironment.warn` since that will collect all
           warnings during parsing for later output.
        """
        if is_suppressed_warning(type, subtype, self.config.suppress_warnings):
            return

        if isinstance(location, tuple):
            docname, lineno = location
            if docname:
                location = '%s:%s' % (self.env.doc2path(docname), lineno or '')
            else:
                location = None
        warntext = location and '%s: %s%s\n' % (location, prefix, message) or \
            '%s%s\n' % (prefix, message)
        if self.warningiserror:
            raise SphinxWarning(warntext)
        self._warncount += 1
        self._log(colorfunc(warntext), self._warning, True)
예제 #7
0
파일: changelog.py 프로젝트: hj3938/dfhack
def generate_changelog(all=False):
    entries = parse_changelog()

    # scan for unrecognized sections
    for entry in entries:
        if entry.section not in CHANGELOG_SECTIONS:
            raise SphinxWarning('Unknown section: ' + entry.section)

    # ordered versions
    versions = ['future']
    # map versions to stable versions
    stable_version_map = {}
    # version -> section -> entry
    stable_entries = collections.defaultdict(
        lambda: collections.defaultdict(list))
    dev_entries = collections.defaultdict(
        lambda: collections.defaultdict(list))

    for entry in entries:
        # build list of all versions
        if entry.dev_version not in versions:
            versions.append(entry.dev_version)
        stable_version_map.setdefault(entry.dev_version, entry.stable_version)

        if not entry.dev_only:
            # add non-dev-only entries to both changelogs
            stable_entries[entry.stable_version][entry.section].append(entry)
        dev_entries[entry.dev_version][entry.section].append(entry)

    consolidate_changelog(stable_entries)
    consolidate_changelog(dev_entries)

    print_changelog(versions, stable_entries,
                    os.path.join(DOCS_ROOT, '_auto/news.rst'))
    print_changelog(versions, dev_entries,
                    os.path.join(DOCS_ROOT, '_auto/news-dev.rst'))

    if all:
        for version in versions:
            if version not in stable_version_map:
                print('warn: skipping ' + version)
                continue
            if stable_version_map[version] == version:
                version_entries = {version: stable_entries[version]}
            else:
                version_entries = {version: dev_entries[version]}
            print_changelog(
                [version],
                version_entries,
                os.path.join(DOCS_ROOT, '_changelogs/%s-github.txt' % version),
                replace=False)
            print_changelog(
                [version],
                version_entries,
                os.path.join(DOCS_ROOT, '_changelogs/%s-reddit.txt' % version),
                replace=False,
                prefix='> ')

    return entries
예제 #8
0
파일: conf.py 프로젝트: shizonic/fish-shell
def get_command_description(path, name):
    """ Return the description for a command, by parsing its synopsis line """
    with open(path) as fd:
        for line in fd:
            if line.startswith(name + " - "):
                _, desc = line.split(" - ", 1)
                return desc.strip()
    raise SphinxWarning("No description in file %s" % os.path.basename(path))
예제 #9
0
    def filter(self, record: logging.LogRecord) -> bool:
        if getattr(record, 'skip_warningsiserror', False):
            # disabled by DisableWarningIsErrorFilter
            return True
        elif self.app.warningiserror:
            location = getattr(record, 'location', '')
            try:
                message = record.msg % record.args
            except (TypeError, ValueError):
                message = record.msg  # use record.msg itself

            if location:
                raise SphinxWarning(location + ":" + message)
            else:
                raise SphinxWarning(message)
        else:
            return True
예제 #10
0
 def warn(self, message, location=None, prefix='WARNING: '):
     warntext = location and '%s: %s%s\n' % (location, prefix, message) or \
                '%s%s\n' % (prefix, message)
     if self.warningiserror:
         raise SphinxWarning(warntext)
     self._warncount += 1
     try:
         self._warning.write(warntext)
     except UnicodeEncodeError:
         encoding = getattr(self._warning, 'encoding', 'ascii') or 'ascii'
         self._warning.write(warntext.encode(encoding, 'replace'))
예제 #11
0
 def warn(self, message, location=None, prefix='WARNING: '):
     if isinstance(location, tuple):
         docname, lineno = location
         if docname:
             location = '%s:%s' % (self.env.doc2path(docname), lineno or '')
         else:
             location = None
     warntext = location and '%s: %s%s\n' % (location, prefix, message) or \
                '%s%s\n' % (prefix, message)
     if self.warningiserror:
         raise SphinxWarning(warntext)
     self._warncount += 1
     self._log(warntext, self._warning, True)
예제 #12
0
 def warn(self, message, location=None, prefix='WARNING: '):
     if isinstance(location, tuple):
         docname, lineno = location
         if docname:
             location = '%s:%s' % (self.env.doc2path(docname), lineno or '')
         else:
             location = None
     warntext = location and '%s: %s%s\n' % (location, prefix, message) or \
                '%s%s\n' % (prefix, message)
     if self.warningiserror:
         raise SphinxWarning(warntext)
     self._warncount += 1
     try:
         self._warning.write(warntext)
     except UnicodeEncodeError:
         encoding = getattr(self._warning, 'encoding', 'ascii') or 'ascii'
         self._warning.write(warntext.encode(encoding, 'replace'))
예제 #13
0
    def run(self):
        node = SaNode()
        node['alt'] = self.options.get('alt', None)
        node['link'] = True if 'link' in self.options else False
        node['render'] = self.options.get('render', None)

        def tolist(val):
            if val:
                return list(map(lambda i: i.strip(), val.split(',')))
            return []

        node['module'] = tolist(self.options.get('module', ''))
        node['include'] = tolist(self.options.get('include', None))
        node['exclude'] = tolist(self.options.get('exclude', None))

        if node['include'] and node['exclude']:
            raise SphinxWarning('sadisplay directive error - \
                    both defined :include: and :exclude:')

        return [node]
예제 #14
0
 def filter(self, record):
     # type: (logging.LogRecord) -> bool
     if self.app.warningiserror:
         raise SphinxWarning(record.msg % record.args)
     else:
         return True