# HG changeset patch # User Thomas De Schampheleire # Date 1476042131 -7200 # Node ID 2ae737b2dbdc2d90860db20d182137f1c98457fa # Parent ecd0d34bc20c76231bf192a1af612b112dd64249 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. diff -r ecd0d34bc20c -r 2ae737b2dbdc kallithea/lib/annotate.py --- 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, diff -r ecd0d34bc20c -r 2ae737b2dbdc kallithea/lib/helpers.py --- 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 diff -r ecd0d34bc20c -r 2ae737b2dbdc kallithea/lib/pygmentsutils.py --- 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) diff -r ecd0d34bc20c -r 2ae737b2dbdc kallithea/lib/utils.py --- 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 #==============================================================================