Skip to content

Commit 96c5cd0

Browse files
committed
Apply Flake8 to check PEP8
1 parent 2d204fa commit 96c5cd0

File tree

7 files changed

+39
-27
lines changed

7 files changed

+39
-27
lines changed

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ typecode_libmagic
44
XlsxWriter
55
fosslight_util
66
PyYAML
7+
pytest
8+
pytest-cov
9+
pytest-flake8

src/fosslight_source/_help.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,32 @@
55
from fosslight_util.help import PrintHelpMsg
66

77
_HELP_MESSAGE_SOURCE = """
8-
Usage: fosslight_source [option1] <arg1> [option2] <arg2>...
8+
Usage: fosslight_source [option1] <arg1> [option2] <arg2>...
99
10-
FOSSLight Source uses ScanCode, a source code scanner, to detect the copyright and license phrases contained in the file.
11-
Some files (ex- build script), binary files, directory and files in specific directories (ex-test) are excluded from the result.
12-
And removes words such as “-only” and “-old-style” from the license name to be printed. The output result is generated in Excel format.
10+
FOSSLight Source uses ScanCode, a source code scanner, to detect the copyright and license phrases
11+
contained in the file. Some files (ex- build script), binary files, directory and files in specific
12+
directories (ex-test) are excluded from the result.
13+
And removes words such as “-only” and “-old-style” from the license name to be printed.
14+
The output result is generated in Excel format.
1315
1416
Options:
1517
Mandatory
1618
-p <source_path>\t\t Path to analyze source
17-
19+
1820
Optional
1921
-h\t\t\t\t Print help message
2022
-j\t\t\t\t Generate additional result of executing ScanCode in json format
2123
-o <file_name>\t\t Output file name"""
2224

2325
_HELP_MESSAGE_CONVERT = """
24-
Usage: fosslight_convert [option1] <arg1> [option2] <arg2>...
26+
Usage: fosslight_convert [option1] <arg1> [option2] <arg2>...
2527
2628
FOSSLigtht_convert converts the result of executing ScanCode in json format into OSS Report format.
2729
2830
Options:
2931
Mandatory
3032
-p <path_dir>\t\t Path of ScanCode json files
31-
33+
3234
Optional
3335
-h\t\t\t\t Print help message
3436
-o <file_name>\t\t Output file name"""
@@ -38,6 +40,7 @@ def print_help_msg_source():
3840
helpMsg = PrintHelpMsg(_HELP_MESSAGE_SOURCE)
3941
helpMsg.print_help_msg(True)
4042

43+
4144
def print_help_msg_convert():
4245
helpMsg = PrintHelpMsg(_HELP_MESSAGE_CONVERT)
4346
helpMsg.print_help_msg(True)

src/fosslight_source/_parsing_scancode_file_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def parsing_file_item(scancode_file_list):
100100

101101
rc = True
102102
scancode_file_item = []
103-
msg ="TOTAL FILE COUNT: "+str(len(scancode_file_list))+"\n"
103+
msg = "TOTAL FILE COUNT: " + str(len(scancode_file_list)) + "\n"
104104

105105
prev_dir = ""
106106
prev_dir_value = False

src/fosslight_source/convert_scancode.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import os
88
import sys
99
import json
10-
import platform
1110
from datetime import datetime
1211
import logging
1312
import fosslight_util.constant as constant
@@ -51,25 +50,25 @@ def convert_json_to_excel(scancode_json, excel_name):
5150
file_list, key=lambda row: (''.join(row.licenses)))
5251
sheet_list["SRC_" + file_name] = [scan_item.get_row_to_print() for scan_item in file_list]
5352
except Exception as ex:
54-
logger.warning("Error parsing "+file+":"+str(ex))
53+
logger.warning("Error parsing "+file+":" + str(ex))
5554

5655
success_to_write, writing_msg = write_excel_and_csv(excel_name, sheet_list)
57-
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
56+
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
5857
if success_to_write:
59-
_result_log["OSS Report"] = excel_name+".xlsx"
58+
_result_log["OSS Report"] = excel_name + ".xlsx"
6059

