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
 
@@ -45,13 +45,13 @@ def annotate_highlight(filenode, annotat
 
    :param order: ordered sequence of ``ls`` (line numbers column),
 
      ``annotate`` (annotate column), ``code`` (code column); Default is
 
      ``['ls', 'annotate', 'code']``
 
    :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,
 
        annotate_from_changeset_func=annotate_from_changeset_func, **options)
 
    lexer = get_custom_lexer(filenode.extension) or filenode.lexer
 
    highlighted = highlight(filenode.content, lexer, formatter)
kallithea/lib/helpers.py
Show inline comments
 
@@ -38,13 +38,13 @@ from webhelpers.pylonslib.secure_form im
 
from webhelpers.text import chop_at, truncate, wrap_paragraphs
 
from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \
 
    convert_boolean_attrs, NotGiven, _make_safe_id_component
 

	
 
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
 
from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
 
from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
 

	
kallithea/lib/pygmentsutils.py
Show inline comments
 
@@ -75,6 +75,18 @@ def get_index_filenames():
 

	
 
    for lx, t in sorted(lexers.LEXERS.items()):
 
        for f in ifilter(likely_filename, t[-2]):
 
            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
 
@@ -577,25 +577,12 @@ def load_rcextensions(root_path):
 
        #from kallithea.config import rcextensions
 
        #for k in dir(rcextensions):
 
        #    if not k.startswith('_') and not hasattr(EXT, k):
 
        #        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
 
#==============================================================================
 
def create_test_index(repo_location, config, full_index):
 
    """
 
    Makes default test index
0 comments (0 inline, 0 general)