[gtk-doc] python: add a gtkdoc python module



commit 426ff219aae58bcf9ddcbf8d1dfc6f7ec7401270
Author: Stefan Sauer <ensonic users sf net>
Date:   Thu Mar 30 19:54:25 2017 +0200

    python: add a gtkdoc python module
    
    Add a config.py there which will take constants from the build such as
    paths and versions. Move the main code of gtkdoc-check into the module
    and turn the gtkdoc-check into a trivial starter loading this module.

 Makefile.am         |   15 +++++-
 configure.ac        |    5 ++-
 gtkdoc-check.in     |  107 ++------------------------------------------
 gtkdoc/check.py     |  122 +++++++++++++++++++++++++++++++++++++++++++++++++++
 gtkdoc/config.py.in |    1 +
 tests/Makefile.am   |    1 +
 6 files changed, 145 insertions(+), 106 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index f1c1e9f..75e8373 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,6 +34,12 @@ gtkdocdata_DATA = \
        style/up-insensitive.png                \
        style/style.css
 
+pylibdatadir = $(datadir)/gtk-doc/python/gtkdoc
+pylibdata_DATA = \
+  gtkdoc/__init__.py \
+  gtkdoc/check.py \
+  gtkdoc/config.py
+
 pkgconfigdir = $(datadir)/pkgconfig
 pkgconfig_DATA = gtk-doc.pc
 
@@ -69,7 +75,10 @@ CLEANFILES = \
   gtkdoc-mkhtmlc \
   gtkdoc-mkmanc \
   gtkdoc-mkpdfc \
-  gtkdoc-rebasec
+  gtkdoc-rebasec \
+  gtkdoc/__init__.pyc \
+  gtkdoc/check.pyc \
+  gtkdoc/config.pyc
 
 DISTCLEANFILES = \
   gtkdoc-check \
@@ -84,8 +93,8 @@ DISTCLEANFILES = \
   gtk-doc.pc \
   gtkdoc-rebase \
   gtkdoc-scangobj \
-  gtkdoc-scan
-
+  gtkdoc-scan \
+  gtkdoc/config.py
 
 MAINTAINERCLEANFILES = \
        $(GITIGNORE_MAINTAINERCLEANFILES_TOPLEVEL) \
diff --git a/configure.ac b/configure.ac
index 1f42386..e74e4f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -136,7 +136,7 @@ fi
 AC_SUBST([HIGHLIGHT_OPTIONS])
 
 dnl
