Patchwork D1120: releasenotes: move import of fuzzywuzzy to import level

login
register
mail settings
Submitter phabricator
Date Oct. 16, 2017, 6:28 p.m.
Message ID <differential-rev-PHID-DREV-uyifbvkheyicpvgrp2fn-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/25026/
State Superseded
Headers show

Comments

phabricator - Oct. 16, 2017, 6:28 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This will help us in determining easily that whether fuzzywuzzy is loaded or not
  loaded in any of the function.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1120

AFFECTED FILES
  hgext/releasenotes.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/releasenotes.py b/hgext/releasenotes.py
--- a/hgext/releasenotes.py
+++ b/hgext/releasenotes.py
@@ -32,6 +32,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
@@ -218,10 +224,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