Skip to content

Commit 4b8d81a

Browse files
authored
Merge pull request #18 from fosslight/develop
Apply Flake8 to check PEP8
2 parents 45b9ce8 + 6239c27 commit 4b8d81a

File tree

7 files changed

+69
-66
lines changed

7 files changed

+69
-66
lines changed

.github/workflows/publish-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Commit files
2323
run: |
2424
git config --local user.name "github-actions[bot]"
25-
git add .
25+
git add CHANGELOG.md
2626
git commit -m "Update ChangeLog"
2727
- name: Push changes
2828
uses: ad-m/github-push-action@master

setup.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,27 @@
1717

1818
if __name__ == "__main__":
1919
setup(
20-
name = 'fosslight_dependency',
21-
version = __version__,
22-
package_dir = {"": "src"},
23-
packages = find_packages(where='src'),
24-
description = 'FOSSLight Dependency',
25-
long_description = reamdme,
26-
long_description_content_type = 'text/markdown',
27-
license = 'Apache-2.0',
28-
author = 'LG Electronics',
29-
url = 'https://github.com/fosslight/fosslight_dependency',
30-
download_url = 'https://github.com/fosslight/fosslight_dependency',
31-
classifiers = ['Programming Language :: Python :: 3.6',
32-
'License :: OSI Approved :: Apache Software License'],
33-
install_requires = required,
34-
package_data = {'fosslight_dependency':['third_party/nomos/nomossa','third_party/askalono/askalono.exe','third_party/askalono/askalono_macos']},
35-
include_package_data = True,
36-
entry_points = {
20+
name='fosslight_dependency',
21+
version=__version__,
22+
package_dir={"": "src"},
23+
packages=find_packages(where='src'),
24+
description='FOSSLight Dependency',
25+
long_description=reamdme,
26+
long_description_content_type='text/markdown',
27+
license='Apache-2.0',
28+
author='LG Electronics',
29+
url='https://github.com/fosslight/fosslight_dependency',
30+
download_url='https://github.com/fosslight/fosslight_dependency',
31+
classifiers=['Programming Language :: Python :: 3.6',
32+
'License :: OSI Approved :: Apache Software License'],
33+
install_requires=required,
34+
package_data={'fosslight_dependency': ['third_party/nomos/nomossa',
35+
'third_party/askalono/askalono.exe',
36+
'third_party/askalono/askalono_macos']},
37+
include_package_data=True,
38+
entry_points={
3739
"console_scripts": [
3840
"fosslight_dependency = fosslight_dependency.analyze_dependency:main"
39-
]
40-
}
41+
]
42+
}
4143
)

src/fosslight_dependency/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from ._version import __version__

