From 0f02aa91b744d5d6ad651ec56bb311ecf40e841a Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Sat, 4 Mar 2017 13:11:40 -0800 Subject: [PATCH] move language priorities into separate file --- wakatime/language_priorities.py | 18 ++++++++++++++++++ wakatime/stats.py | 11 +++-------- 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 wakatime/language_priorities.py diff --git a/wakatime/language_priorities.py b/wakatime/language_priorities.py new file mode 100644 index 0000000..d4794bc --- /dev/null +++ b/wakatime/language_priorities.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +""" + wakatime.language_priorities + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Overwrite pygments Lexer.priority attribute for specific languages. + + :copyright: (c) 2017 Alan Hamlett. + :license: BSD, see LICENSE for more details. +""" + + +LANGUAGES = { + 'typescript': 0.11, + 'perl': 0.1, + 'perl6': 0.1, + 'f#': 0.1, +} diff --git a/wakatime/stats.py b/wakatime/stats.py index cc5935c..50392aa 100644 --- a/wakatime/stats.py +++ b/wakatime/stats.py @@ -16,6 +16,7 @@ import sys from .compat import u, open from .dependencies import DependencyParser +from .language_priorities import LANGUAGES from .packages.pygments.lexers import ( _iter_lexerclasses, @@ -307,15 +308,9 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options): return result[-1][1](**options) -CUSTOM_PRIORITIES = { - 'typescript': 0.11, - 'perl': 0.1, - 'perl6': 0.1, - 'f#': 0.1, -} def customize_priority(lexer): """Return an integer priority for the given lexer object.""" - if lexer.name.lower() in CUSTOM_PRIORITIES: - lexer.priority = CUSTOM_PRIORITIES[lexer.name.lower()] + if lexer.name.lower() in LANGUAGES: + lexer.priority = LANGUAGES[lexer.name.lower()] return lexer