Skip to content

Commit 69d2070

Browse files
authored
Merge pull request #11 from fosslight/develop
Apply Flake8 to check PEP8
2 parents 7a2f2ab + 11678fb commit 69d2070

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
tox
2+
pytest
3+
pytest-cov
4+
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def get_error_from_header(header_item):
108108
error_cnt = len(errors)
109109
if error_cnt > 0:
110110
has_error = True
111-
str_error ='{}...({})'.format(errors[0], error_cnt)
111+
str_error = '{}...({})'.format(errors[0], error_cnt)
112112
break
113113
except Exception as ex:
114114
logger.debug("error_parsing_header:"+str(ex))
@@ -119,7 +119,7 @@ def parsing_file_item(scancode_file_list, has_error):
119119

120120
rc = True
121121
scancode_file_item = []
122-
msg ="TOTAL FILE COUNT: "+str(len(scancode_file_list))+"\n"
122+
msg = "TOTAL FILE COUNT: " + str(len(scancode_file_list)) + "\n"
123123

124124
prev_dir = ""
125125
prev_dir_value = False
@@ -147,7 +147,7 @@ def parsing_file_item(scancode_file_list, has_error):
147147
if has_error and "scan_errors" in file:
148148
error_msg = file["scan_errors"]
149149
if len(error_msg) > 0:
150-
logger.debug("test_msg"+file_path+":"+ str(error_msg))
150+
logger.debug("test_msg" + file_path + ":" + str(error_msg))
151151
result_item.set_comment(",".join(error_msg))
152152
scancode_file_item.append(result_item)
153153
continue

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,12 +50,12 @@ 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
@@ -69,7 +68,7 @@ def convert_json_to_excel(scancode_json, excel_name):
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

@@ -81,12 +80,12 @@ def get_detected_licenses_from_scancode(scancode_json_file):
8180
with open(scancode_json_file, "r") as st_json:
8281
st_python = json.load(st_json)
8382
has_error, str_error = get_error_from_header(st_python["headers"])
84-
rc, file_list, msg= parsing_file_item(st_python["files"], has_error)
83+
rc, file_list, msg = parsing_file_item(st_python["files"], has_error)
8584
logger.info("|---"+msg)
8685
if has_error:
8786
logger.info("|---Scan error:"+str_error)
8887
except Exception as error:
89-
logger.warning("Parsing "+scancode_json_file+":"+str(error))
88+
logger.warning("Parsing " + scancode_json_file + ":" + str(error))
9089
logger.info("|---Number of files detected: " + str(len(file_list)))
9190
return file_list
9291

@@ -108,8 +107,8 @@ def main():
108107
path_to_find_bin = arg
109108
elif opt == "-o":
110109
output_file_name = arg
111-
except Exception as error:
112-
pass
110+
except Exception:
111+
print_help_msg_convert()
113112

114113
if output_file_name == "":
115114
output_dir = os.getcwd()
@@ -118,7 +117,7 @@ def main():
118117
oss_report_name = output_file_name
119118
output_dir = os.path.dirname(os.path.abspath(output_file_name))
120119

121-
logger = init_log(os.path.join(output_dir, "fosslight_src_log_"+start_time+".txt"))
120+
logger = init_log(os.path.join(output_dir, "fosslight_src_log_" + start_time + ".txt"))
122121

123122
convert_json_to_excel(path_to_find_bin, oss_report_name)
124123

src/fosslight_source/run_scancode.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,19 @@ def run_scan(path_to_scan, output_file_name="",
9898
processes=num_cores,
9999
output_json_pp=output_json_file,
100100
only_findings=True)
101+
101102
if not rc:
102103
msg = "Source code analysis failed."
103104
success = False
105+
104106
if results:
105107
sheet_list = {}
106108
has_error = False
107109
if "headers" in results:
108110
has_error, error_msg = get_error_from_header(results["headers"])
109111
if has_error:
110112
_result_log["Error_files"] = error_msg
111-
msg = "Failed to analyze :"+ error_msg
113+
msg = "Failed to analyze :" + error_msg
112114
if "files" in results:
113115
rc, result_list, parsing_msg = parsing_file_item(results["files"], has_error)
114116
_result_log["Parsing Log"] = parsing_msg
@@ -121,13 +123,13 @@ def run_scan(path_to_scan, output_file_name="",
121123

122124
success_to_write, writing_msg = write_excel_and_csv(
123125
output_file, sheet_list)
124-
logger.info("Writing excel :"+str(success_to_write)+ " "+writing_msg)
126+
logger.info("Writing excel :" + str(success_to_write) + " " + writing_msg)
125127
if success_to_write:
126-
_result_log["OSS Report"] = output_file +".xlsx"
128+
_result_log["OSS Report"] = output_file + ".xlsx"
127129
except Exception as ex:
128130
success = False
129131
msg = str(ex)
130-
logger.error("Analyze "+path_to_scan+":"+msg)
132+
logger.error("Analyze " + path_to_scan + ":" + msg)
131133
else:
132134
success = False
133135
msg = "Check the path to scan. :" + path_to_scan
@@ -142,7 +144,7 @@ def run_scan(path_to_scan, output_file_name="",
142144
_str_final_result_log = yaml.safe_dump(_result_log, allow_unicode=True, sort_keys=True)
143145
logger.info(_str_final_result_log)
144146
except Exception as ex:
145-
logger.warning("Failed to print result log. "+ str(ex))
147+
logger.warning("Failed to print result log. " + str(ex))
146148
return success, _result_log["Scan Result"], result_list
147149

148150

tests/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("tests/test_files/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+
exclude = .tox/*
13+
14+
[pytest]
15+
filterwarnings = ignore::DeprecationWarning
16+
1017
[testenv:test_run]
18+
deps =
19+
-r{toxinidir}/requirements-dev.txt
20+
1121
setenv =
1222
PYTHONPATH=.
1323

@@ -20,3 +30,4 @@ commands =
2030
fosslight_convert -p test_scan/scan_result.json -o test_convert/convert_result
2131
cat test_convert/convert_result.csv
2232
python tests/cli_test.py
33+
pytest -v --flake8

0 commit comments

Comments
 (0)