From 92d7f477e476611e83ec1938c93770df0ad4c6b6 Mon Sep 17 00:00:00 2001 From: Hezheng Yin Date: Mon, 10 Jun 2019 20:41:45 -0700 Subject: [PATCH 1/3] Add .ts and .tsx files to analysis target --- persper/analytics/graph_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persper/analytics/graph_server.py b/persper/analytics/graph_server.py index 29d8e81f213..049c721166b 100644 --- a/persper/analytics/graph_server.py +++ b/persper/analytics/graph_server.py @@ -6,7 +6,7 @@ from persper.analytics.call_commit_graph import CallCommitGraph JS_FILENAME_REGEXES = [ - r'.+\.(js|vue)$', + r'.+\.(js|vue|ts|tsx)$', r'^(?!dist/).+', r'^(?!test(s)?/).+', r'^(?!spec/).+', From 56f2b410fef6791caeae38cfd75bae6fe4b3589d Mon Sep 17 00:00:00 2001 From: Hezheng Yin Date: Mon, 10 Jun 2019 20:42:37 -0700 Subject: [PATCH 2/3] Merge TypeScript to JavaScript for linguist --- persper/analytics/multi_analyzer.py | 44 ++++++++++++++++++---- test/test_analytics/test_multi_analyzer.py | 21 +++++++++-- 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/persper/analytics/multi_analyzer.py b/persper/analytics/multi_analyzer.py index 6b424aa81c8..9e5e04c1871 100644 --- a/persper/analytics/multi_analyzer.py +++ b/persper/analytics/multi_analyzer.py @@ -2,6 +2,7 @@ import json import pickle from git import Repo +from enum import Enum from Naked.toolshed.shell import muterun_rb from persper.util.path import root_path from persper.analytics.c import CGraphServer @@ -12,6 +13,20 @@ from persper.analytics.analyzer2 import Analyzer, AnalyzerObserver, emptyAnalyzerObserver +class Linguist(Enum): + """ + Encodes the relationship between a language and its name in linguist's output + https://github.com/github/linguist/blob/master/lib/linguist/languages.yml + """ + C = "C" + CPP = "C++" + GO = "Go" + JAVA = "Java" + JAVASCRIPT = "JavaScript" + TYPESCRIPT = "TypeScript" + VUE = "Vue" + + class MultiAnalyzer: LANGUAGE_THRESHOLD = 0.3 @@ -35,18 +50,33 @@ def _set_linguist(self): for k in lang_dict.keys(): lang_dict[k] = lang_dict[k] * 1.0 / total_lines + js = Linguist.JAVASCRIPT.value + ts = Linguist.TYPESCRIPT.value + vue = Linguist.VUE.value + + print(lang_dict) + if vue in lang_dict: + print("Merging Vue to Javascript...") + if js not in lang_dict: + lang_dict[js] = 0 + lang_dict[js] += lang_dict[vue] + del lang_dict[vue] + print(lang_dict) + + if ts in lang_dict: + print("Merging TypeScript to JavaScript...") + if js not in lang_dict: + lang_dict[js] = 0 + lang_dict[js] += lang_dict[ts] + del lang_dict[ts] + print(lang_dict) + + # intersect with what languages we support for lang, value in lang_dict.items(): if lang in self._supported_analyzers().keys(): self._linguist[lang] = value print(self._linguist) - if "Vue" in self._linguist: - print("Merging Vue to Javascript...") - if "JavaScript" not in self._linguist: - self._linguist["JavaScript"] = 0 - self._linguist["JavaScript"] += self._linguist["Vue"] - del self._linguist["Vue"] - print(self._linguist) else: print('Analyzing Language Error from Linguist') diff --git a/test/test_analytics/test_multi_analyzer.py b/test/test_analytics/test_multi_analyzer.py index 1e9b70d1942..c2bbaa6ae56 100644 --- a/test/test_analytics/test_multi_analyzer.py +++ b/test/test_analytics/test_multi_analyzer.py @@ -6,7 +6,7 @@ @pytest.fixture(scope='module') -def repo_path(): +def vue_repo_path(): repo_path = os.path.join(root_path, "repos/vue-realworld-example-app") repo_url = 'https://github.com/gothinkster/vue-realworld-example-app' if not os.path.exists(repo_path): @@ -14,5 +14,20 @@ def repo_path(): return repo_path -def test_set_linguist(repo_path): - maz = MultiAnalyzer(repo_path) +@pytest.fixture(scope='module') +def ts_repo_path(): + repo_path = os.path.join(root_path, "repos/TypeScriptSamples") + repo_url = 'https://github.com/microsoft/TypeScriptSamples' + if not os.path.exists(repo_path): + Repo.clone_from(repo_url, repo_path) + return repo_path + + +def test_set_linguist_vue(vue_repo_path): + # _set_linguist is called during the initialization of MultiAnalyzer + maz = MultiAnalyzer(vue_repo_path) + + +def test_set_linguist_ts(ts_repo_path): + # _set_linguist is called during the initialization of MultiAnalyzer + maz = MultiAnalyzer(ts_repo_path) From 262dbd95b63383d4ffaa0398316831768927095b Mon Sep 17 00:00:00 2001 From: Hezheng Yin Date: Mon, 10 Jun 2019 20:50:11 -0700 Subject: [PATCH 3/3] Replace print with logging --- persper/analytics/multi_analyzer.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/persper/analytics/multi_analyzer.py b/persper/analytics/multi_analyzer.py index 9e5e04c1871..cc1328a1f57 100644 --- a/persper/analytics/multi_analyzer.py +++ b/persper/analytics/multi_analyzer.py @@ -1,6 +1,7 @@ import os import json import pickle +import logging from git import Repo from enum import Enum from Naked.toolshed.shell import muterun_rb @@ -13,6 +14,9 @@ from persper.analytics.analyzer2 import Analyzer, AnalyzerObserver, emptyAnalyzerObserver +_logger = logging.getLogger(__name__) + + class Linguist(Enum): """ Encodes the relationship between a language and its name in linguist's output @@ -54,32 +58,32 @@ def _set_linguist(self): ts = Linguist.TYPESCRIPT.value vue = Linguist.VUE.value - print(lang_dict) + _logger.info(lang_dict) if vue in lang_dict: - print("Merging Vue to Javascript...") + _logger.info("Merging Vue to Javascript...") if js not in lang_dict: lang_dict[js] = 0 lang_dict[js] += lang_dict[vue] del lang_dict[vue] - print(lang_dict) + _logger.info(lang_dict) if ts in lang_dict: - print("Merging TypeScript to JavaScript...") + _logger.info("Merging TypeScript to JavaScript...") if js not in lang_dict: lang_dict[js] = 0 lang_dict[js] += lang_dict[ts] del lang_dict[ts] - print(lang_dict) + _logger.info(lang_dict) # intersect with what languages we support for lang, value in lang_dict.items(): if lang in self._supported_analyzers().keys(): self._linguist[lang] = value - print(self._linguist) + _logger.info(self._linguist) else: - print('Analyzing Language Error from Linguist') + _logger.info('Analyzing Language Error from Linguist') def _set_analyzers(self): for language, value in self._linguist.items():