releasenotes: move import of fuzzywuzzy to import level
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 16 Oct 2017 22:46:11 +0530
changeset 34812 bc2caa4b4480
parent 34811 a542ad320adb
child 34813 288fad8c55f9
releasenotes: move import of fuzzywuzzy to import level This will help us in determining easily that whether fuzzywuzzy is loaded or not loaded in any of the function. Differential Revision: https://phab.mercurial-scm.org/D1120
hgext/releasenotes.py
--- a/hgext/releasenotes.py	Sun Oct 15 20:31:44 2017 +0530
+++ b/hgext/releasenotes.py	Mon Oct 16 22:46:11 2017 +0530
@@ -33,6 +33,12 @@
 cmdtable = {}
 command = registrar.command(cmdtable)
 
+try:
+    import fuzzywuzzy.fuzz as fuzz
+    fuzz.token_set_ratio
+except ImportError:
+    fuzz = None
+
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
@@ -219,10 +225,8 @@
     """
     Returns false when note fragment can be merged to existing notes.
     """
-    try:
-        import fuzzywuzzy.fuzz as fuzz
-        fuzz.token_set_ratio
-    except ImportError:
+    # fuzzywuzzy not present
+    if not fuzz:
         return True
 
     merge = True