Exemple #1
0
 def tearDown(self):
     self.__remove_tmp_dirs()
     TestExtension.symbols = []
     TestExtension.comments = []
     Logger.fatal_warnings = False
     Logger.silent = False
     Logger.reset()
Exemple #2
0
    def test_warning(self):
        test_journal = []

        Logger.warn('baz', 'This baz is bad')
        test_journal.append(
            LogEntry(WARNING, 'bar', 'baz', 'This baz is bad'))
        self.assertListEqual(Logger.journal, test_journal)
Exemple #3
0
    def test_warning(self):
        test_journal = []

        Logger.warn('baz', 'This baz is bad')
        test_journal.append(
            LogEntry(WARNING, 'bar', 'baz', 'This baz is bad'))
        self.assertListEqual(Logger.journal, test_journal)
Exemple #4
0
 def test_cannot_ignore_error(self):
     test_journal = []
     Logger.add_ignored_code('foo')
     with self.assertRaises(FooError):
         Logger.error('foo', 'This foo is bad I have to care')
     test_journal.append(LogEntry(ERROR, 'bar', 'foo',
                                  'This foo is bad I have to care'))
     self.assertListEqual(Logger.journal, test_journal)
Exemple #5
0
    def test_error(self):
        test_journal = []

        with self.assertRaises(FooError) as cm:
            Logger.error('foo', 'This foo is bad')
        self.assertEqual(cm.exception.message, 'This foo is bad')
        test_journal.append(LogEntry(ERROR, 'bar', 'foo', 'This foo is bad'))
        self.assertListEqual(Logger.journal, test_journal)
 def test_cannot_ignore_error(self):
     test_journal = []
     Logger.add_ignored_code('foo')
     with self.assertRaises(FooError):
         Logger.error('foo', 'This foo is bad I have to care')
     test_journal.append(
         LogEntry(ERROR, 'bar', 'foo', 'This foo is bad I have to care'))
     self.assertListEqual(Logger.journal, test_journal)
    def test_error(self):
        test_journal = []

        with self.assertRaises(FooError) as cm:
            Logger.error('foo', 'This foo is bad')
        self.assertEqual(cm.exception.message, 'This foo is bad')
        test_journal.append(LogEntry(ERROR, 'bar', 'foo', 'This foo is bad'))
        self.assertListEqual(Logger.journal, test_journal)
Exemple #8
0
 def setUp(self):
     here = os.path.dirname(__file__)
     Logger.reset()
     self.__md_dir = os.path.abspath(
         os.path.join(here, 'tmp-markdown-files'))
     self.__output_dir = os.path.abspath(os.path.join(here, 'html'))
     self.__remove_tmp_dirs()
     os.mkdir(self.__md_dir)
     Logger.silent = True
    def test_fatal_warnings(self):
        Logger.fatal_warnings = True
        test_journal = []

        with self.assertRaises(BazError) as cm:
            Logger.warn('baz', 'This baz is bad')
        self.assertEqual(cm.exception.message, 'This baz is bad')
        test_journal.append(LogEntry(ERROR, 'bar', 'baz', 'This baz is bad'))
        self.assertListEqual(Logger.journal, test_journal)
Exemple #10
0
    def test_fatal_warnings(self):
        Logger.fatal_warnings = True
        test_journal = []

        with self.assertRaises(BazError) as cm:
            Logger.warn('baz', 'This baz is bad')
        self.assertEqual(cm.exception.message, 'This baz is bad')
        test_journal.append(
            LogEntry(ERROR, 'bar', 'baz', 'This baz is bad'))
        self.assertListEqual(Logger.journal, test_journal)
Exemple #11
0
 def setUp(self):
     here = os.path.dirname(__file__)
     Logger.reset()
     self.__md_dir = os.path.abspath(os.path.join(
         here, 'tmp-markdown-files'))
     self.__output_dir = os.path.abspath(os.path.join(
         here, 'html'))
     self.__remove_tmp_dirs()
     os.mkdir(self.__md_dir)
     Logger.silent = True
Exemple #12
0
    def test_redefined_symbol(self):
        self.database.create_symbol(FunctionSymbol, unique_name='foo')

        Logger.fatal_warnings = True
        Logger.raise_on_fatal_warnings = True
        Logger.silent = True
        with self.assertRaises(RedefinedSymbolException):
            self.database.create_symbol(FunctionSymbol, unique_name='foo')
        Logger.fatal_warnings = False
        Logger.silent = False
        Logger.reset()
