From 66efd3dea9482a69681be33b05e9ed442a6c0578 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de> Date: Tue, 11 Apr 2023 18:18:03 +0200 Subject: [PATCH] purge devtools: rm line counting tools --- devtools/linecount/baloc/__init__.py | 3 - devtools/linecount/baloc/file_types.py | 122 ----------------- devtools/linecount/baloc/history_collector.py | 128 ------------------ devtools/linecount/baloc/history_plot.py | 63 --------- devtools/linecount/lines_of_code.py | 58 -------- 5 files changed, 374 deletions(-) delete mode 100644 devtools/linecount/baloc/__init__.py delete mode 100644 devtools/linecount/baloc/file_types.py delete mode 100644 devtools/linecount/baloc/history_collector.py delete mode 100644 devtools/linecount/baloc/history_plot.py delete mode 100755 devtools/linecount/lines_of_code.py diff --git a/devtools/linecount/baloc/__init__.py b/devtools/linecount/baloc/__init__.py deleted file mode 100644 index c8a9d7cc449..00000000000 --- a/devtools/linecount/baloc/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .file_types import * -from .history_collector import * -from .history_plot import * diff --git a/devtools/linecount/baloc/file_types.py b/devtools/linecount/baloc/file_types.py deleted file mode 100644 index 9a86fccbd53..00000000000 --- a/devtools/linecount/baloc/file_types.py +++ /dev/null @@ -1,122 +0,0 @@ -""" -Contains machinery to convert BornAgain filename to the type of the content -""" - -class FileTypes: - """ - Enumerator class to hold file types - """ - CORE, FTEST, UTEST, PYCODE, MACROS, GUI, PYAPI, THIRD, UNDEF, TOTAL = range(10) - descr=["Core", "Functional Tests", "Unit Tests", "*.py", "macros", "GUI", "PythonAPI", "Third", "Undef"] - @staticmethod - def loc_for_type(): - result = [] - for i in range(FileTypes.TOTAL): - result.append(0) - return result - - -def filePython(x): - if ".py" in x and not ".pypp." in x: return True - return False - - -def fileCpp(x): - if ".h" in x or ".cpp" in x: return True - return False - - -def dirCore(x): - # if "/Core/Algorithms" in x: return True - # if "/Core/FormFactors" in x: return True - # if "/Core/Samples" in x: return True - # if "/Core/StandardSamples" in x: return True - # if "/Core/Tools" in x: return True - # if "/Core/Fitting" in x: return True - # if "/Core/inc" in x: return True - # if "/Core/src" in x: return True - # if "/Core/InputOutput" in x: return True - # if "/Core/Geometry" in x: return True - # if "/Fit/Factory" in x: return True - # if "/Fit/FitKernel" in x: return True - # if "/Fit/StandardFits" in x: return True - # if "/Core/Geometry" in x: return True - if "/Core/" in x: return True - if "/Fit/" in x: return True - - return False - - -def dirPyAPI(x): - if "/Core/PythonAPI" in x: return True - if "/Fit/PythonAPI" in x: return True - return False - - -def dirFuncTest(x): - # if "/App/" in x: return True - if "/Tests/Functional" in x: return True - if "/Tests/PerformanceTests" in x: return True - if "/Tests/FunctionalTests/TestCore" in x: return True - if "/Tests/FunctionalTests/TestFit" in x: return True - if "/Tests/FunctionalTests/TestPyCore" in x: return True - if "/Tests/FunctionalTests/TestPyFit" in x: return True - if "/Core/TestMachinery" in x: return True - return False - - -def dirGUI(x): - if "/GUI/coregui" in x and not "widgetbox" in x and not "qttools" in x: return True - if "/GUI/main" in x: return True - if "/AppGUI/coregui" in x: return True - if "/BASuite" in x: return True - return False - - -def dirThirdParty(x): - if "/ThirdParty" in x: return True - return False - - -def dirSkip(x): - if "/pub/core" in x: return True - return False - - -def dirUnitTests(x): - if "/UnitTests/" in x: return True - if "/Tests/UnitTests/TestCore/" in x: return True - if "/Tests/UnitTests/TestFit/" in x: return True - if "/Tests/UnitTests/" in x: return True - return False - - -def filetype(x): - """ - Returns type of file - """ - result = FileTypes.UNDEF - - if dirSkip(x): - return result - - if dirPyAPI(x): - result = FileTypes.PYAPI - - elif dirThirdParty(x): - result = FileTypes.THIRD - - elif (fileCpp(x) or filePython(x)) and dirFuncTest(x): - result = FileTypes.FTEST - - elif fileCpp(x) and dirCore(x): - result = FileTypes.CORE - - elif dirUnitTests(x): - result = FileTypes.UTEST - - elif dirGUI(x): - result = FileTypes.GUI - - return result - diff --git a/devtools/linecount/baloc/history_collector.py b/devtools/linecount/baloc/history_collector.py deleted file mode 100644 index 8ac42f65e6d..00000000000 --- a/devtools/linecount/baloc/history_collector.py +++ /dev/null @@ -1,128 +0,0 @@ -""" -Process gitlog and create a file with number of lines of code. -""" -from datetime import datetime -from .file_types import FileTypes, filetype -import re -from email.utils import parsedate -import subprocess - - -def gitlog(): - """ - Execute gitlog command and make generator over lines in the log - """ - p = subprocess.Popen(['git', 'log', 'develop', '--reverse', '-p'], stdout=subprocess.PIPE) - for line in iter(p.stdout.readline, b''): - decoded = line.decode('latin1') - if decoded and len(decoded): - yield decoded.strip() - - -class Commit: - """ - Contains commit info and accumulated number of lines of code (file type dependent). - """ - def __init__(self): - self.date = datetime.today() - self.added_lines = 0 - self.removed_lines = 0 - self.loc_for_type = FileTypes.loc_for_type() - self.hsh = None - self.who = None - self.cmt = None - - def increment_loc(self, file_type): - self.loc_for_type[file_type] += 1 - self.added_lines += 1 - - def decrement_loc(self, file_type): - self.loc_for_type[file_type] -= 1 - self.removed_lines += 1 - - -class DayHistory: - """ - Number of lines added or deleted for given day. - """ - def __init__(self, date, locs): - self.date = date - self.loc_for_type = locs - - -class HistoryCollector: - def __init__(self): - self.last_commit = Commit() - self.data = [] - self.locs = 0 - self.fc = 0 - self.file_type_ppp = FileTypes.UNDEF - self.file_type_mmm = FileTypes.UNDEF - self.start_date = datetime(2012, 4, 1) - self.days_history = {} # DayHistory vs. number of days since beginning of coding - - def pop(self): - if not self.last_commit.added_lines: - return - pstr="%s %8u %5s %5s %7s %s"%(self.last_commit.date, self.locs, '+' + str(self.last_commit.added_lines), '-' + str(self.last_commit.removed_lines), self.last_commit.hsh, self.last_commit.who) - print(pstr) - delta = (self.last_commit.date - self.start_date).days - self.days_history[delta] = DayHistory(self.last_commit.date, self.last_commit.loc_for_type) - - tmp = list(self.last_commit.loc_for_type) - self.last_commit = Commit() - self.last_commit.loc_for_type = tmp - - def run(self): - nnn = 0 - for x in gitlog(): - nnn += 1 - if x.startswith('commit'): - self.pop() - self.last_commit.hsh = x[7:14] - - if x.startswith('Author'): - self.last_commit.who = x.replace("Author: ", '').replace('\n', '') - self.last_commit.who = re.sub(">.*", "", self.last_commit.who) - self.last_commit.who = re.sub(".*<", "", self.last_commit.who) - - if x.startswith('Date'): - self.fc = 1 - self.last_commit.date = datetime(*parsedate(x[5:])[:7]) - - if self.fc == 2: - self.last_commit.cmt = x[:-1] - self.fc = 0 - - if self.fc == 1: - if len(x) == 1: - self.fc = 2 - - if x.startswith('+++'): - self.file_type_ppp = filetype(x) - - if x.startswith('---'): - self.file_type_mmm = filetype(x) - - if x.startswith('+') and not x.startswith('+++'): - self.last_commit.increment_loc(self.file_type_ppp) - if self.file_type_ppp <FileTypes.PYAPI: - self.locs += 1 - - if x.startswith('-') and not x.startswith('---'): - self.last_commit.decrement_loc(self.file_type_mmm) - if self.file_type_mmm < FileTypes.PYAPI: - self.locs -= 1 - - # if nnn>1000000: - # break - - self.pop() - - def save_report(self, filename): - print("Saving report in {0}".format(filename)) - with open(filename, 'w') as the_file: - for key in self.days_history: - dayhist = self.days_history[key] - pstr = "%s %s \n" % (str(dayhist.date), ' '.join(str(e) for e in dayhist.loc_for_type)) - the_file.write(pstr) diff --git a/devtools/linecount/baloc/history_plot.py b/devtools/linecount/baloc/history_plot.py deleted file mode 100644 index 73eabfc5792..00000000000 --- a/devtools/linecount/baloc/history_plot.py +++ /dev/null @@ -1,63 +0,0 @@ -import matplotlib.pyplot as plt -import seaborn as sns -from datetime import datetime -from .file_types import FileTypes, filetype - - -selected_file_type = [FileTypes.CORE, FileTypes.FTEST, FileTypes.UTEST, FileTypes.GUI, FileTypes.PYAPI] - - -def read_history(filename): - xvals = [] # Time - ydata = {} # id of file type .vs. LOC .vs. time - for x in selected_file_type: - ydata[x] = [] - - print("Reading file {0}".format(filename)) - with open(filename, 'r') as the_file: - for line in the_file: - parts = line.strip().split() - date = datetime.strptime(parts[0] + " " + parts[1], '%Y-%m-%d %H:%M:%S') - xvals.append(date) - for x in selected_file_type: - ydata[x].append(int(parts[2+x])) - - yvals = [] - descr = [] - for key in ydata: - descr.append(FileTypes.descr[key]) - yvals.append(ydata[key]) - - # printing summary of LOC - for x in range(0, len(yvals)): - print("{:18} : {:10}".format(descr[x], yvals[x][-1])) - - return xvals, yvals, descr - - -def history_plot(filename): - xvals, yvals, descr = read_history(filename) - - # figure size - my_dpi = 96 - plt.figure(figsize=(1600*1.2 / my_dpi, 900*1.2 / my_dpi), dpi=my_dpi) - plt.style.use('seaborn-bright') - - # making stackplot - plt.stackplot(xvals, yvals) - pal = ["#3399ff", "#ffcc00", "#ff0000", "#0033ff", "#999999"] - plt.stackplot(xvals, yvals, labels=descr, colors=pal) - - # styling axes and grid - plt.grid(color='gray', linestyle='dashed') - ax = plt.gca() - ax.set_axisbelow(True) - plt.ylim(0.0, 220e+03) - plt.tick_params(axis='both', which='major', labelsize=14) - - # making inverse legend - handles, labels = ax.get_legend_handles_labels() - ax.legend(handles[::-1], labels[::-1], loc='upper left', prop={'size': 18}) - - # saving plot - plt.savefig('lines_of_code.png', dpi=my_dpi, bbox_inches='tight') diff --git a/devtools/linecount/lines_of_code.py b/devtools/linecount/lines_of_code.py deleted file mode 100755 index 2366fa6f5a4..00000000000 --- a/devtools/linecount/lines_of_code.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -""" -Creates picture with number of lines of code. -Usage: python3 lines_of_code.py - -The command should be executed in the directory where lines_of_code.py is located -(i.e. in <BornAgain>/devtools/linecount) -""" -import sys -if sys.version_info < (3, 0): - exit("Requires python3, exiting ...") -import os -from baloc import HistoryCollector -from baloc import history_plot -import matplotlib.pyplot as plt - - -gitlog_filename = "gitlog.tmp" - - -def process_loc_number(targetfolder="../..", gitlog=gitlog_filename): - prevfolder = os.getcwd() - os.chdir(targetfolder) - - collector = HistoryCollector() - collector.run() - collector.save_report(os.path.join(prevfolder, gitlog)) - - os.chdir(prevfolder) - - -def plot_loc_number(gitlog=gitlog_filename): - history_plot(gitlog) - plt.show() - - -if __name__ == '__main__': - print('-' * 80) - print("Generating picture for number of lines of code") - print('-' * 80) - print(" ") - print("Possible options:") - print("[0] - Generate {0} and picture.".format(gitlog_filename)) - print("[1] - Generate only {0}.".format(gitlog_filename)) - print("[2] - Generate picture using existing {0}.".format(gitlog_filename)) - print("[3] - Exit") - - var = int(input("Enter your choice [0]: ") or "0") - - if var == 0: - process_loc_number() - plot_loc_number() - elif var == 1: - process_loc_number() - elif var == 2: - plot_loc_number() - else: - exit("Good bye") -- GitLab