upgrade wakatime-cli to v8.0.3

This commit is contained in:
Alan Hamlett 2017-06-08 00:18:26 -07:00
parent 9100af48c6
commit a96180dd0e
4 changed files with 30 additions and 16 deletions

View file

@ -1,7 +1,7 @@
__title__ = 'wakatime' __title__ = 'wakatime'
__description__ = 'Common interface to the WakaTime api.' __description__ = 'Common interface to the WakaTime api.'
__url__ = 'https://github.com/wakatime/wakatime' __url__ = 'https://github.com/wakatime/wakatime'
__version_info__ = ('8', '0', '2') __version_info__ = ('8', '0', '3')
__version__ = '.'.join(__version_info__) __version__ = '.'.join(__version_info__)
__author__ = 'Alan Hamlett' __author__ = 'Alan Hamlett'
__author_email__ = 'alan@wakatime.com' __author_email__ = 'alan@wakatime.com'

View file

@ -11,8 +11,8 @@
LANGUAGES = { LANGUAGES = {
'typescript': 0.01, 'f#': 0.01,
'perl': 0.01, 'perl': 0.01,
'perl6': 0.01, 'perl6': 0.01,
'f#': 0.01, 'typescript': 0.01,
} }

View file

@ -134,9 +134,9 @@ class MatlabLexer(RegexLexer):
} }
def analyse_text(text): def analyse_text(text):
if re.match('^\s*%', text, re.M): # comment if re.search(r'^\s*%', text, re.M): # comment
return 0.2 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 return 0.2

View file

@ -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'))): 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' return 'C'
directory = os.path.dirname(file_name) available_extensions = extensions_in_same_folder(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]
if '.cpp' in available_extensions: if '.cpp' in available_extensions:
return 'C++' return 'C++'
if '.c' in available_extensions: if '.c' in available_extensions:
@ -300,7 +297,7 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options):
rv = lexer.analyse_text(_text) rv = lexer.analyse_text(_text)
if rv == 1.0: if rv == 1.0:
return lexer(**options) return lexer(**options)
result.append((rv, customize_priority(lexer))) result.append(customize_lexer_priority(_fn, rv, lexer))
def type_sort(t): def type_sort(t):
# sort by: # sort by:
@ -308,16 +305,33 @@ def custom_pygments_guess_lexer_for_filename(_fn, _text, **options):
# - is primary filename pattern? # - is primary filename pattern?
# - priority # - priority
# - last resort: class name # - 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) result.sort(key=type_sort)
return result[-1][1](**options) return result[-1][2](**options)
def customize_priority(lexer): def customize_lexer_priority(file_name, accuracy, lexer):
"""Return an integer priority for the given lexer object.""" """Customize lexer priority"""
priority = lexer.priority
lexer_name = lexer.name.lower().replace('sharp', '#') lexer_name = lexer.name.lower().replace('sharp', '#')
if lexer_name in LANGUAGES: if lexer_name in LANGUAGES:
lexer.priority = LANGUAGES[lexer_name] priority = LANGUAGES[lexer_name]
return lexer 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