linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Markus Heiser <markus.heiser@darmarit.de>
Cc: Jonathan Corbet <corbet@lwn.net>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	Jani Nikula <jani.nikula@intel.com>,
	Daniel Vetter <daniel.vetter@ffwll.ch>,
	Matthew Wilcox <mawilcox@microsoft.com>,
	"linux-doc @ vger . kernel . org List"
	<linux-doc@vger.kernel.org>,
	"linux-kernel @ vger . kernel . org List" 
	<linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v1 3/6] kernel-doc: add kerneldoc-lint command
Date: Wed, 25 Jan 2017 07:38:46 +0100	[thread overview]
Message-ID: <20170125063846.ylhhbcqatsis2rny@phenom.ffwll.local> (raw)
In-Reply-To: <1485287564-24205-4-git-send-email-markus.heiser@darmarit.de>

On Tue, Jan 24, 2017 at 08:52:41PM +0100, Markus Heiser wrote:
> this patch adds a command to lint kernel-doc comments.::
> 
>   scripts/kerneldoc-lint --help
> 
> The lint check include (only) kernel-doc rules described at [1]. It
> does not check against reST (sphinx-doc) markup used in the kernel-doc
> comments.  Since reST markups could include depencies to the build-
> context (e.g. open/closed refs) only a sphinx-doc build can check the
> reST markup in the context of the document it builds.
> 
> With 'kerneldoc-lint' command you can check a single file or a whole
> folder, e.g:
> 
>   scripts/kerneldoc-lint include/drm
>   ...
>   scripts/kerneldoc-lint include/media/media-device.h
> 
> The lint-implementation is a part of the parser module (kernel_doc.py).
> The comandline implementation consist only of a argument parser ('opts')
> which calls the kernel-doc parser with a 'NullTranslator'.::
> 
>    parser = kerneldoc.Parser(opts, kerneldoc.NullTranslator())
> 
> Latter is also a small example of how-to implement kernel-doc
> applications with the kernel-doc parser architecture.
> 
> [1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#writing-kernel-doc-comments
> 
> Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

Didn't we have a patch from Jani to gives us a make target doing this? I
think that'd be even neater ...
-Daniel

> ---
>  Documentation/sphinx/lint.py | 121 +++++++++++++++++++++++++++++++++++++++++++
>  scripts/kerneldoc-lint       |  11 ++++
>  2 files changed, 132 insertions(+)
>  create mode 100755 Documentation/sphinx/lint.py
>  create mode 100755 scripts/kerneldoc-lint
> 
> diff --git a/Documentation/sphinx/lint.py b/Documentation/sphinx/lint.py
> new file mode 100755
> index 0000000..5a0128f
> --- /dev/null
> +++ b/Documentation/sphinx/lint.py
> @@ -0,0 +1,121 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8; mode: python -*-
> +# pylint: disable=C0103
> +
> +u"""
> +    lint
> +    ~~~~
> +
> +    Implementation of the ``kerneldoc-lint`` command.
> +
> +    :copyright:  Copyright (C) 2016  Markus Heiser
> +    :license:    GPL Version 2, June 1991 see Linux/COPYING for details.
> +
> +    The ``kernel-doclint`` command *lints* documentation from Linux kernel's
> +    source code comments, see ``--help``::
> +
> +        $ kernel-lintdoc --help
> +
> +    .. note::
> +
> +       The kernel-lintdoc command is under construction, no stable release
> +       yet. The command-line arguments might be changed/extended in the near
> +       future."""
> +
> +# ------------------------------------------------------------------------------
> +# imports
> +# ------------------------------------------------------------------------------
> +
> +import sys
> +import argparse
> +
> +#import six
> +
> +from fspath import FSPath
> +import kernel_doc as kerneldoc
> +
> +# ------------------------------------------------------------------------------
> +# config
> +# ------------------------------------------------------------------------------
> +
> +MSG    = lambda msg: sys.__stderr__.write("INFO : %s\n" % msg)
> +ERR    = lambda msg: sys.__stderr__.write("ERROR: %s\n" % msg)
> +FATAL  = lambda msg: sys.__stderr__.write("FATAL: %s\n" % msg)
> +
> +epilog = u"""This implementation of uses the kernel-doc parser
> +from the linuxdoc extension, for detail informations read
> +http://return42.github.io/sphkerneldoc/books/kernel-doc-HOWTO"""
> +
> +# ------------------------------------------------------------------------------
> +def main():
> +# ------------------------------------------------------------------------------
> +
> +    CLI = argparse.ArgumentParser(
> +        description = ("Lint *kernel-doc* comments from source code")
> +        , epilog = epilog
> +        , formatter_class=argparse.ArgumentDefaultsHelpFormatter)
> +
> +    CLI.add_argument(
> +        "srctree"
> +        , help    = "File or folder of source code."
> +        , type    = lambda x: FSPath(x).ABSPATH)
> +
> +    CLI.add_argument(
> +        "--sloppy"
> +        , action  = "store_true"
> +        , help    = "Sloppy linting, reports only severe errors.")
> +
> +    CLI.add_argument(
> +        "--markup"
> +        , choices = ["reST", "kernel-doc"]
> +        , default = "reST"
> +        , help    = (
> +            "Markup of the comments. Change this option only if you know"
> +            " what you do. New comments must be marked up with reST!"))
> +
> +    CLI.add_argument(
> +        "--verbose", "-v"
> +        , action  = "store_true"
> +        , help    = "verbose output with log messages to stderr" )
> +
> +    CLI.add_argument(
> +        "--debug"
> +        , action  = "store_true"
> +        , help    = "debug messages to stderr" )
> +
> +    CMD = CLI.parse_args()
> +    kerneldoc.DEBUG = CMD.debug
> +    kerneldoc.VERBOSE = CMD.verbose
> +
> +    if not CMD.srctree.EXISTS:
> +        ERR("%s does not exists or is not a folder" % CMD.srctree)
> +        sys.exit(42)
> +
> +    if CMD.srctree.ISDIR:
> +        for fname in CMD.srctree.reMatchFind(r"^.*\.[ch]$"):
> +            if fname.startswith(CMD.srctree/"Documentation"):
> +                continue
> +            lintdoc_file(fname, CMD)
> +    else:
> +        fname = CMD.srctree
> +        CMD.srctree = CMD.srctree.DIRNAME
> +        lintdoc_file(fname, CMD)
> +
> +# ------------------------------------------------------------------------------
> +def lintdoc_file(fname, CMD):
> +# ------------------------------------------------------------------------------
> +
> +    fname = fname.relpath(CMD.srctree)
> +    opts = kerneldoc.ParseOptions(
> +        rel_fname       = fname
> +        , src_tree      = CMD.srctree
> +        , verbose_warn  = not (CMD.sloppy)
> +        , markup        = CMD.markup )
> +
> +    parser = kerneldoc.Parser(opts, kerneldoc.NullTranslator())
> +    try:
> +        parser.parse()
> +    except Exception: # pylint: disable=W0703
> +        FATAL("kernel-doc comments markup of %s seems buggy / can't parse" % opts.fname)
> +        return
> +
> diff --git a/scripts/kerneldoc-lint b/scripts/kerneldoc-lint
> new file mode 100755
> index 0000000..5109f7b
> --- /dev/null
> +++ b/scripts/kerneldoc-lint
> @@ -0,0 +1,11 @@
> +#!/usr/bin/python
> +
> +import sys
> +from os import path
> +
> +linuxdoc = path.abspath(path.join(path.dirname(__file__), '..'))
> +linuxdoc = path.join(linuxdoc, 'Documentation', 'sphinx')
> +sys.path.insert(0, linuxdoc)
> +
> +import lint
> +lint.main()
> -- 
> 2.7.4
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

  reply	other threads:[~2017-01-25  6:38 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 19:52 [RFC PATCH v1 0/6] pure python kernel-doc parser and more Markus Heiser
2017-01-24 19:52 ` [RFC PATCH v1 1/6] kernel-doc: pure python kernel-doc parser (preparation) Markus Heiser
2017-01-24 19:52 ` [RFC PATCH v1 2/6] kernel-doc: replace kernel-doc perl parser with a pure python one (WIP) Markus Heiser
2017-01-25  0:13   ` Jonathan Corbet
2017-01-25  6:37     ` Daniel Vetter
2017-01-25  7:37       ` Markus Heiser
2017-01-25 10:24     ` Jani Nikula
2017-01-25 10:35       ` Daniel Vetter
2017-01-25 19:07       ` Markus Heiser
2017-01-25 20:59         ` Jani Nikula
2017-01-26  9:54           ` Markus Heiser
2017-01-26 10:16             ` Jani Nikula
2017-01-26 18:50         ` Jonathan Corbet
2017-01-26 19:26           ` Jani Nikula
2017-01-27  9:46             ` Markus Heiser
2017-01-24 19:52 ` [RFC PATCH v1 3/6] kernel-doc: add kerneldoc-lint command Markus Heiser
2017-01-25  6:38   ` Daniel Vetter [this message]
2017-01-25  8:21     ` Jani Nikula
2017-01-25  9:34       ` Markus Heiser
2017-01-25 10:08         ` Jani Nikula
2017-01-24 19:52 ` [RFC PATCH v1 4/6] kernel-doc: insert TODOs on kernel-doc errors Markus Heiser
2017-01-24 19:52 ` [RFC PATCH v1 5/6] kernel-doc: add kerneldoc-src2rst command Markus Heiser
2017-01-24 19:52 ` [RFC PATCH v1 6/6] kernel-doc: add man page builder (target mandocs) Markus Heiser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170125063846.ylhhbcqatsis2rny@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=corbet@lwn.net \
    --cc=daniel.vetter@ffwll.ch \
    --cc=jani.nikula@intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markus.heiser@darmarit.de \
    --cc=mawilcox@microsoft.com \
    --cc=mchehab@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).