6160
except Exception as ex:
6261
success = False
6362
logger.warning(str(ex))
6463

65-
scan_result_msg = str(success)+" "+msg
64+
scan_result_msg = str(success) + " " + msg
6665
_result_log["Scan Result"] = scan_result_msg.strip()
6766

6867
try:
6968
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
7069
logger.info(_str_final_result_log)
7170
except Exception as ex:
72-
logger.warning("Failed to print result log.: "+ str(ex))
71+
logger.warning("Failed to print result log.: " + str(ex))
7372

7473
return file_list
7574

@@ -80,10 +79,10 @@ def get_detected_licenses_from_scancode(scancode_json_file):
8079
logger.info("Start parsing " + scancode_json_file)
8180
with open(scancode_json_file, "r") as st_json:
8281
st_python = json.load(st_json)
83-
rc, file_list, msg= parsing_file_item(st_python["files"])
84-
logger.info("|---"+msg)
82+
rc, file_list, msg = parsing_file_item(st_python["files"])
83+
logger.info("|---" + msg)
8584
except Exception as error:
86-
logger.warning("Parsing "+scancode_json_file+":"+str(error))
85+
logger.warning("Parsing " + scancode_json_file + ":" + str(error))
8786
logger.info("|---Number of files detected: " + str(len(file_list)))
8887
return file_list
8988

@@ -106,7 +105,7 @@ def main():
106105
elif opt == "-o":
107106
output_file_name = arg
108107
except Exception as error:
109-
pass
108+
print("Wrong option " + str(error))
110109

111110
if output_file_name == "":
112111
output_dir = os.getcwd()

src/fosslight_source/run_scancode.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,27 @@ def run_scan(path_to_scan, output_file_name="",
113113

114114
success_to_write, writing_msg = write_excel_and_csv(
115115
output_file, sheet_list)
116-
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
116+
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
117117
if success_to_write:
118-
_result_log["OSS Report"] = output_file +".xlsx"
118+
_result_log["OSS Report"] = output_file + ".xlsx"
119119
except Exception as ex:
120120
success = False
121121
msg = str(ex)
122-
logger.error("Analyze "+path_to_scan+":"+msg)
122+
logger.error("Analyze " + path_to_scan + ":" + msg)
123123
else:
124124
success = False
125125
msg = "Check the path to scan. :" + path_to_scan
126126

127127
if not return_results:
128128
result_list = []
129-
scan_result_msg = str(success)+" "+msg
129+
scan_result_msg = str(success) + " " + msg
130130
_result_log["Scan Result"] = scan_result_msg.strip()
131131
_result_log["Output Directory"] = output_dir
132132
try:
133133
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
134134
logger.info(_str_final_result_log)
135135
except Exception as ex:
136-
logger.warning("Failed to print result log. "+ str(ex))
136+
logger.warning("Failed to print result log. " + str(ex))
137137
return success, _result_log["Scan Result"], result_list
138138

139139

test/cli_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
# Copyright (c) 2020 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
import getopt
76
import os
8-
import sys
9-
import json
107
from datetime import datetime
118
import logging
129
import fosslight_util.constant as constant
@@ -19,7 +16,6 @@
1916
def main():
2017
global logger
2118

22-
argv = sys.argv[1:]
2319
path_to_find_bin = os.path.abspath("test/test")
2420
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
2521
output_file_name = ""

tox.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ install_command = pip install {opts} {packages}
77
basepython= python3.6
88
whitelist_externals = cat
99

10+
[flake8]
11+
max-line-length = 130
12+
per-file-ignores = .tox/*
13+
14+
[pytest]
15+
filterwarnings = ignore::DeprecationWarning
16+
1017
[testenv:test_run]
18+
deps =
19+
-r{toxinidir}/requirements.txt
20+
1121
setenv =
1222
PYTHONPATH=.
1323

@@ -19,3 +29,4 @@ commands =
1929
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result
2030
cat test_convert/convert_result.csv
2131
python test/cli_test.py
32+
pytest -v --flake8

0 commit comments

Comments
 (0)