Changeset - 2ae737b2dbdc
[Not reviewed]
default
0 4 0
Thomas De Schampheleire - 9 years ago 2016-10-09 21:42:11
thomas.de.schampheleire@gmail.com
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.
4 files changed with 14 insertions and 15 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/annotate.py
Show inline comments
 
@@ -48,7 +48,7 @@ def annotate_highlight(filenode, annotat
 
    :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,
kallithea/lib/helpers.py
Show inline comments
 
@@ -41,7 +41,7 @@ from webhelpers.html.tags import _set_in
 

	
 
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
kallithea/lib/pygmentsutils.py
Show inline comments
 
@@ -78,3 +78,15 @@ def get_index_filenames():
 
            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)
kallithea/lib/utils.py
Show inline comments
 
@@ -580,19 +580,6 @@ def load_rcextensions(root_path):
 
        #        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
 
#==============================================================================
0 comments (0 inline, 0 general)