changeset 6274:2ae737b2dbdc

lib: move get_custom_lexer from utils to pygmentsutils get_custom_lexer is the only dependency from helpers to utils. In attempting to get a clearer dependency tree, we can move out get_custom_lexer to a different place so that helpers does not depend on utils. It so happens that there already is a pygmentsutils.py file in lib, which is a very good fit, since the lexers used in Kallithea are effectively provided by pygments.
author Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
date Sun, 09 Oct 2016 21:42:11 +0200
parents ecd0d34bc20c
children 84099c5e0920
files kallithea/lib/annotate.py kallithea/lib/helpers.py kallithea/lib/pygmentsutils.py kallithea/lib/utils.py
diffstat 4 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/annotate.py	Sun Oct 09 21:08:18 2016 +0200
+++ b/kallithea/lib/annotate.py	Sun Oct 09 21:42:11 2016 +0200
@@ -48,7 +48,7 @@
     :param headers: dictionary with headers (keys are whats in ``order``
       parameter)
     """
-    from kallithea.lib.utils import get_custom_lexer
+    from kallithea.lib.pygmentsutils import get_custom_lexer
     options['linenos'] = True
     formatter = AnnotateHtmlFormatter(filenode=filenode, order=order,
         headers=headers,
--- a/kallithea/lib/helpers.py	Sun Oct 09 21:08:18 2016 +0200
+++ b/kallithea/lib/helpers.py	Sun Oct 09 21:42:11 2016 +0200
@@ -41,7 +41,7 @@
 
 from kallithea.config.routing import url
 from kallithea.lib.annotate import annotate_highlight
-from kallithea.lib.utils import get_custom_lexer
+from kallithea.lib.pygmentsutils import get_custom_lexer
 from kallithea.lib.utils2 import str2bool, safe_unicode, safe_str, \
     time_to_datetime, AttributeDict, safe_int, MENTIONS_REGEX
 from kallithea.lib.markup_renderer import url_re
--- a/kallithea/lib/pygmentsutils.py	Sun Oct 09 21:08:18 2016 +0200
+++ b/kallithea/lib/pygmentsutils.py	Sun Oct 09 21:42:11 2016 +0200
@@ -78,3 +78,15 @@
             filenames.append(f)
 
     return filenames
+
+
+def get_custom_lexer(extension):
+    """
+    returns a custom lexer if it's defined in rcextensions module, or None
+    if there's no custom lexer defined
+    """
+    import kallithea
+    #check if we didn't define this extension as other lexer
+    if kallithea.EXTENSIONS and extension in kallithea.EXTENSIONS.EXTRA_LEXERS:
+        _lexer_name = kallithea.EXTENSIONS.EXTRA_LEXERS[extension]
+        return lexers.get_lexer_by_name(_lexer_name)
--- a/kallithea/lib/utils.py	Sun Oct 09 21:08:18 2016 +0200
+++ b/kallithea/lib/utils.py	Sun Oct 09 21:42:11 2016 +0200
@@ -580,19 +580,6 @@
         #        setattr(EXT, k, getattr(rcextensions, k))
 
 
-def get_custom_lexer(extension):
-    """
-    returns a custom lexer if it's defined in rcextensions module, or None
-    if there's no custom lexer defined
-    """
-    import kallithea
-    from pygments import lexers
-    #check if we didn't define this extension as other lexer
-    if kallithea.EXTENSIONS and extension in kallithea.EXTENSIONS.EXTRA_LEXERS:
-        _lexer_name = kallithea.EXTENSIONS.EXTRA_LEXERS[extension]
-        return lexers.get_lexer_by_name(_lexer_name)
-
-
 #==============================================================================
 # TEST FUNCTIONS AND CREATORS
 #==============================================================================