changeset 3:9ac0ee86ec7c

Some cleanup to the recipe commands and reporters.
author cmlenz
date Sun, 22 May 2005 23:12:16 +0000
parents 3ba3fb6f0054
children 196009657e5e
files Makefile bitten/python/rep_pylint.py bitten/python/rep_trace.py bitten/python/rep_unittest.py bitten/recipe.py recipe.xml scripts/build.py setup.py
diffstat 8 files changed, 64 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,6 @@
 PYLINT_MSGS = C0101,E0201,E0213,W0103,W0704,R0921,R0923
 
-all: pylint test
+all: pylint
 
 pylint:
-	PYTHONPATH=.:../Trac/trunk pylint --parseable=y --disable-msg=$(PYLINT_MSGS) --ignore=tests bitten > build/pylint.txt
-
-#test:
-#	find . -name *.pyc | xargs rm
-#	PYTHONPATH=. trac/test.py
+	PYTHONPATH=.:../Trac/trunk pylint --parseable=y --disable-msg=$(PYLINT_MSGS) --ignore=tests bitten > build/pylint-results.txt
--- a/bitten/python/rep_pylint.py
+++ b/bitten/python/rep_pylint.py
@@ -4,20 +4,20 @@
 from elementtree import ElementTree
 from trac.core import *
 from bitten import BuildError
-from bitten.recipe import IReportPreparator
+from bitten.recipe import IReportProcessor
 
 
 _msg_re = re.compile(r'^(?P<file>.+):(?P<line>\d+): '
                      r'\[(?P<type>[A-Z])(?:, (?P<tag>[\w\.]+))?\] '
                      r'(?P<msg>.*)$')
 
-class PylintReportPreparator(Component):
-    implements(IReportPreparator)
+class PylintReportProcessor(Component):
+    implements(IReportProcessor)
 
     def get_name(self):
         return 'pylint'
 
-    def execute(self, basedir, file=None):
+    def process(self, basedir, file=None):
         assert file, 'Missing required attribute "file"'
 
         for line in open(file, 'r'):
@@ -27,4 +27,3 @@
                 if filename.startswith(basedir):
                     filename = filename[len(basedir) + 1:]
                 lineno = int(match.group('line'))
-                print filename, lineno
new file mode 100644
--- /dev/null
+++ b/bitten/python/rep_trace.py
@@ -0,0 +1,19 @@
+import os
+import re
+
+from elementtree import ElementTree
+from trac.core import *
+from bitten import BuildError
+from bitten.recipe import IReportProcessor
+
+
+class TraceReportProcessor(Component):
+    implements(IReportProcessor)
+
+    def get_name(self):
+        return 'trace'
+
+    def process(self, basedir, summary=None, coverdir=None, include=None,
+                exclude=None):
+        assert summary, 'Missing required attribute "summary"'
+        assert coverdir, 'Missing required attribute "coverdir"'
--- a/bitten/python/rep_unittest.py
+++ b/bitten/python/rep_unittest.py
@@ -4,27 +4,18 @@
 from elementtree import ElementTree
 from trac.core import *
 from bitten import BuildError
-from bitten.recipe import IReportPreparator
+from bitten.recipe import IReportProcessor
 
 
 _test_re = re.compile(r'^(?P<testname>\w+) \((?P<testcase>\d+): '
                       r'\[(?P<type>[A-Z])(?:, (?P<tag>[\w\.]+))?\] '
                       r'(?P<msg>.*)$')
 
-class PylintReportPreparator(Component):
-    implements(IReportPreparator)
+class UnittestReportProcessor(Component):
+    implements(IReportProcessor)
 
     def get_name(self):
-        return 'pylint'
-
-    def execute(self, basedir, file=None):
-        assert file, 'Missing required attribute "file"'
+        return 'unittest'
 