Exemple #13
0
def execute_command(parser, config, ext_classes):
    """
    Banana banana
    """
    res = 0
    cmd = config.get('command')

    get_private_folder = config.get('get_private_folder', False)

    if cmd == 'help':
        parser.print_help()
    elif cmd == 'run' or get_private_folder:  # git.mk backward compat
        app = Application(ext_classes)
        try:
            app.parse_config(config)
            if get_private_folder:
                print(app.private_folder)
                return res
            res = app.run()
        except HotdocException:
            res = len(Logger.get_issues())
        except Exception:  # pylint: disable=broad-except
            print("An unknown error happened while building the documentation"
                  " and hotdoc cannot recover from it. Please report "
                  "a bug with this error message and the steps to "
                  "reproduce it")
            traceback.print_exc()
            res = 1
        finally:
            app.finalize()
    elif cmd == 'init':
        try:
            create_default_layout(config)
        except HotdocException:
            res = 1
    elif cmd == 'conf':
        config.dump(conf_file=config.get('output_conf_file', None))
    elif cmd is None:
        if config.get('version'):
            print(VERSION)
        elif config.get('makefile_path'):
            here = os.path.dirname(__file__)
            path = os.path.join(here, 'utils', 'hotdoc.mk')
            print(os.path.abspath(path))
        elif config.get('get_conf_path'):
            key = config.get('get_conf_path')
            path = config.get_path(key, rel_to_cwd=True)
            if path is not None:
                print(path)
        elif config.get('get_conf_key'):
            key = config.get('get_conf_key')
            value = config.get(key, None)
            if value is not None:
                print(value)
        else:
            parser.print_usage()
    else:
        parser.print_usage()

    return res
Exemple #14
0
def run(args):
    """
    Banana banana
    """
    res = 0
    doc_repo = DocRepo()

    # pylint: disable=broad-except
    try:
        doc_repo.load_command_line(args)
        doc_repo.setup()
        doc_repo.format()
        doc_repo.persist()
    except HotdocException:
        res = len(Logger.get_issues())
    except Exception:
        print("An unknown error happened while building the documentation"
              " and hotdoc cannot recover from it. Please report "
              "a bug with this error message and the steps to "
              "reproduce it")
        traceback.print_exc()
        res = 1
    finally:
        doc_repo.finalize()

    return res
Exemple #15
0
def run(args):
    """
    Banana banana
    """
    res = 0
    doc_repo = DocRepo()

    # pylint: disable=broad-except
    try:
        doc_repo.load_command_line(args)
        doc_repo.setup()
        doc_repo.format()
        doc_repo.persist()
    except HotdocException:
        res = len(Logger.get_issues())
    except Exception:
        print ("An unknown error happened while building the documentation"
               " and hotdoc cannot recover from it. Please report "
               "a bug with this error message and the steps to "
               "reproduce it")
        traceback.print_exc()
        res = 1
    finally:
        doc_repo.finalize()

    return res
Exemple #16
0
 def setUp(self):
     self._test_dir = os.path.join(os.path.dirname(__file__), 'tmptestdir')
     try:
         shutil.rmtree(self._test_dir)
     except FileNotFoundError:
         pass
     os.mkdir(self._test_dir)
     os.chdir(self._test_dir)
     Logger.reset()
     self.__md_dir = os.path.abspath(
         os.path.join(self._test_dir, 'tmp-markdown-files'))
     self.__output_dir = os.path.abspath(
         os.path.join(self._test_dir, 'html'))
     self.__remove_tmp_dirs()
     os.mkdir(self.__md_dir)
     Logger.silent = True
Exemple #17
0
    def test_checkpoint(self):
        test_journal = []

        Logger.warn('baz', 'This baz is bad')
        test_journal.append(LogEntry(WARNING, 'bar', 'baz', 'This baz is bad'))
        self.assertListEqual(Logger.journal, test_journal)
        self.assertListEqual(Logger.since_checkpoint(), test_journal)
        Logger.checkpoint()
        self.assertListEqual(Logger.since_checkpoint(), [])
        Logger.warn('baz', 'This baz is really bad')
        test_journal.append(
            LogEntry(WARNING, 'bar', 'baz', 'This baz is really bad'))
        partial_journal = [
            LogEntry(WARNING, 'bar', 'baz', 'This baz is really bad')
        ]
        self.assertListEqual(Logger.journal, test_journal)
        self.assertListEqual(Logger.since_checkpoint(), partial_journal)
Exemple #18
0
    def test_checkpoint(self):
        test_journal = []

        Logger.warn('baz', 'This baz is bad')
        test_journal.append(
            LogEntry(WARNING, 'bar', 'baz', 'This baz is bad'))
        self.assertListEqual(Logger.journal, test_journal)
        self.assertListEqual(Logger.since_checkpoint(), test_journal)
        Logger.checkpoint()
        self.assertListEqual(Logger.since_checkpoint(), [])
        Logger.warn('baz', 'This baz is really bad')
        test_journal.append(LogEntry(WARNING, 'bar', 'baz',
                                     'This baz is really bad'))
        partial_journal = [LogEntry(WARNING, 'bar', 'baz',
                                    'This baz is really bad')]
        self.assertListEqual(Logger.journal, test_journal)
        self.assertListEqual(Logger.since_checkpoint(), partial_journal)
