How to use the hotdoc.utils.loggable.warn function in hotdoc

To help you get started, we’ve selected a few hotdoc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hotdoc / hotdoc / hotdoc / core / tree.py View on Github external
Banana banana
        """
        raw_contents = contents

        meta = {}
        if contents.startswith('---\n'):
            split = contents.split('\n...\n', 1)
            if len(split) == 2:
                contents = split[1]
                try:
                    blocks = yaml.load_all(split[0], Loader=yaml.FullLoader)
                    for block in blocks:
                        if block:
                            meta.update(block)
                except ConstructorError as exception:
                    warn('invalid-page-metadata',
                         '%s: Invalid metadata: \n%s' % (source_file,
                                                         str(exception)))

        output_path = os.path.dirname(os.path.relpath(
            source_file, next(iter(self.project.include_paths))))

        ast = cmark.hotdoc_to_ast(contents, self, source_file)
        return Page(source_file, False, self.project.sanitized_name, extension_name,
                    source_file=source_file, ast=ast, meta=meta, raw_contents=raw_contents,
                    output_path=output_path)
github hotdoc / hotdoc / hotdoc / core / tree.py View on Github external
Banana banana
        """
        raw_contents = contents

        meta = {}
        if contents.startswith('---\n'):
            split = contents.split('\n...\n', 1)
            if len(split) == 2:
                contents = split[1]
                try:
                    blocks = yaml.load_all(split[0])
                    for block in blocks:
                        if block:
                            meta.update(block)
                except ConstructorError as exception:
                    warn('invalid-page-metadata',
                         '%s: Invalid metadata: \n%s' % (source_file,
                                                         str(exception)))

        output_path = os.path.dirname(os.path.relpath(
            source_file, next(iter(self.project.include_paths))))

        ast = cmark.hotdoc_to_ast(contents, self)
        return Page(source_file, ast, output_path, self.project.sanitized_name,
                    meta=meta, raw_contents=raw_contents)