-        for line in open(file, 'r'):
-            match = _msg_re.search(line)
-            if match:
-                filename = match.group('file')
-                if filename.startswith(basedir):
-                    filename = filename[len(basedir) + 1:]
-                lineno = int(match.group('line'))
-                print filename, lineno
+    def process(self, basedir, file=None):
+        assert file, 'Missing required attribute "file"'
--- a/bitten/recipe.py
+++ b/bitten/recipe.py
@@ -12,12 +12,12 @@
         Return the name of the command as used in the XML file.
         """
 
-    def execute(basedir, *attrs):
+    def execute(basedir, **attrs):
         """
         """
 
 
-class IReportPreparator(Interface):
+class IReportProcessor(Interface):
 
     def get_name():
         """
@@ -42,8 +42,8 @@
 
 class RecipeExecutor(Component):
 
-    commands = ExtensionPoint(ICommandExecutor)
-    reporters = ExtensionPoint(IReportPreparator)
+    command_executors = ExtensionPoint(ICommandExecutor)
+    report_processors = ExtensionPoint(IReportProcessor)
 
     def execute(self, recipe):
         for step in recipe.tree:
@@ -51,21 +51,21 @@
             for element in step:
                 if element.tag == 'reports':
                     for report in element:
-                        reporter = self._get_reporter(report.tag)
-                        reporter.execute(basedir, **report.attrib)
+                        reporter = self._get_report_processor(report.tag)
+                        reporter.process(recipe.basedir, **report.attrib)
                 else:
-                    cmd = self._get_command(element.tag)
-                    cmd.execute(basedir, **element.attrib)
+                    cmd = self._get_command_executor(element.tag)
+                    cmd.execute(recipe.basedir, **element.attrib)
             print
 
-    def _get_command(self, name):
-        for command in self.commands:
-            if command.get_name() == name:
-                return command
+    def _get_command_executor(self, name):
+        for command_executor in self.command_executors:
+            if command_executor.get_name() == name:
+                return command_executor
         raise Exception, "Unknown command <%s>" % name
 
-    def _get_reporter(self, name):
-        for report in self.reporters:
-            if report.get_name() == name:
-                return report
-        raise Exception, "Unknown report <%s>" % name
+    def _get_report_processor(self, name):
+        for report_processor in self.report_processors:
+            if report_processor.get_name() == name:
+                return report_processor
+        raise Exception, "Unknown report type <%s>" % name
--- a/recipe.xml
+++ b/recipe.xml
@@ -5,21 +5,26 @@
         <distutils command="build"/>
     </step>
 
+    <step id="test" title="Unit tests"
+          description="Run unit tests and trace code coverage">
+        <distutils command="unittest"/>
+        <reports>
+            <unittest file="build/test-results.xml"/>
+            <trace summary="build/test-coverage.txt" coverdir="build/coverage"
+                   include="trac*" exclude="*.tests.*"/>
+        </reports>
+    </step>
+
     <step id="lint" title="Run Pylint"
           description="Run Pylint to check for bad style and potential errors">
         <make target="pylint"/>
         <reports>
-            <pylint file="build/pylint.txt"/>
+            <pylint file="build/pylint-results.txt"/>
         </reports>
     </step>
 
-    <step id="test" title="Unit tests"
-          description="Run unit tests and trace code coverage">
-        <make target="test"/>
-        <reports>
-            <unittest file="build/test-results.xml"/>
-            <trace.py dir="build/coverage" include="trac*" exclude="*.tests.*"/>
-        </reports>
+    <step id="dist" title="Package up distributions">
+        <distutils command="sdist"/>
     </step>
 
 </recipe>
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -3,7 +3,7 @@
 from trac.core import ComponentManager
 
 from bitten.recipe import Recipe, RecipeExecutor
-from bitten.python import cmd_distutils, rep_pylint
+from bitten.python import cmd_distutils, rep_pylint, rep_unittest, rep_trace
 from bitten.general import cmd_make
 
 if __name__ == '__main__':
--- a/setup.py
+++ b/setup.py
@@ -3,4 +3,6 @@
 
 setup(name='bitten', version='1.0',
       packages=['bitten', 'bitten.general', 'bitten.python'],
+      author="Christopher Lenz", author_email="cmlenz@gmx.de",
+      url="http://projects.edgewall.com/bitten/",
       cmdclass={'unittest': unittest})
Copyright (C) 2012-2017 Edgewall Software