Exemple #19
0
 def setUp(self):
     Logger.reset()
     Logger.silent = True
     Logger.register_error_code('foo', FooError, 'bar')
     Logger.register_warning_code('baz', BazError, 'bar')
Exemple #20
0
 def test_ignore_warning(self):
     Logger.add_ignored_code('baz')
     Logger.warn('baz', 'This baz is bad but I do not care')
     self.assertListEqual(Logger.journal, [])
Exemple #21
0
 def test_unknown_codes(self):
     with self.assertRaises(AssertionError):
         Logger.warn('does-not-exist', 'Should not exist')
     with self.assertRaises(AssertionError):
         Logger.error('does-not-exist', 'Should not exist')
Exemple #22
0
class SitemapDuplicateError(HotdocSourceException):
    """
    Raised when the same file was listed multiple times in
    a sitemap file.
    """
    pass


class SitemapError(HotdocSourceException):
    """
    Generic sitemap error.
    """
    pass


Logger.register_error_code('bad-indent', IndentError, domain='sitemap')
Logger.register_error_code('sitemap-duplicate', SitemapDuplicateError,
                           domain='sitemap')
Logger.register_error_code('sitemap-error', SitemapError,
                           domain='sitemap')


# pylint: disable=too-few-public-methods
class StandaloneParser(object):
    """
    Banana banana
    """
    pass


class Sitemap(object):
Exemple #23
0
from hotdoc.core.extension import Extension
from hotdoc.core.formatter import Formatter
from hotdoc.core.tree import Page
from hotdoc.core.exceptions import HotdocException
from hotdoc.utils.loggable import error, Logger


class NoSuchLicenseException(HotdocException):
    """
    Raised when an unknown license is used
    """
    pass


Logger.register_error_code('no-such-license', NoSuchLicenseException,
                           domain='license-extension')


DESCRIPTION =\
    """
This extension helps licensing your hotdoc project
"""


HERE = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.join(HERE, 'data')


BASE_COPYRIGHT_SCHEMA = {'name': And(str, len),
                         Optional('email'): And(str, len),
                         Optional('years', default=[]): Schema([Use(int)])}
Exemple #24
0
from hotdoc.utils.setup_utils import THEME_VERSION
from hotdoc.utils.utils import OrderedSet
from hotdoc.utils.utils import id_from_text
from hotdoc.core.exceptions import HotdocException
from hotdoc.utils.loggable import Logger, warn, info


class HtmlFormatterBadLinkException(HotdocException):
    """
    Raised when a produced html page contains an empty local link
    to nowhere.
    """
    pass


Logger.register_warning_code('bad-local-link', HtmlFormatterBadLinkException,
                             domain='html-formatter')


HERE = os.path.dirname(__file__)


# pylint: disable=too-few-public-methods
class TocSection(object):
    """
    Banana banana
    """

    def __init__(self, summaries, name):
        self.summaries = summaries
        self.name = name
        self.id_ = ''.join(name.split())
Exemple #25
0
class PageNotFoundException(HotdocSourceException):
    """
    Raised when a subpage listed in the sitemap file could not be found
    in any of the include paths.
    """
    pass


class IndexExtensionNotFoundException(HotdocSourceException):
    """
    Raised when the extension was not found for an index placeholder
    """
    pass


Logger.register_error_code('index-extension-not-found', IndexExtensionNotFoundException,
                           domain='doc-tree')
Logger.register_error_code('page-not-found', PageNotFoundException,
                           domain='doc-tree')
Logger.register_warning_code('invalid-page-metadata', InvalidPageMetadata,
                             domain='doc-tree')
Logger.register_warning_code('markdown-bad-link', HotdocSourceException)


