Repository: ocr-d/core
Issue: processor wrapper fails to handle version output

Calls to `ocrd-some-processor --version` will currently end up in:
```
  File "ocrd/decorators.py", line 44, in ocrd_cli_wrap_processor
    print("Version %s, ocrd/core %s" % (p.version, OCRD_VERSION))
UnboundLocalError: local variable 'p' referenced before assignment
```

There are 2 flaws here:
1. in `ocrd_cli_wrap_processor`, the `--version` case catches any exception from the constructor, but never shows the actual error, and then goes on to use the instance regardless, cf [here](https://github.com/OCR-D/core/blob/44556e160a1b93bc1717798c8173cd7980184d2f/ocrd/ocrd/decorators.py#L42)
2. in the `Processor` base class [constructor](https://github.com/OCR-D/core/blob/44556e160a1b93bc1717798c8173cd7980184d2f/ocrd/ocrd/processor/base.py#L175), no special attention is paid to the `--version` case, hence parameter validator will be active. There can however be no parameters, so any required properties (without default) will cause an (silent) exception.

Changed files:
ocrd/ocrd/processor/base.py, ocrd/ocrd/decorators.py

diff --git a/ocrd/ocrd/decorators.py b/ocrd/ocrd/decorators.py
index ac4f41c8..424466bb 100644
--- a/ocrd/ocrd/decorators.py
+++ b/ocrd/ocrd/decorators.py
@@ -7,8 +7,6 @@ from ocrd_utils import (
     get_local_filename,
     setOverrideLogLevel,
     parse_json_string_or_file,
-
-    VERSION as OCRD_VERSION
 )
 
 from ocrd_utils import getLogger
@@ -36,11 +34,7 @@ def ocrd_cli_wrap_processor(processorClass, ocrd_tool=None, mets=None, working_d
     elif help:
         processorClass(workspace=None, show_help=True)
     elif version:
-        try:
-            p = processorClass(workspace=None)
-        except Exception: # pylint: disable=bare-except
-            pass
-        print("Version %s, ocrd/core %s" % (p.version, OCRD_VERSION))
+        processorClass(workspace=None, show_version=True)
     elif mets is None:
         msg = 'Error: Missing option "-m" / "--mets".'
         LOG.error(msg)
diff --git a/ocrd/ocrd/processor/base.py b/ocrd/ocrd/processor/base.py
index fec6e8f9..07ce2395 100644
--- a/ocrd/ocrd/processor/base.py
+++ b/ocrd/ocrd/processor/base.py
@@ -2,7 +2,7 @@ import os
 import json
 from click import wrap_text
 import subprocess
-from ocrd_utils import getLogger
+from ocrd_utils import getLogger, VERSION as OCRD_VERSION
 from ocrd_validators import ParameterValidator
 
 log = getLogger('ocrd.processor')
@@ -160,6 +160,7 @@ class Processor():
             output_file_grp="OUTPUT",
             page_id=None,
             show_help=False,
+            show_version=False,
             dump_json=False,
             version=None
     ):
@@ -173,6 +174,9 @@ class Processor():
             self.show_help()
             return
         self.version = version
+        if show_version:
+            self.show_version()
+            return
         self.workspace = workspace
         # FIXME HACK would be better to use pushd_popd(self.workspace.directory)
         # but there is no way to do that in process here since it's an
@@ -191,6 +195,9 @@ class Processor():
     def show_help(self):
         print(generate_processor_help(self.ocrd_tool))
 
+    def show_version(self):
+        print("Version %s, ocrd/core %s" % (self.version, OCRD_VERSION))
+
     def verify(self):
         """
         Verify that the input fulfills the processor's requirements.