github hotdoc / hotdoc / hotdoc / extensions / git_upload / git_upload_extension.py View on Github external
stderr=subprocess.STDOUT)
        except (subprocess.CalledProcessError, FileNotFoundError):
            print("cloning %s" % repo_url)
            try:
                subprocess.check_call(['git', 'clone', repo_url, repo])
            except subprocess.CalledProcessError as exc:
                warn("git-error", "Could not clone %s in %s: %s" % (
                    repo_url, repo, exc.output))

                return None

        try:
            call(['git', 'checkout', self.__remote_branch[1]], cwd=repo,
                 stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as exc:
            warn("git-error", "Could not checkout branch %s in %s: %s" % (
                self.__remote_branch[1], repo, exc.output))
            return None

        try:
            call(['git', 'pull'], cwd=repo, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as exc:
            warn("git-error", "Could not update %s (in %s) from remote %s" % (
                repo_url, repo, exc.output))
            return None

        return os.path.join(repo, repo_path)
github hotdoc / hotdoc / hotdoc / parsers / gtk_doc.py View on Github external
return self.__parse_returns_tag(name, desc)
        if name.lower() == "return value":
            return self.__parse_returns_tag("returns", desc)
        if name.lower() == "stability":
            return self.__parse_stability_tag("stability", desc)
        if name.lower() == "deprecated":
            return self.__parse_deprecated_tag("deprecated", desc)
        if name.lower() == "topic":
            return self.__parse_topic_tag("topic", desc)

        validator = self.project.tag_validators.get(name)
        if not validator:
            warn('gtk-doc', "FIXME no tag validator")
            return None
        if not validator.validate(desc):
            warn('gtk-doc', "invalid value for tag %s : %s" % (name, desc))
            return None
        return Tag(name=name, description=desc, value=desc)
github hotdoc / hotdoc / hotdoc / extensions / edit_on_github / edit_on_github_extension.py View on Github external
def __formatting_page_cb(self, formatter, page):
        # Only allow editing markdown pages
        if page.generated:
            return

        root = self.__get_repo_root(page)
        if not root:
            warn('source-not-in-git-repo',
                 'File %s not in a git repository' % (
                     page.source_file))

        edit_link = self.__repo + '/edit/' + self.__branch + \
            '/' + os.path.relpath(page.source_file, root)

        sitename = "github" if "github" in self.__repo else "GitLab"

        page.output_attrs['html']['edit_button'] = \
            '<a data-hotdoc-role="edit-button" href="%s">' \
            'Edit on %s</a>' % (edit_link, sitename)
github hotdoc / hotdoc / hotdoc / extensions / c / c_extension.py View on Github external
if not include_path.endswith(".c") or not symbol_name:
            return None

        if not line_ranges:
            line_ranges = [(1, -1)]
        symbol = self.app.database.get_symbol(symbol_name)
        if symbol and symbol.filename != include_path:
            symbol = None

        if not symbol:
            scanner = ClangScanner(self.app, self.project, self)
            scanner.scan([include_path], self.flags, True, ['*.c', '*.h'])
            symbol = self.app.database.get_symbol(symbol_name)

            if not symbol:
                warn('bad-c-inclusion',
                     "Trying to include symbol %s but could not be found in "
                     "%s" % (symbol_name, include_path))
                return None

        res = ''
        for n, (start, end) in enumerate(line_ranges):
            if n != 0:
                res += "\n...\n"

            start += symbol.extent_start - 2
            if end > 0:
                end += (symbol.extent_start - 1)  # We are inclusive here
            else:
                end = symbol.extent_end

            with open(include_path, "r") as _:
github hotdoc / hotdoc / hotdoc / core / tree.py View on Github external
self.symbols = []
        self.typed_symbols = OrderedDict()
        self.by_parent_symbols = OrderedDict()
        self.is_stale = True
        self.formatted_contents = None
        self.detailed_description = None
        self.build_path = None
        self.project_name = project_name
        self.cached_paths = OrderedSet()

        meta = meta or {}

        try:
            self.meta = Schema(Page.meta_schema).validate(meta)
        except SchemaError as _:
            warn('invalid-page-metadata',
                 '%s: Invalid metadata: \n%s' % (self.source_file,
                                                 str(_)))
            self.meta = meta

        if not self.meta.get('extra'):
            self.meta['extra'] = defaultdict()

        self.symbol_names = OrderedSet(meta.get('symbols') or [])
        self.short_description = meta.get('short-description')
        self.render_subpages = meta.get('render-subpages', True)

        self.title = None
        self.__discover_title(meta)
        self.link = Link(pagename, self.title or name, ref)
github hotdoc / hotdoc / hotdoc / core / tree.py View on Github external
def __redirect_if_needed(self, formatter, link_resolver):
        redirect = self.meta.get("redirect")
        if not redirect:
            return False
        link = link_resolver.get_named_link(redirect)
        if link:
            if formatter.extension.project.is_toplevel:
                page_path = self.link.ref
            else:
                page_path = self.project_name + '/' + self.link.ref
            self_dir = os.path.dirname(page_path)
            if self_dir == self.link.ref:
                self_dir = ""
            self.meta["redirect"] = os.path.relpath(link.ref, self_dir)
        else:
            warn('markdown-bad-link', "Bad redirect link '%s' in page: %s"
                 % (redirect, self.name))
        return True
github hotdoc / hotdoc / hotdoc / core / formatter.py View on Github external
def __update_links(self, page, doc_root, id_nodes):
        rel_path = os.path.join(self.get_output_folder(page), page.link.ref)
        links = doc_root.xpath('.//*[@data-hotdoc-role="main"]//a')
        for link in links:
            href = link.attrib.get('href')
            if href and href.startswith('#'):
                if not link.text and not link.getchildren():
                    id_node = id_nodes.get(href.strip('#'))
                    if id_node is not None:
                        link.text = ''.join([x for x in id_node.itertext()])
                    else:
                        warn('bad-local-link',
                             "Empty anchor link to %s in %s points nowhere" %
                             (href, page.name))
                        link.text = "FIXME broken link to %s" % href
                link.attrib["href"] = rel_path + href