# pylint: disable=too-many-instance-attributes
class Page:
    "Banana banana"
    meta_schema = {Optional('title'): And(str, len),
                   Optional('short-description'): And(str),
                   Optional('description'): And(str),
                   Optional('render-subpages'): bool,
                   Optional('auto-sort'): bool,
"""

import re
import cgi
from itertools import izip_longest


from hotdoc.core.comment_block import (Comment, Annotation, Tag,
                                       comment_from_tag)
from hotdoc.core.exceptions import HotdocSourceException
from hotdoc.utils.configurable import Configurable
from hotdoc.parsers import cmark
from hotdoc.utils.loggable import Logger, warn


Logger.register_warning_code('gtk-doc-bad-link', HotdocSourceException)
Logger.register_warning_code('gtk-doc-bad-syntax', HotdocSourceException)


# http://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks
def _grouper(iterable, n_args, fillvalue=None):
    """
    Banana banana
    """
    args = [iter(iterable)] * n_args
    return izip_longest(*args, fillvalue=fillvalue)


# pylint: disable=too-few-public-methods
class GtkDocParser(object):
    """
from hotdoc.core.symbols import *
from hotdoc.core.base_extension import BaseExtension, ExtDependency
from hotdoc.core.base_formatter import Formatter
from hotdoc.core.file_includer import find_md_file
from hotdoc.core.links import Link, LinkResolver
from hotdoc.core.doc_tree import Page
from hotdoc.core.comment_block import Comment
from hotdoc.core.exceptions import BadInclusionException
from hotdoc.utils.loggable import warn, Logger

from .gi_html_formatter import GIHtmlFormatter
from .gi_annotation_parser import GIAnnotationParser
from .fundamentals import PY_FUNDAMENTALS, JS_FUNDAMENTALS


Logger.register_warning_code('missing-gir-include', BadInclusionException,
                             'gi-extension')


class Flag (object):
    def __init__ (self, nick, link):
        self.nick = nick
        self.link = link


class RunLastFlag (Flag):
    def __init__(self):
        Flag.__init__ (self, "Run Last",
                "https://developer.gnome.org/gobject/unstable/gobject-Signals.html#G-SIGNAL-RUN-LAST:CAPS")


class RunFirstFlag (Flag):
Exemple #28
0
yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
                     _no_duplicates_constructor)
yaml.add_constructor(u'tag:yaml.org,2002:str',
                     _custom_str_constructor)


class DocTreeNoSuchPageException(HotdocSourceException):
    """
    Raised when a subpage listed in the sitemap file could not be found
    in any of the include paths.
    """
    pass


Logger.register_error_code('no-such-subpage', DocTreeNoSuchPageException,
                           domain='doc-tree')
Logger.register_warning_code('invalid-page-metadata', InvalidPageMetadata,
                             domain='doc-tree')
Logger.register_warning_code('markdown-bad-link', HotdocSourceException)


# pylint: disable=too-many-instance-attributes
class Page(object):
    "Banana banana"
    meta_schema = {Optional('title'): And(unicode, len),
                   Optional('symbols'): Schema([And(unicode, len)]),
                   Optional('short-description'): And(unicode, len)}

    resolving_symbol_signal = Signal()
    formatting_signal = Signal()
Exemple #29
0
 def test_ignore_warning(self):
     Logger.add_ignored_code('baz')
     Logger.warn('baz', 'This baz is bad but I do not care')
     self.assertListEqual(Logger.journal, [])
from docutils.core import publish_parts
from docutils.utils import error_reporting
from docutils import nodes
from hotdoc.core.comment_block import Comment
from hotdoc.core.exceptions import HotdocSourceException
from hotdoc.utils.loggable import Logger, warn
from docutils.statemachine import ViewList
from docutils.writers.html4css1 import Writer as HtmlWriter
from docutils.parsers.rst import roles, directives
from xml.sax.saxutils import unescape

from hotdoc_python_extension.napoleon import Config
from hotdoc_python_extension.napoleon import docstring


Logger.register_warning_code('python-doc-issue', HotdocSourceException)


_google_typed_arg_regex = re.compile(r'\s*(.+?)\s*\(\s*(.+?)\s*\)')

class MyGoogleDocString(docstring.GoogleDocstring):
    def __init__(self, *args, **kwargs):
        self.param_fields = []
        self.attribute_fields = []
        self.return_fields = []
        docstring.GoogleDocstring.__init__(self, *args, **kwargs)

    def _consume_field(self, parse_type=True, prefer_type=False):
        line = next(self._line_iter)

        before, colon, after = self._partition_field_on_colon(line)
Exemple #31
0
import os
from collections import defaultdict
from lxml import etree
import networkx as nx
from hotdoc.core.symbols import QualifiedSymbol
from hotdoc.core.exceptions import BadInclusionException
from hotdoc.extensions.gi.utils import *
from hotdoc.extensions.gi.fundamentals import FUNDAMENTALS
from hotdoc.utils.loggable import warn, Logger

Logger.register_warning_code('missing-gir-include', BadInclusionException,
                             'gi-extension')
'''
Names of boilerplate GObject macros we don't want to expose
'''
SMART_FILTERS = set()


