From e84a5788e8745d03242a632ac19d36aa40dfa9e9 Mon Sep 17 00:00:00 2001 From: "jaekwon.bang" Date: Mon, 24 May 2021 17:33:48 +0900 Subject: [PATCH] Apply Flake8 to check PEP8 --- requirements-dev.txt | 3 +++ src/fosslight_util/constant.py | 3 +-- src/fosslight_util/help.py | 19 +++++++++---------- src/fosslight_util/set_log.py | 8 ++++---- src/fosslight_util/timer_thread.py | 3 ++- src/fosslight_util/write_excel.py | 15 ++++++--------- tests/test_excel.py | 2 +- tests/test_help.py | 3 ++- tests/test_log.py | 4 +++- tests/test_timer.py | 1 - tox.ini | 11 +++++++++++ 11 files changed, 42 insertions(+), 30 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 053148f..306ef44 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1 +1,4 @@ tox +pytest +pytest-cov +pytest-flake8 diff --git a/src/fosslight_util/constant.py b/src/fosslight_util/constant.py index ec7da1e..0fa530a 100755 --- a/src/fosslight_util/constant.py +++ b/src/fosslight_util/constant.py @@ -3,5 +3,4 @@ # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 - -LOGGER_NAME = "FOSSLight" \ No newline at end of file +LOGGER_NAME = "FOSSLight" diff --git a/src/fosslight_util/help.py b/src/fosslight_util/help.py index e236715..3f28ddf 100644 --- a/src/fosslight_util/help.py +++ b/src/fosslight_util/help.py @@ -5,26 +5,25 @@ import sys _HELP_MESSAGE_COMMON = """ - _______ _______ _______ _______ ___ ___ _______ __ __ _______ + _______ _______ _______ _______ ___ ___ _______ __ __ _______ | || || || || | | | | || | | || | | ___|| _ || _____|| _____|| | | | | ___|| |_| ||_ _| - | |___ | | | || |_____ | |_____ | | | | | | __ | | | | - | ___|| |_| ||_____ ||_____ || |___ | | | || || _ | | | - | | | | _____| | _____| || || | | |_| || | | | | | - |___| |_______||_______||_______||_______||___| |_______||__| |__| |___| + | |___ | | | || |_____ | |_____ | | | | | | __ | | | | + | ___|| |_| ||_____ ||_____ || |___ | | | || || _ | | | + | | | | _____| | _____| || || | | |_| || | | | | | + |___| |_______||_______||_______||_______||___| |_______||__| |__| |___| """ + class PrintHelpMsg(): message_suffix = "" def __init__(self, value): self.message_suffix = value - + def print_help_msg(self, exitopt): print(_HELP_MESSAGE_COMMON) print(self.message_suffix) - - if exitopt == True: - sys.exit() - + if exitopt: + sys.exit() diff --git a/src/fosslight_util/set_log.py b/src/fosslight_util/set_log.py index 4f0c57d..b84dff1 100755 --- a/src/fosslight_util/set_log.py +++ b/src/fosslight_util/set_log.py @@ -15,7 +15,7 @@ def init_log(log_file, create_file=True, stream_log_level=logging.INFO, file_log_level=logging.DEBUG): logger = logging.getLogger(constant.LOGGER_NAME) - + if not logger.hasHandlers(): logger.setLevel(logging.DEBUG) log_dir = os.path.dirname(log_file) @@ -42,7 +42,7 @@ def init_log(log_file, create_file=True, stream_log_level=logging.INFO, file_log return logger -def init_log_item(main_package_name="", path_to_analyze= ""): +def init_log_item(main_package_name="", path_to_analyze=""): _PYTHON_VERSION = sys.version_info[0] _result_log = { @@ -52,8 +52,8 @@ def init_log_item(main_package_name="", path_to_analyze= ""): } if main_package_name != "": pkg_version = pkg_resources.get_distribution(main_package_name).version - _result_log["Tool Info"] = main_package_name +" v."+pkg_version + _result_log["Tool Info"] = main_package_name + " v." + pkg_version if path_to_analyze != "": - _result_log["Path to analyze"] = path_to_analyze + _result_log["Path to analyze"] = path_to_analyze return _result_log diff --git a/src/fosslight_util/timer_thread.py b/src/fosslight_util/timer_thread.py index 56183e1..2d07dcd 100755 --- a/src/fosslight_util/timer_thread.py +++ b/src/fosslight_util/timer_thread.py @@ -6,6 +6,7 @@ import time from progress.spinner import Spinner + class TimerThread(threading.Thread): def __init__(self): threading.Thread.__init__(self, name=' Thread') @@ -14,4 +15,4 @@ def run(self): spinner = Spinner('') while True: time.sleep(1) - spinner.next() \ No newline at end of file + spinner.next() diff --git a/src/fosslight_util/write_excel.py b/src/fosslight_util/write_excel.py index 4afcdef..1518c6d 100755 --- a/src/fosslight_util/write_excel.py +++ b/src/fosslight_util/write_excel.py @@ -7,9 +7,7 @@ import time import logging import os -import json import platform -import time import pandas as pd from pathlib import Path import fosslight_util.constant as constant @@ -40,11 +38,10 @@ def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False) output_dir = os.path.dirname(filename_without_extension) Path(output_dir).mkdir(parents=True, exist_ok=True) - success, error_msg = write_result_to_excel(filename_without_extension + - ".xlsx", sheet_list) + success, error_msg = write_result_to_excel(filename_without_extension + ".xlsx", sheet_list) + if ignore_os or platform.system() != "Windows": - success_csv, error_msg_csv = write_result_to_csv(filename_without_extension + - ".csv", sheet_list) + success_csv, error_msg_csv = write_result_to_csv(filename_without_extension + ".csv", sheet_list) if not success: error_msg = "[Error] Writing excel:" + error_msg if not success_csv: @@ -65,7 +62,7 @@ def remove_empty_sheet(sheet_items): try: if sheet_items: for sheet_name, sheet_content in sheet_items.items(): - logger.debug("ITEM COUNT:"+str(len(sheet_content))) + logger.debug("ITEM COUNT:" + str(len(sheet_content))) if len(sheet_content) > 0: final_sheet_to_print[sheet_name] = sheet_content cnt_sheet_to_print += 1 @@ -74,7 +71,7 @@ def remove_empty_sheet(sheet_items): if cnt_sheet_to_print != 0: success = True if len(skip_sheet_name) > 0: - logger.warn("* Empty sheet(not printed):"+ str(skip_sheet_name)) + logger.warn("* Empty sheet(not printed):" + str(skip_sheet_name)) except Exception as ex: logger.warn("* Warning:"+str(ex)) @@ -157,7 +154,7 @@ def merge_excels(find_excel_dir, final_out): if len([name for name in files if name.endswith(_find_extension)]) > 0: writer = pd.ExcelWriter(final_out) - df = pd.DataFrame() + for file in files: if file.endswith(_find_extension): f_short_name = os.path.splitext( diff --git a/tests/test_excel.py b/tests/test_excel.py index db0f09c..c3c92fd 100755 --- a/tests/test_excel.py +++ b/tests/test_excel.py @@ -9,7 +9,7 @@ def main(): logger = init_log("test_result/excel/log_write_excel.txt") logger.warning("TESTING - Writing an excel") - + sheet_contents = {} src_sheet_items = [['run_scancode.py', 'fosslight_source', '3.0.6', 'Apache-2.0', 'https://github.com/LGE-OSS/fosslight_source', diff --git a/tests/test_help.py b/tests/test_help.py index fab8e3e..3bfce76 100755 --- a/tests/test_help.py +++ b/tests/test_help.py @@ -13,6 +13,7 @@ def main(): """ helpMsg = PrintHelpMsg(_HELP_MESSAGE_TEST) helpMsg.print_help_msg(True) - + + if __name__ == '__main__': main() diff --git a/tests/test_log.py b/tests/test_log.py index 74cd8ff..4c4b22b 100755 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -8,10 +8,11 @@ from _print_log import print_log from _print_log_with_another_logger import print_log_another_logger + def main(): logger = init_log("test_result/log_file1.txt") logger.warning("TESTING LOG - from 1st Module") - + result_log = init_log_item("fosslight_util") _str_final_result_log = yaml.safe_dump(result_log, allow_unicode=True) logger.warning(_str_final_result_log) @@ -19,5 +20,6 @@ def main(): print_log() print_log_another_logger() + if __name__ == '__main__': main() diff --git a/tests/test_timer.py b/tests/test_timer.py index 334fcc4..3d05c79 100755 --- a/tests/test_timer.py +++ b/tests/test_timer.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021 LG Electronics Inc. # SPDX-License-Identifier: Apache-2.0 -import os import time from fosslight_util.timer_thread import TimerThread diff --git a/tox.ini b/tox.ini index 7e44441..021556a 100644 --- a/tox.ini +++ b/tox.ini @@ -8,9 +8,18 @@ basepython= python3.6 whitelist_externals = cat ls +[flake8] +max-line-length = 130 +exclude = .tox/* + +[pytest] +filterwarnings = ignore::DeprecationWarning + [testenv:test_run] setenv = PYTHONPATH=. +deps = + -r{toxinidir}/requirements-dev.txt commands = # Test - print help msg @@ -28,3 +37,5 @@ commands = cat test_result/excel/OSS-Report.csv # Test - timer python tests/test_timer.py + # Test - check PEP8 + pytest -v --flake8 \ No newline at end of file