-dnl Set PACKAGE_DATA_DIR so we can find the script containing common routines.
+dnl Set runtime package dirs so we can find the script containing common routines.
 dnl
 dnl From Autoconf Macro Archive:
 m4_define([AC_DEFINE_DIR], [
@@ -152,6 +152,8 @@ m4_define([AC_DEFINE_DIR], [
 ])
 PACKAGE_DATA_DIR="${datadir}/${PACKAGE}/data"
 AC_DEFINE_DIR([PACKAGE_DATA_DIR], [PACKAGE_DATA_DIR])
+PYTHON_PACKAGE_DIR="${datadir}/${PACKAGE}/python"
+AC_DEFINE_DIR([PYTHON_PACKAGE_DIR], [PYTHON_PACKAGE_DIR])
 
 dnl Only use -Wall if we have gcc
 if test "x$GCC" = "xyes"; then
@@ -239,6 +241,7 @@ gtkdoc-common.pl
 cmake/Makefile
 cmake/GtkDocConfig.cmake
 cmake/GtkDocConfigVersion.cmake
+gtkdoc/config.py
 help/Makefile
 help/manual/Makefile
 tests/Makefile
diff --git a/gtkdoc-check.in b/gtkdoc-check.in
index 40d1e5a..9db50fb 100755
--- a/gtkdoc-check.in
+++ b/gtkdoc-check.in
@@ -5,7 +5,7 @@
 # Copyright (C) 2007  David Nečas
 #               2007-2017  Stefan Sauer
 #
-# This program is free scperlonoftware; you can redistribute it and/or modify
+# This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.
@@ -20,107 +20,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 
-#############################################################################
-# Script      : gtkdoc-check
-# Description : Runs various checks on built documentation and outputs test
-#                results. Can be run druring make check, by adding this to the
-#                documentations Makefile.am: TESTS = $(GTKDOC_CHECK)
-#############################################################################
-
-# Support both Python 2 and 3
-from __future__ import print_function
-
-import os, re, sys, argparse, subprocess
-from glob import glob
-
-
-def grep(regexp, filename, what):
-    pattern = re.compile(regexp)
-    with open(filename) as f:
-        for line in f:
-            for match in re.finditer(pattern, line):
-                return match.group(1)
-    sys.exit("Cannot find %s in %s" % (what, filename));
-
-
-def check_empty(filename, what):
-    with open(filename) as f:
-        count = sum(1 for line in f if line.strip())
-        if count:
-            print("%s:1:E: %d %st\n" % (filename, count, what))
-            return count
-    return 0
-
-
-def check_includes(filename):
-    # Check that each XML file in the xml directory is included in doc_main_file
-    with open(filename) as f:
-        lines = f.read().splitlines()
-        num_missing = 0;
-        for include in glob('xml/*.xml'):
-            try:
-                next(line for line in lines if include in line)
-            except StopIteration:
-                num_missing += 1;
-                print('% doesn\'t appear to include "%s"' % (filename, xml_file))
-
-    return num_missing
-
-
-def run():
-    checks = 4
-
-    parser = argparse.ArgumentParser(description='gtkdoc-check version @VERSION@ - run documentation unit 
tests')
-    parser.add_argument('--version', action='version', version='@VERSION@')
-    parser.parse_args()
-
-    # Get parameters from test env, if not there try to grab them from the makefile
-    # We like Makefile.am more but builddir does not necessarily contain one.
-    makefile = 'Makefile.am'
-    if not os.path.exists(makefile):
-        makefile = 'Makefile'
-
-    # For historic reasons tests are launched in srcdir
-    srcdir = os.environ.get('SRCDIR', None)
-    builddir = os.environ.get('BUILDDIR', None)
-    workdir = '.'
-    if builddir:
-        workdir = builddir
-
-    doc_module = os.environ.get('DOC_MODULE', None)
-    if not doc_module:
-        doc_module = grep(r'^\s*DOC_MODULE\s*=\s*(\S+)', makefile, 'DOC_MODULE')
-
-    doc_main_file = os.environ.get('DOC_MAIN_SGML_FILE', None)
-    if not doc_main_file:
-        doc_main_file = grep(r'^\s*DOC_MAIN_SGML_FILE\s*=\s*(\S+)', makefile, 'DOC_MAIN_SGML_FILE')
-        doc_main_file = doc_main_file.replace('$(DOC_MODULE)', doc_module)
-
-
-    print('Running suite(s): gtk-doc-doc_module')
-
-    undocumented = int(grep(r'^(\d+)\s+not\s+documented\.\s*$',
-                            os.path.join(workdir, doc_module + '-undocumented.txt'),
-                            'number of undocumented symbols'))
-    incomplete = int(grep(r'^(\d+)\s+symbols?\s+incomplete\.\s*$',
-                          os.path.join(workdir, doc_module + '-undocumented.txt'),
-                          'number of incomplete symbols'))
-    total = undocumented + incomplete
-    if total:
-        print('doc_module-undocumented.txt:1:E: %d undocumented or incomplete symbols' % total)
-
-    undeclared = check_empty(os.path.join(workdir, doc_module + '-undeclared.txt'),
-                             'undeclared symbols')
-    unused = check_empty(os.path.join(workdir, doc_module + '-unused.txt'),
-                         'unused documentation entries')
-
-    missing_includes = check_includes(os.path.join(workdir, doc_main_file))
-
-    failed = (total > 0) + (undeclared != 0) + (unused != 0) + (missing_includes != 0)
-    rate = 100.0 * (checks - failed) / checks
-    print("%.1f%%: Checks %d, Failures: %d" % (rate, checks, failed))
-    sys.exit(failed != 0)
+import sys
+sys.path.append('@PYTHON_PACKAGE_DIR@')
 
+from gtkdoc import check
 
 if __name__== '__main__':
-    run()
+    sys.exit(check.run() != 0)
diff --git a/gtkdoc/__init__.py b/gtkdoc/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/gtkdoc/check.py b/gtkdoc/check.py
new file mode 100755
index 0000000..3f58634
--- /dev/null
+++ b/gtkdoc/check.py
@@ -0,0 +1,122 @@
+# -*- python; coding: utf-8 -*-
+#
+# gtk-doc - GTK DocBook documentation generator.
+# Copyright (C) 2007  David Nečas
+#               2007-2017  Stefan Sauer
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#############################################################################
+# Script      : gtkdoc-check
+# Description : Runs various checks on built documentation and outputs test
+#                results. Can be run druring make check, by adding this to the
+#                documentations Makefile.am: TESTS = $(GTKDOC_CHECK)
+#############################################################################
+
+# Support both Python 2 and 3
+from __future__ import print_function
+
+import os, re, sys, argparse, subprocess
+from glob import glob
+
+from . import config
+
+
+def grep(regexp, filename, what):
+    pattern = re.compile(regexp)
+    with open(filename) as f:
+        for line in f:
+            for match in re.finditer(pattern, line):
+                return match.group(1)
+    sys.exit("Cannot find %s in %s" % (what, filename));
+
+
+def check_empty(filename, what):
+    with open(filename) as f:
+        count = sum(1 for line in f if line.strip())
+        if count:
+            print("%s:1:E: %d %st\n" % (filename, count, what))
+            return count
+    return 0
+
+
+def check_includes(filename):
+    # Check that each XML file in the xml directory is included in doc_main_file
+    with open(filename) as f:
+        lines = f.read().splitlines()
+        num_missing = 0;
+        for include in glob('xml/*.xml'):
+            try:
+                next(line for line in lines if include in line)
+            except StopIteration:
+                num_missing += 1;
+                print('% doesn\'t appear to include "%s"' % (filename, xml_file))
+
+    return num_missing
+
+
+def run():
+    checks = 4
+
+    parser = argparse.ArgumentParser(description='gtkdoc-check version %s - run documentation unit tests' % 
config.version)
+    parser.add_argument('--version', action='version', version=config.version)
+    parser.parse_args()
+
+    # Get parameters from test env, if not there try to grab them from the makefile
+    # We like Makefile.am more but builddir does not necessarily contain one.
+    makefile = 'Makefile.am'
+    if not os.path.exists(makefile):
+        makefile = 'Makefile'
+
+    # For historic reasons tests are launched in srcdir
+    srcdir = os.environ.get('SRCDIR', None)
+    builddir = os.environ.get('BUILDDIR', None)
+    workdir = '.'
+    if builddir:
+        workdir = builddir
+
+    doc_module = os.environ.get('DOC_MODULE', None)
+    if not doc_module:
+        doc_module = grep(r'^\s*DOC_MODULE\s*=\s*(\S+)', makefile, 'DOC_MODULE')
+
+    doc_main_file = os.environ.get('DOC_MAIN_SGML_FILE', None)
+    if not doc_main_file:
+        doc_main_file = grep(r'^\s*DOC_MAIN_SGML_FILE\s*=\s*(\S+)', makefile, 'DOC_MAIN_SGML_FILE')
+        doc_main_file = doc_main_file.replace('$(DOC_MODULE)', doc_module)
+
+    print('Running suite(s): gtk-doc-doc_module')
+
+    undocumented = int(grep(r'^(\d+)\s+not\s+documented\.\s*$',
+                            os.path.join(workdir, doc_module + '-undocumented.txt'),
+                            'number of undocumented symbols'))
+    incomplete = int(grep(r'^(\d+)\s+symbols?\s+incomplete\.\s*$',
+                          os.path.join(workdir, doc_module + '-undocumented.txt'),
+                          'number of incomplete symbols'))
+    total = undocumented + incomplete
+    if total:
+        print('doc_module-undocumented.txt:1:E: %d undocumented or incomplete symbols' % total)
+
+    undeclared = check_empty(os.path.join(workdir, doc_module + '-undeclared.txt'),
+                             'undeclared symbols')
+    unused = check_empty(os.path.join(workdir, doc_module + '-unused.txt'),
+                         'unused documentation entries')
+
+    missing_includes = check_includes(os.path.join(workdir, doc_main_file))
+
+    failed = (total > 0) + (undeclared != 0) + (unused != 0) + (missing_includes != 0)
+    rate = 100.0 * (checks - failed) / checks
+    print("%.1f%%: Checks %d, Failures: %d" % (rate, checks, failed))
+    return failed
diff --git a/gtkdoc/config.py.in b/gtkdoc/config.py.in
new file mode 100644
index 0000000..4286b8f
--- /dev/null
+++ b/gtkdoc/config.py.in
@@ -0,0 +1 @@
+version = "@VERSION@"
\ No newline at end of file
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d9d289a..216c8d0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,6 +15,7 @@ TESTS_ENVIRONMENT = \
        ABS_TOP_SRCDIR=$(abs_top_srcdir) \
        PATH=$(abs_top_builddir):$(srcdir):$(PATH) \
        PERL5LIB=$(abs_top_builddir):$(PERL5LIB) \
+       PYTHONPATH=$(abs_top_builddir):${PYTHONPATH} \
        GLIB_PREFIX="$(glib_prefix)"
 
 endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]