def __generate_smart_filters(id_prefixes, sym_prefixes, node):
    sym_prefix = node.attrib['{%s}symbol-prefix' % NS_MAP['c']]
    SMART_FILTERS.add(('%s_IS_%s' % (sym_prefixes, sym_prefix)).upper())
    SMART_FILTERS.add(('%s_TYPE_%s' % (sym_prefixes, sym_prefix)).upper())
    SMART_FILTERS.add(('%s_%s' % (sym_prefixes, sym_prefix)).upper())
    SMART_FILTERS.add(('%s_%s_CLASS' % (sym_prefixes, sym_prefix)).upper())
    SMART_FILTERS.add(('%s_IS_%s_CLASS' % (sym_prefixes, sym_prefix)).upper())
    SMART_FILTERS.add(('%s_%s_GET_CLASS' % (sym_prefixes, sym_prefix)).upper())
    SMART_FILTERS.add(('%s_%s_GET_IFACE' % (sym_prefixes, sym_prefix)).upper())


__HIERARCHY_GRAPH = nx.DiGraph()
Exemple #32
0
from hotdoc.core.base_extension import BaseExtension
from hotdoc.core.base_formatter import Formatter
from hotdoc.core.doc_tree import Page
from hotdoc.core.exceptions import HotdocException
from hotdoc.utils.loggable import error, warn, Logger


class NoSuchLicenseException(HotdocException):
    """
    Raised when an unknown license is used
    """
    pass


Logger.register_error_code('no-such-license', NoSuchLicenseException,
                           domain='license-extension')


DESCRIPTION=\
"""
This extension helps licensing your hotdoc project
"""


HERE = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.join(HERE, 'data')


base_copyright_schema = {'name': And(unicode, len),
                         Optional('email'): And(unicode, len),
                         Optional('years'): Schema([Use(int)])}
Exemple #33
0
Utilities and baseclasses for extensions
"""
import os
from collections import OrderedDict
from collections import defaultdict

from hotdoc.core.inclusions import find_file
from hotdoc.core.symbols import Symbol
from hotdoc.core.tree import Page, OverridePage, PageResolutionResult
from hotdoc.core.formatter import Formatter
from hotdoc.utils.configurable import Configurable
from hotdoc.core.exceptions import InvalidOutputException
from hotdoc.utils.loggable import debug, info, warn, error, Logger
from hotdoc.utils.utils import OrderedSet, DefaultOrderedDict

Logger.register_warning_code('unavailable-symbol-listed',
                             InvalidOutputException, 'extension')


# pylint: disable=too-few-public-methods
class ExtDependency:
    """
    Represents a dependency on another extension.

    If not satisfied, the extension will not be instantiated.

    See the `Extension.get_dependencies` static method documentation
    for more information.

    Attributes:
        dependency_name: str, the name of the extension depended on.
        is_upstream: bool, if set to true hotdoc will arrange for
Exemple #34
0
import re

from hotdoc.core.exceptions import HotdocSourceException
from hotdoc.core.extension import Extension
from hotdoc.core.tree import Page
from hotdoc.core.project import Project
from hotdoc.run_hotdoc import Application
from hotdoc.core.formatter import Formatter
from hotdoc.utils.loggable import Logger, warn, info

import typing as T

if T.TYPE_CHECKING:
    import argparse

Logger.register_warning_code('unknown-refman-link', HotdocSourceException,
                             'refman-links')


