From fa4087463547afd5bb1b217f2ec380749aff774d Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Thu, 8 Jun 2017 00:20:10 -0700 Subject: [PATCH] upgrade wakatime-cli to v8.0.3 --- packages/wakatime/__about__.py | 2 +- packages/wakatime/language_priorities.py | 4 +-- .../packages/pygments/lexers/matlab.py | 4 +-- packages/wakatime/stats.py | 36 +++++++++++++------ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/packages/wakatime/__about__.py b/packages/wakatime/__about__.py index 2b2b185..5058176 100644 --- a/packages/wakatime/__about__.py +++ b/packages/wakatime/__about__.py @@ -1,7 +1,7 @@ __title__ = 'wakatime' __description__ = 'Common interface to the WakaTime api.' __url__ = 'https://github.com/wakatime/wakatime' -__version_info__ = ('8', '0', '2') +__version_info__ = ('8', '0', '3') __version__ = '.'.join(__version_info__) __author__ = 'Alan Hamlett' __author_email__ = 'alan@wakatime.com' diff --git a/packages/wakatime/language_priorities.py b/packages/wakatime/language_priorities.py index 8ae7848..cb7d185 100644 --- a/packages/wakatime/language_priorities.py +++ b/packages/wakatime/language_priorities.py @@ -11,8 +11,8 @@ LANGUAGES = { - 'typescript': 0.01, + 'f#': 0.01, 'perl': 0.01, 'perl6': 0.01, - 'f#': 0.01, + 'typescript': 0.01, } diff --git a/packages/wakatime/packages/pygments/lexers/matlab.py b/packages/wakatime/packages/pygments/lexers/matlab.py index 56a0f6d..02a90bb 100644 --- a/packages/wakatime/packages/pygments/lexers/matlab.py +++ b/packages/wakatime/packages/pygments/lexers/matlab.py @@ -134,9 +134,9 @@ class MatlabLexer(RegexLexer): } def analyse_text(text): - if re.match('^\s*%', text, re.M): # comment + if re.search(r'^\s*%', text, re.M): # comment return 0.2 - elif re.match('^!\w+', text, re.M): # system cmd + elif re.search(r'^!\w+', text, re.M): # system cmd return 0.2 diff --git a/packages/wakatime/stats.py b/packages/wakatime/stats.py index e6fc3ff..ac23ef8 100644 --- a/packages/wakatime/stats.py +++ b/packages/wakatime/stats.py @@ -172,10 +172,7 @@ def get_language_from_extension(file_name): if os.path.exists(u('{0}{1}').format(u(filepart), u('.c'))) or os.path.exists(u('{0}{1}').format(u(filepart), u('.C'))): return 'C' - directory = os.path.dirname(file_name) - available_files = os.listdir(directory) - available_extensions = list(zip(*map(os.path.splitext, available_files)))[1] - available_extensions = [ext.lower() for ext in available_extensions] + available_extensions = extensions_in_same_folder(file_name) if '.cpp' in available_extensions: return 'C++' if '.c' in available_extensions: @@ -300,7 +297,7 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options): rv = lexer.analyse_text(_text) if rv == 1.0: return lexer(**options) - result.append((rv, customize_priority(lexer))) + result.append(customize_lexer_priority(_fn, rv, lexer)) def type_sort(t): # sort by: @@ -308,16 +305,33 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options): # - is primary filename pattern? # - priority # - last resort: class name - return (t[0], primary[t[1]], t[1].priority, t[1].__name__) + return (t[0], primary[t[2]], t[1], t[2].__name__) result.sort(key=type_sort) - return result[-1][1](**options) + return result[-1][2](**options) -def customize_priority(lexer): - """Return an integer priority for the given lexer object.""" +def customize_lexer_priority(file_name, accuracy, lexer): + """Customize lexer priority""" + + priority = lexer.priority lexer_name = lexer.name.lower().replace('sharp', '#') if lexer_name in LANGUAGES: - lexer.priority = LANGUAGES[lexer_name] - return lexer + priority = LANGUAGES[lexer_name] + elif lexer_name == 'matlab': + available_extensions = extensions_in_same_folder(file_name) + if '.mat' in available_extensions: + priority = 0.06 + + return (accuracy, priority, lexer) + + +def extensions_in_same_folder(file_name): + """Returns a list of file extensions from the same folder as file_name.""" + + directory = os.path.dirname(file_name) + files = os.listdir(directory) + extensions = list(zip(*map(os.path.splitext, files)))[1] + extensions = set([ext.lower() for ext in extensions]) + return extensions