diff --git a/bin/doxec b/bin/doxec index fa2f5568a02ea7a61eaa6c4857ef2846f5ee5b21..c421d7a1495b0d57e71241f7f977f68f45deb893 100755 --- a/bin/doxec +++ b/bin/doxec @@ -2,6 +2,7 @@ import argparse import doxec +import sys if __name__ == "__main__": parser = argparse.ArgumentParser( @@ -14,12 +15,19 @@ if __name__ == "__main__": default="markdown", help="The syntax parser to be used for the listed files.") + parser.add_argument("--version", action="store_true", + help="Prints the version of the doxec package and exits.") + parser.add_argument("documents", metavar="DOCUMENT", nargs="+", default=[], help="A document from which the code examples should be parsed and " "executed") args = parser.parse_args() + if args.version: + print("Doxec package version: %s" % doxec.__version__) + sys.exit(0) + parser = doxec.parser[args.syntax] def monitor(op, exception): @@ -29,6 +37,9 @@ if __name__ == "__main__": print(exception, end="") print(chr(27) + "[0m") + fail_count = 0 for doc_path in args.documents: doc = doxec.Document(doc_path, syntax=parser) - doc.run(monitor=monitor) + fail_count += not doc.run(monitor=monitor) + + sys.exit(fail_count) diff --git a/doxec/__init__.py b/doxec/__init__.py index ea23cfc640997ee8e015e16f0b4f7ca7e796ba07..29eca7f14bc65c99801585ac8c1245ca199102c1 100644 --- a/doxec/__init__.py +++ b/doxec/__init__.py @@ -3,6 +3,8 @@ import abc import re import subprocess +__version__ = "0.1.1" + class TestException(Exception): """ This exception should be raised, if an operation performed tests and one @@ -310,11 +312,15 @@ class Document: is called after every iteration. The first argument of monitor is the operation object, the second argument is None or the exception that occurred. + + The method returns True on success. """ + success = True for op in self.operations: try: op.execute() except TestException as e: + success = False if callable(monitor): monitor(op, e) else: @@ -322,3 +328,4 @@ class Document: else: if callable(monitor): monitor(op, None) + return success diff --git a/setup.py b/setup.py index 2c7f1f5eabaaa58b00eef9f3994d5eb704265469..abd8850e4c91bb9f3d3e788f5b731fbb3229b92d 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name="doxec", - version= "0.1.0", + version= "0.1.1", author="Frank Sauerburger", author_email= "frank@sauerburger.com", description=("Run documentation and test whether the examples work."),