src/fosslight_dependency/_help.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Usage: fosslight_dependency [option1] <arg1> [option2] <arg2>...
99
1010
FOSSLight Dependency utilizes the open source software for analyzing each package manager dependencies.
11-
We choose the open source software for each package manager that shows not only the direct dependencies
11+
We choose the open source software for each package manager that shows not only the direct dependencies
1212
but also the transitive dependencies including the information of dependencies such as oss name, oss version and license name.
1313
1414
Each package manager uses the results of the following software:
@@ -25,11 +25,11 @@
2525
-m <package_manager>\t Enther the package manager(npm, maven, gradle, pip, pub, cocoapods).
2626
-p <input_path>\t\t Enter the path where the script will be run.
2727
-o <output_path>\t\t Enter the path where the result file will be generated.
28-
28+
2929
Required only for pypi
3030
-a <activate_cmd>\t\t Virtual environment activate command(ex, 'conda activate (venv name)')
3131
-d <deactivate_cmd>\t\t Virtual environment deactivate command(ex, 'conda deactivate')
32-
32+
3333
Optional only for gradle, maven
3434
-c <dir_name>\t\t Enter the customized build output directory name(default: target)
3535
"""

src/fosslight_dependency/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.7"
1+
__version__ = "3.0.7"

src/fosslight_dependency/analyze_dependency.py

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@
88
import os
99
import sys
1010
import argparse
11-
from openpyxl import load_workbook, Workbook
1211
import platform
1312
import shutil
1413
import subprocess
1514
import json
1615
import re
1716
from xml.etree.ElementTree import parse
1817
from bs4 import BeautifulSoup
19-
import pkg_resources
2018
import yaml
2119
from lastversion import lastversion
2220
from fosslight_util.set_log import init_log
2321
from datetime import datetime
24-
from . import __version__
22+
from ._version import __version__
2523
from fosslight_util.write_excel import write_excel_and_csv
2624
from ._help import print_help_msg
2725

@@ -173,7 +171,7 @@ def check_virtualenv_arg():
173171

174172
python_version = check_python_version()
175173

176-
venv_path = os.path.join(CUR_PATH,venv_tmp_dir)
174+
venv_path = os.path.join(CUR_PATH, venv_tmp_dir)
177175

178176
if python_version == 2:
179177
create_venv_command = "virtualenv -p python " + venv_tmp_dir
@@ -327,7 +325,8 @@ def open_input_file():
327325

328326
logger.error("Please check the below thing first.")
329327
logger.error(" 1.Did you run the license-maven-plugin?")
330-
logger.error(" 2.Or if your project has the customized build output directory, then use '-c' option with your customized build output directory name")
328+
logger.error(" 2.Or if your project has the customized build output directory, \
329+
then use '-c' option with your customized build output directory name")
331330
logger.error(" $ fosslight_dependency -c output")
332331
sys.exit(1)
333332

@@ -343,8 +342,8 @@ def close_input_file(input_fp):
343342
def make_custom_json(tmp_custom_json):
344343
with open(tmp_custom_json, 'w', encoding='utf8') as custom:
345344
custom.write(
346-
"{\n\t\"name\": \"\",\n\t\"version\": \"\",\n\t\"licenses\": \"\",\n\t\"repository\": \"\",\n\t\"url\": \"\",\n\t\"copyright\": \"\",\n\t\"licenseText\": \"\"\n}\n".encode().decode(
347-
"utf-8"))
345+
"{\n\t\"name\": \"\",\n\t\"version\": \"\",\n\t\"licenses\": \"\",\n\t\"repository\": \
346+
\"\",\n\t\"url\": \"\",\n\t\"copyright\": \"\",\n\t\"licenseText\": \"\"\n}\n".encode().decode("utf-8"))
348347

349348

350349
def start_license_checker():
@@ -443,7 +442,7 @@ def resource_path(relative_path):
443442

444443
def check_license_scanner(os_name):
445444
global license_scanner_url, license_scanner_bin
446-
445+
447446
if os_name == 'Linux':
448447
license_scanner_url = license_scanner_url_linux
449448
elif os_name == 'Darwin':
@@ -508,7 +507,7 @@ def check_and_run_license_scanner(file_dir, os_name):
508507

509508
except Exception as ex:
510509
logger.info("There are some errors for the license scanner binary")
511-
logger.info("Error:"+ str(ex))
510+
logger.info("Error:" + str(ex))
512511
license_name = ""
513512

514513
return license_name
@@ -574,8 +573,8 @@ def parse_and_generate_output_pip(tmp_file_name):
574573
sheet_list = {}
575574

576575
try:
577-
with open(tmp_file_name, 'r', encoding='utf-8') as json_file:
578-
json_data = json.load(json_file)
576+
with open(tmp_file_name, 'r', encoding='utf-8') as json_file:
577+
json_data = json.load(json_file)
579578

580579
sheet_list["SRC"] = []
581580

@@ -596,7 +595,7 @@ def parse_and_generate_output_pip(tmp_file_name):
596595
sheet_list["SRC"].append(['pip', oss_name, oss_version, license_name, dn_loc, homepage, '', '', ''])
597596

598597
except Exception as ex:
599-
logger.error("Error:"+ str(ex))
598+
logger.error("Error:" + str(ex))
600599

601600
if os.path.isdir(venv_tmp_dir):
602601
shutil.rmtree(venv_tmp_dir)
@@ -608,7 +607,7 @@ def parse_and_generate_output_pip(tmp_file_name):
608607
def parse_and_generate_output_npm(tmp_file_name):
609608
with open(tmp_file_name, 'r', encoding='utf8') as json_file:
610609
json_data = json.load(json_file)
611-
610+
612611
sheet_list = {}
613612
sheet_list["SRC"] = []
614613

@@ -625,19 +624,14 @@ def parse_and_generate_output_npm(tmp_file_name):
625624
license_name = ''
626625

627626
oss_version = d['version']
628-
627+
629628
if d['repository']:
630629
dn_loc = d['repository']
631630
else:
632631
dn_loc = dn_url + oss_init_name + '/v/' + oss_version
633632

634633
homepage = dn_url + oss_init_name
635634

636-
if d['copyright']:
637-
copyright_text = d['copyright']
638-
else:
639-
copyright_text = ''
640-
641635
multi_license = check_multi_license(license_name)
642636

643637
if multi_license == 1:
@@ -649,7 +643,7 @@ def parse_and_generate_output_npm(tmp_file_name):
649643
license_name = license_name.replace(",", "")
650644

651645
sheet_list["SRC"].append(['package.json', oss_name, oss_version, license_name, dn_loc, homepage, '', '', ''])
652-
646+
653647
return sheet_list
654648

655649

@@ -741,7 +735,7 @@ def preprocess_pub_result(input_file):
741735

742736

743737
def parse_and_generate_output_pub(tmp_file_name):
744-
global license_scanner_bin, tmp_license_txt_file_name
738+
global license_scanner_bin, tmp_license_txt_file_name
745739

746740
json_txt = preprocess_pub_result(tmp_file_name)
747741
json_data = json.loads(json_txt)
@@ -752,7 +746,6 @@ def parse_and_generate_output_pub(tmp_file_name):
752746
os_name = check_os()
753747
check_license_scanner(os_name)
754748

755-
idx = 1
756749
for key in json_data:
757750
oss_origin_name = json_data[key]['name']
758751
oss_name = "pub:" + oss_origin_name
@@ -790,7 +783,7 @@ def compile_pods_item(pods_item, spec_repo_list, pod_in_sepc_list, pod_not_in_sp
790783
oss_info = []
791784
oss_info.append(oss_name)
792785
oss_info.append(oss_version)
793-
786+
794787
if oss_name in spec_repo_list:
795788
pod_in_sepc_list.append(oss_info)
796789
spec_repo_list.remove(oss_name)
@@ -815,22 +808,22 @@ def parse_and_generate_output_cocoapods(input_fp):
815808
for pods_list in podfile_yaml['PODS']:
816809
if not isinstance(pods_list, str):
817810
for pods_list_key, pods_list_item in pods_list.items():
818-
pod_in_sepc_list, spec_repo_list, pod_not_in_spec_list = compile_pods_item(pods_list_key, spec_repo_list, pod_in_sepc_list, pod_not_in_spec_list)
811+
pod_in_sepc_list, spec_repo_list, pod_not_in_spec_list = \
812+
compile_pods_item(pods_list_key, spec_repo_list, pod_in_sepc_list, pod_not_in_spec_list)
819813
else:
820-
pod_in_sepc_list, spec_repo_list, pod_not_in_spec_list = compile_pods_item(pods_list, spec_repo_list, pod_in_sepc_list, pod_not_in_spec_list)
814+
pod_in_sepc_list, spec_repo_list, pod_not_in_spec_list = \
815+
compile_pods_item(pods_list, spec_repo_list, pod_in_sepc_list, pod_not_in_spec_list)
821816

822817
if len(spec_repo_list) != 0:
823818
for spec_in_item in spec_repo_list:
824819
spec_oss_name_adding_core = spec_in_item + "/Core"
825820
for pod_not_item in pod_not_in_spec_list:
826821
if spec_oss_name_adding_core == pod_not_item[0]:
827822
pod_in_sepc_list.append([spec_in_item, pod_not_item[1]])
828-
829823

830824
sheet_list = {}
831825
sheet_list["SRC"] = []
832826

833-
idx = 1
834827
for pod_oss in pod_in_sepc_list:
835828

836829
search_oss_name = ""
@@ -840,7 +833,7 @@ def parse_and_generate_output_cocoapods(input_fp):
840833
else:
841834
search_oss_name += alphabet_oss
842835

843-
command = 'pod spec which --regex ' + '^' +search_oss_name + '$'
836+
command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
844837
spec_which = os.popen(command).readline()
845838
if spec_which.startswith('[!]'):
846839
logger.error("### Error Message ###")
@@ -849,16 +842,14 @@ def parse_and_generate_output_cocoapods(input_fp):
849842

850843
file_path = spec_which.rstrip().split(os.path.sep)
851844
if file_path[0] == '':
852-
file_path_without_version = os.path.join(os.sep,*file_path[:-2])
845+
file_path_without_version = os.path.join(os.sep, *file_path[:-2])
853846
else:
854847
file_path_without_version = os.path.join(*file_path[:-2])
855-
spec_file_path = os.path.join(file_path_without_version,pod_oss[1],file_path[-1])
848+
spec_file_path = os.path.join(file_path_without_version, pod_oss[1], file_path[-1])
856849

857850
with open(spec_file_path, 'r', encoding='utf8') as json_file:
858851
json_data = json.load(json_file)
859852

860-
keys = [key for key in json_data]
861-
862853
oss_origin_name = json_data['name']
863854
oss_name = "cocoapods:" + oss_origin_name
864855
oss_version = json_data['version']
@@ -901,7 +892,7 @@ def main_pip():
901892
# Remove temporary output file.
902893
if os.path.isfile(tmp_file_name):
903894
os.remove(tmp_file_name)
904-
895+
905896
return sheet_list
906897

907898

@@ -935,7 +926,7 @@ def main_maven():
935926

936927
if not is_maven_first_try:
937928
clean_run_maven_plugin_output()
938-
929+
939930
return sheet_list
940931

941932

@@ -965,7 +956,7 @@ def main_pub():
965956

966957

967958
def main_cocoapods():
968-
959+
969960
# open Podfile.lock
970961
input_fp = open_input_file()
971962

@@ -977,14 +968,16 @@ def main_cocoapods():
977968

978969

979970
def main():
980-
981-
global PACKAGE, output_file_name, input_file_name, CUR_PATH, OUTPUT_RESULT_DIR, MANUAL_DETECT, OUTPUT_CUSTOM_DIR, dn_url, PIP_ACTIVATE, PIP_DEACTIVATE
982-
global license_scanner_url, license_scanner_bin, venv_tmp_dir, pom_backup, is_maven_first_try, tmp_license_txt_file_name, source_type, logger
971+
972+
global PACKAGE, output_file_name, input_file_name, CUR_PATH, OUTPUT_RESULT_DIR, \
973+
MANUAL_DETECT, OUTPUT_CUSTOM_DIR, dn_url, PIP_ACTIVATE, PIP_DEACTIVATE
974+
global license_scanner_url, license_scanner_bin, venv_tmp_dir, pom_backup, \
975+
is_maven_first_try, tmp_license_txt_file_name, source_type, logger
983976

984977
start_time = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
985978

986979
parse_option()
987-
logger = init_log(os.path.join(OUTPUT_RESULT_DIR, "fosslight_dependency_log_"+start_time+".txt"), True, 20, 10)
980+
logger = init_log(os.path.join(OUTPUT_RESULT_DIR, "fosslight_dependency_log_" + start_time + ".txt"), True, 20, 10)
988981

989982
# Check the latest version
990983
latest_version = lastversion.has_update(repo="fosslight_dependency", at='pip', current_version=__version__)
@@ -1032,7 +1025,7 @@ def main():
10321025
input_file_name = "Podfile.lock"
10331026
output_file_name = "cocoapods_dependency_output"
10341027
source_type = ['git', 'http', 'svn', 'hg']
1035-
1028+
10361029
else:
10371030
logger.error("### Error Message ###")
10381031
logger.error("You enter the wrong first argument.")

tox.ini

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ skipdist = true
66
install_command = pip install {opts} {packages}
77
basepython= python3.6
88

9+
[pytest]
10+
filterwarnings = ignore::DeprecationWarning
11+
12+
[flake8]
13+
max-line-length = 130
14+
exclude = .tox/*
15+
ignore = E722
16+
917
[testenv:test_run]
1018
deps =
11-
-r{toxinidir}/requirements.txt
19+
-r{toxinidir}/requirements-dev.txt
1220

1321
setenv =
1422
PYTHONPATH=.
1523

1624
commands =
1725
fosslight_dependency -h
26+
pytest -v --flake8

0 commit comments

Comments
 (0)