class RefmanLinksExtension(Extension):
    extension_name = 'refman-links'
    argument_prefix = 'refman'

    def __init__(self, app: Application, project: Project):
        self.project: Project
        super().__init__(app, project)
        self._data_file: T.Optional[Path] = None
        self._data: T.Dict[str, str] = {}

    @staticmethod
    def add_arguments(parser: 'argparse.ArgumentParser'):
        group = parser.add_argument_group(
Exemple #35
0
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:hotdoc="uri:hotdoc">
    <xsl:variable name="subpages" select="hotdoc:subpages()" />
    <xsl:template match="subpages">
        <xsl:apply-templates select="$subpages" />
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>''')

Logger.register_warning_code('bad-local-link',
                             FormatterBadLinkException,
                             domain='html-formatter')
Logger.register_warning_code('no-image-src',
                             FormatterBadLinkException,
                             domain='html-formatter')
Logger.register_warning_code('bad-image-src',
                             FormatterBadLinkException,
                             domain='html-formatter')
Logger.register_warning_code('download-theme-error',
                             HotdocException,
                             domain='html-formatter')

HERE = os.path.dirname(__file__)


def _download_progress_cb(blocknum, blocksize, totalsize):
Exemple #36
0
 def test_ignore_domain(self):
     Logger.add_ignored_domain('bar')
     Logger.warn('baz', 'This baz is bad but I do not care')
     self.assertListEqual(Logger.journal, [])
     with self.assertRaises(FooError):
         Logger.error('foo', 'This foo is bad I need to care')
Exemple #37
0
from hotdoc.utils.loggable import info, Logger, error
from hotdoc.utils.utils import OrderedSet
from hotdoc.core.extension import Extension
from hotdoc.core.symbols import ClassSymbol, QualifiedSymbol, PropertySymbol, \
    SignalSymbol, ReturnItemSymbol, ParameterSymbol, Symbol
from hotdoc.parsers.gtk_doc import GtkDocParser
from hotdoc.extensions.c.utils import CCommentExtractor
from hotdoc.core.exceptions import HotdocSourceException
from hotdoc.core.formatter import Formatter
from hotdoc.core.comment import Comment
from hotdoc.extensions.gi.gi_extension import WritableFlag, ReadableFlag, \
    ConstructFlag, ConstructOnlyFlag
from hotdoc.extensions.gi.gtkdoc_links import gather_gtk_doc_links
from hotdoc.extensions.devhelp.devhelp_extension import TYPE_MAP

Logger.register_warning_code('signal-arguments-mismatch',
                             HotdocSourceException, 'gst-extension')

DESCRIPTION =\
    """
Extract gstreamer plugin documentation from sources and
built plugins.
"""


def _cleanup_package_name(package_name):
    return package_name.strip('git').strip('release').strip(
        'prerelease').strip('GStreamer').strip('Plug-ins').strip(' ')


def create_hierarchy(element_dict):
Exemple #38
0
 def test_unknown_codes(self):
     with self.assertRaises(AssertionError):
         Logger.warn('does-not-exist', 'Should not exist')
     with self.assertRaises(AssertionError):
         Logger.error('does-not-exist', 'Should not exist')
Exemple #39
0
from hotdoc.core.formatter import Formatter
from hotdoc.utils.configurable import Configurable
from hotdoc.core.exceptions import InvalidPageMetadata, InvalidOutputException
from hotdoc.utils.loggable import debug, info, warn, error, Logger
from hotdoc.utils.utils import OrderedSet, DefaultOrderedDict


class SymbolListedTwiceException(InvalidPageMetadata):
    pass


class InvalidRelocatedSourceException(InvalidPageMetadata):
    pass


Logger.register_warning_code(
    'unavailable-symbol-listed', InvalidOutputException, 'extension')
Logger.register_warning_code(
    'output-page-conflict', InvalidOutputException, 'extension')
Logger.register_warning_code(
    'symbol-listed-twice', SymbolListedTwiceException, 'extension')
Logger.register_warning_code(
    'invalid-relocated-source', InvalidRelocatedSourceException, 'extension')


# pylint: disable=too-few-public-methods
class ExtDependency:
    """
    Represents a dependency on another extension.

    If not satisfied, the extension will not be instantiated.
Exemple #40
0
yaml.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
                     _no_duplicates_constructor)
yaml.add_constructor(u'tag:yaml.org,2002:str',
                     _custom_str_constructor)


class DocTreeNoSuchPageException(HotdocSourceException):
    """
    Raised when a subpage listed in the sitemap file could not be found
    in any of the include paths.
    """
    pass


Logger.register_error_code('no-such-subpage', DocTreeNoSuchPageException,
                           domain='doc-tree')
Logger.register_error_code('invalid-page-metadata', InvalidPageMetadata,
                           domain='doc-tree')


# pylint: disable=too-many-instance-attributes
class Page(object):
    "Banana banana"
    meta_schema = {Optional('title'): And(unicode, len),
                   Optional('symbols'): Schema([And(unicode, len)]),
                   Optional('short-description'): And(unicode, len)}

    resolving_symbol_signal = Signal()
    formatting_signal = Signal()

    def __init__(self, source_file, ast, meta=None, raw_contents=None):
    if ast_node.kind == clang.cindex.TypeKind.POINTER and \
            ast_node.get_pointee().get_result().kind != \
            clang.cindex.TypeKind.INVALID:
        return True
    return False


def info(message):
    core_info(message, domain='c-extension')


def debug(message):
    core_debug(message, domain='c-extension')


Logger.register_warning_code('clang-diagnostic', ParsingException,
                             'c-extension')
Logger.register_warning_code('clang-heisenbug', ParsingException,
                             'c-extension')
Logger.register_warning_code('clang-flags', ParsingException,
                             'c-extension')
Logger.register_warning_code('bad-c-inclusion', BadInclusionException,
                             'c-extension')
Logger.register_warning_code('clang-headers-not-found', HotdocException,
                             'c-extension')


CLANG_HEADERS_WARNING = (
'Did not find clang headers. Please report a bug with the output of the'
'\'llvm-config --version\' and \'llvm-config --prefix\' commands')

Exemple #42
0
from lxml import etree
import lxml.html

from hotdoc.core.exceptions import InvalidOutputException
from hotdoc.utils.loggable import info as core_info, Logger

from hotdoc.extensions.search.trie import Trie
from hotdoc.utils.utils import OrderedSet


def info(message):
    core_info(message, domain='search-extension')


Logger.register_warning_code('invalid-html', InvalidOutputException,
                             'search-extension')

SECTIONS_SELECTOR = ('./div[@id]')

INITIAL_SELECTOR = ('.//div[@id="main"]')

TITLE_SELECTOR = ('./h1|h2|h2|h3|h4|h5|h6')

TOK_REGEX = re.compile(r'[a-zA-Z_][a-zA-Z0-9_\.]*[a-zA-Z0-9_]*')


def get_sections(root, selector='./div[@id]'):
    return root.xpath(selector)


def parse_content(section, stop_words, selector='.//p'):
Exemple #43
0
def run(args, verbose=False):
    """
    Banana banana
    """

    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter, add_help=False)
    parser.add_argument("--extra-extension-path",
                        action="append",
                        default=[],
                        dest="extra_extension_path",
                        help="An extra extension path to use")
    parser.add_argument('--conf-file',
                        help='Path to the config file',
                        dest='conf_file')
    tmpargs, _args = parser.parse_known_args(args)

    json_conf = None
    if tmpargs.conf_file:
        json_conf = load_config_json(tmpargs.conf_file)
        tmpargs.extra_extension_path += json_conf.get('extra_extension_path',
                                                      [])

    # We only get these once, doing this now means all
    # installed extensions will show up as Configurable subclasses.
    try:
        ext_classes = get_extension_classes(
            sort=True, extra_extension_paths=tmpargs.extra_extension_path)
    except HotdocException:
        return 1

    parser.add_argument('command',
                        action="store",
                        choices=('run', 'conf', 'init', 'help'),
                        nargs="?")
    parser.add_argument('--output-conf-file',
                        help='Path where to save the updated conf'
                        ' file',
                        dest='output_conf_file')
    parser.add_argument('--init-dir',
                        help='Directory to initialize',
                        dest='init_dir')
    parser.add_argument('--version',
                        help="Print version and exit",
                        action="store_true")
    parser.add_argument('--makefile-path',
                        help="Print path to includable "
                        "Makefile and exit",
                        action="store_true")
    parser.add_argument("--get-conf-key",
                        action="store",
                        help="print the value for a configuration "
                        "key")
    parser.add_argument("--get-conf-path",
                        action="store",
                        help="print the value for a configuration "
                        "path")
    parser.add_argument("--get-private-folder",
                        action="store_true",
                        help="get the path to hotdoc's private "
                        "folder")
    parser.add_argument("--has-extension",
                        action="append",
                        dest="has_extensions",
                        default=[],
                        help="Check if a given extension is available")
    parser.add_argument("--list-extensions",
                        action="store_true",
                        dest="list_extensions",
                        help="Print "
                        "available extensions")
    parser.add_argument("-",
                        action="store_true",
                        help="Separator to allow finishing a list"
                        " of arguments before a command",
                        dest="whatever")

    add_args_methods = set()

    for klass in all_subclasses(Configurable):
        if klass.add_arguments not in add_args_methods:
            klass.add_arguments(parser)
            add_args_methods.add(klass.add_arguments)

    known_args, _ = parser.parse_known_args(args)

    defaults = {}
    actual_args = {}
    for key, value in list(dict(vars(known_args)).items()):
        if value != parser.get_default(key):
            actual_args[key] = value
        if parser.get_default(key) is not None:
            defaults[key] = value

    if known_args.has_extensions:
        res = 0
        for extension_name in known_args.has_extensions:
            found = False
            for klass in ext_classes:
                if klass.extension_name == extension_name:
                    found = True
                    if verbose:
                        print("Extension '%s'... FOUND." % extension_name)
            if not found:
                if verbose:
                    print("Extension '%s'... NOT FOUND." % extension_name)
                res = 1
        return res

    if known_args.list_extensions:
        print("Extensions:")
        extensions = [e.extension_name for e in ext_classes]
        for extension in sorted(extensions):
            print(" - %s " % extension)
        return 0

    if known_args.command != 'init':
        conf_file = actual_args.get('conf_file')
        if conf_file is None and os.path.exists('hotdoc.json'):
            conf_file = 'hotdoc.json'
    else:
        conf_file = ''

    config = Config(command_line_args=actual_args,
                    conf_file=conf_file,
                    defaults=defaults,
                    json_conf=json_conf)

    Logger.parse_config(config)

    return execute_command(parser, config, ext_classes)
Exemple #44
0
class SitemapDuplicateError(HotdocSourceException):
    """
    Raised when the same file was listed multiple times in
    a sitemap file.
    """
    pass


class SitemapError(HotdocSourceException):
    """
    Generic sitemap error.
    """
    pass


Logger.register_error_code('bad-indent', IndentError, domain='sitemap')
Logger.register_error_code('sitemap-duplicate',
                           SitemapDuplicateError,
                           domain='sitemap')
Logger.register_error_code('sitemap-error', SitemapError, domain='sitemap')


# pylint: disable=too-few-public-methods
class StandaloneParser(object):
    """
    Banana banana
    """
    pass


class Sitemap(object):
Exemple #45
0
"""GitUploadExtension"""

import os
import shutil
import subprocess
from subprocess import check_output as call
import urllib.parse

import appdirs
from hotdoc.utils.utils import recursive_overwrite
from hotdoc.core.extension import Extension
from hotdoc.core.exceptions import HotdocException
from hotdoc.utils.loggable import Logger, warn

Logger.register_warning_code('no-local-repository',
                             HotdocException,
                             domain='git-uploader')
Logger.register_warning_code('dirty-local-repository',
                             HotdocException,
                             domain='git-uploader')
Logger.register_warning_code('git-error',
                             HotdocException,
                             domain='git-uploader')

DESCRIPTION =\
    """
An extension to upload the result of a hotdoc build
to git a repository.

It can be used to upload to github pages for example.
"""
Exemple #46
0
 def test_ignore_domain(self):
     Logger.add_ignored_domain('bar')
     Logger.warn('baz', 'This baz is bad but I do not care')
     self.assertListEqual(Logger.journal, [])
     with self.assertRaises(FooError):
         Logger.error('foo', 'This foo is bad I need to care')
Exemple #47
0
    if ast_node.kind == cindex.TypeKind.POINTER and \
            ast_node.get_pointee().get_result().kind != \
            cindex.TypeKind.INVALID:
        return True
    return False


def info(message):
    core_info(message, domain='c-extension')


def debug(message):
    core_debug(message, domain='c-extension')


Logger.register_warning_code('clang-diagnostic', ParsingException,
                             'c-extension')
Logger.register_warning_code('clang-heisenbug', ParsingException,
                             'c-extension')
Logger.register_warning_code('clang-flags', ParsingException, 'c-extension')
Logger.register_warning_code('bad-c-inclusion', BadInclusionException,
                             'c-extension')
Logger.register_warning_code('clang-headers-not-found', HotdocException,
                             'c-extension')

CLANG_HEADERS_WARNING = (
    'Did not find clang headers. Please report a bug with the output of the'
    '\'llvm-config --version\' and \'llvm-config --prefix\' commands')


def get_clang_headers():
    version = subprocess.check_output(['llvm-config',
Exemple #48
0
 def setUp(self):
     Logger.reset()
     Logger.silent = True
     Logger.register_error_code('foo', FooError, 'bar')
     Logger.register_warning_code('baz', BazError, 'bar')
Exemple #49
0
# pylint: disable=missing-docstring

import json
from hotdoc.core.exceptions import HotdocSourceException
from hotdoc.utils.loggable import Logger, warn
from hotdoc.core.extension import Extension

DESCRIPTION =\
    """
This extension allows to warn about missing `Since` markers in newly added
API.
"""


Logger.register_warning_code('missing-since-marker', HotdocSourceException,
                             'check-missing-since-markers')


class CheckMissingSinceMarkersExtension(Extension):
    extension_name = 'check-missing-since-markers'

    def __init__(self, app, project):
        Extension.__init__(self, app, project)
        self.__symbols_database = None

    @staticmethod
    def add_arguments(parser):
        group = parser.add_argument_group('since-markers-check-extension',
                                          DESCRIPTION)
        group.add_argument("--previous-symbol-index")
Exemple #50
0
from lxml import etree
import lxml.html
from collections import defaultdict

from hotdoc.core.exceptions import InvalidOutputException
from hotdoc.utils.loggable import info as core_info, warn, Logger

from hotdoc.extensions.search.trie import Trie
from hotdoc.utils.utils import OrderedSet


def info(message):
    core_info(message, domain='search-extension')

Logger.register_warning_code('invalid-html', InvalidOutputException,
                             'search-extension')

SECTIONS_SELECTOR=(
'./div[@id]'
)

INITIAL_SELECTOR=(
'.//div[@id="main"]'
)

TITLE_SELECTOR=(
'./ul[@class="base_symbol_header"]'
'/li'
'/h3'
'/span'
'/code'