[diffoscope] 03/05: diffoscope.tools: Make @tool_required decorator strict rather than lazy.

Chris Lamb chris at chris-lamb.co.uk
Tue Mar 28 21:40:19 CEST 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch experimental
in repository diffoscope.

commit 2213dd785be05fc0c2c818c5031b5f44d87e6afc
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Mar 28 20:24:28 2017 +0100

    diffoscope.tools: Make @tool_required decorator strict rather than lazy.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/tools.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/diffoscope/tools.py b/diffoscope/tools.py
index d03e248..66a11d3 100644
--- a/diffoscope/tools.py
+++ b/diffoscope/tools.py
@@ -52,20 +52,20 @@ def tool_required(command):
     """
     Decorator that checks if the specified tool is installed
     """
+    from .exc import RequiredToolNotFound
+
     if not hasattr(tool_required, 'all'):
         tool_required.all = set()
     tool_required.all.add(command)
-    def wrapper(original_function):
-        if find_executable(command):
-            @functools.wraps(original_function)
-            def tool_check(*args, **kwargs):
-                with profile('command', command):
-                    return original_function(*args, **kwargs)
-        else:
-            @functools.wraps(original_function)
-            def tool_check(*args, **kwargs):
-                from .exc import RequiredToolNotFound
+
+    def wrapper(fn):
+        @functools.wraps(fn)
+        def tool_check(*args, **kwargs):
+            if not find_executable(command):
                 raise RequiredToolNotFound(command)
+
+            with profile('command', command):
+                return fn(*args, **kwargs)
         return tool_check
     return wrapper
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list