Skip to content

Commit

Permalink
Supports for excluding paths from checking (#200)
Browse files Browse the repository at this point in the history
Signed-off-by: SeongjunJo <[email protected]>
  • Loading branch information
SeongjunJo authored Jun 5, 2024
1 parent 046a5cc commit ccae838
Show file tree
Hide file tree
Showing 9 changed files with 1,875 additions and 8 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lxml
virtualenv
pyyaml
lastversion
fosslight_util>=1.4.40
fosslight_util>=1.4.43
PyGithub
requirements-parser
defusedxml
Expand Down
1 change: 1 addition & 0 deletions src/fosslight_dependency/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
-m <package_manager>\t Enter the package manager.
\t(npm, maven, gradle, pip, pub, cocoapods, android, swift, carthage, go, nuget, helm)
-p <input_path>\t\t Enter the path where the script will be run.
-e <exclude_path>\t\t Enter the path where the analysis will not be performed.
-o <output_path>\t\t Output path
\t\t\t\t\t(If you want to generate the specific file name, add the output path with file name.)
-f <format>\t\t\t Output file format (excel, csv, opossum, yaml, spdx-tag, spdx-yaml, spdx-json, spdx-xml)
Expand Down
28 changes: 21 additions & 7 deletions src/fosslight_dependency/run_dependency_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
_exclude_dir = ['node_moduels', 'venv']


def find_package_manager(input_dir):
def find_package_manager(input_dir, abs_path_to_exclude=[]):
ret = True
manifest_file_name = []
for value in const.SUPPORT_PACKAE.values():
Expand All @@ -52,7 +52,14 @@ def find_package_manager(input_dir):
continue
if os.path.basename(parent) in _exclude_dir:
continue
if os.path.abspath(parent) in abs_path_to_exclude:
continue
for file in files:
file_path = os.path.join(parent, file)
file_abs_path = os.path.abspath(file_path)
if any(os.path.commonpath([file_abs_path, exclude_path]) == exclude_path
for exclude_path in abs_path_to_exclude):
continue
if file in manifest_file_name:
found_manifest_file.append(file)
if len(found_manifest_file) > 0:
Expand Down Expand Up @@ -83,8 +90,9 @@ def find_package_manager(input_dir):
return ret, found_package_manager, input_dir


def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='', pip_activate_cmd='', pip_deactivate_cmd='',
output_custom_dir='', app_name=const.default_app_name, github_token='', format='', direct=True):
def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='', pip_activate_cmd='',
pip_deactivate_cmd='', output_custom_dir='', app_name=const.default_app_name,
github_token='', format='', direct=True, path_to_exclude=[]):
global logger

ret = True
Expand Down Expand Up @@ -117,7 +125,8 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
sys.exit(1)

logger, _result_log = init_log(os.path.join(output_path, "fosslight_log_dep_" + _start_time + ".txt"),
True, logging.INFO, logging.DEBUG, _PKG_NAME)
True, logging.INFO, logging.DEBUG, _PKG_NAME, "", path_to_exclude)
abs_path_to_exclude = [os.path.abspath(os.path.join(input_dir, path)) for path in path_to_exclude]

logger.info(f"Tool Info : {_result_log['Tool Info']}")

Expand Down Expand Up @@ -151,7 +160,7 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
found_package_manager = {}
if autodetect:
try:
ret, found_package_manager, input_dir = find_package_manager(input_dir)
ret, found_package_manager, input_dir = find_package_manager(input_dir, abs_path_to_exclude)
os.chdir(input_dir)
except Exception as e:
logger.error(f'Fail to find package manager: {e}')
Expand Down Expand Up @@ -188,7 +197,8 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
fail_pm.append(f"{pm} ({', '.join(manifest_file_name)})")
cover = CoverItem(tool_name=_PKG_NAME,
start_time=_start_time,
input_path=input_dir)
input_path=input_dir,
exclude_path=path_to_exclude)
cover_comment_arr = []
if len(found_package_manager.keys()) > 0:
if len(success_pm) > 0:
Expand Down Expand Up @@ -231,6 +241,7 @@ def main():
package_manager = ''
input_dir = ''
output_dir = ''
path_to_exclude = []
pip_activate_cmd = ''
pip_deactivate_cmd = ''
output_custom_dir = ''
Expand All @@ -244,6 +255,7 @@ def main():
parser.add_argument('-v', '--version', action='store_true', required=False)
parser.add_argument('-m', '--manager', nargs=1, type=str, default='', required=False)
parser.add_argument('-p', '--path', nargs=1, type=str, required=False)
parser.add_argument('-e', '--exclude', nargs='*', required=False, default=[])
parser.add_argument('-o', '--output', nargs=1, type=str, required=False)
parser.add_argument('-a', '--activate', nargs=1, type=str, default='', required=False)
parser.add_argument('-d', '--deactivate', nargs=1, type=str, default='', required=False)
Expand All @@ -268,6 +280,8 @@ def main():
package_manager = ''.join(args.manager)
if args.path: # -p option
input_dir = ''.join(args.path)
if args.exclude: # -e option
path_to_exclude = args.exclude
if args.output: # -o option
output_dir = ''.join(args.output)
if args.activate: # -a option
Expand Down Expand Up @@ -301,7 +315,7 @@ def main():
sys.exit(0)

run_dependency_scanner(package_manager, input_dir, output_dir, pip_activate_cmd, pip_deactivate_cmd,
output_custom_dir, app_name, github_token, format, direct)
output_custom_dir, app_name, github_token, format, direct, path_to_exclude)


if __name__ == '__main__':
Expand Down
66 changes: 66 additions & 0 deletions tests/test_exclude/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: iamport_flutter
description: Plugin that allows Flutter to use Iamport payment and certification functions.
version: 0.10.0-dev.1
homepage: https://github.com/iamport/iamport_flutter

environment:
sdk: '>=2.12.0 <3.0.0'
flutter: ">=2.0.0"

dependencies:
flutter:
sdk: flutter
iamport_webview_flutter: ^3.0.1
url_launcher: ^6.0.4
dev_dependencies:
dart_json_mapper: ^2.1.0
uni_links: ^0.5.1
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
# This section identifies this Flutter project as a plugin project.
# The androidPackage and pluginClass identifiers should not ordinarily
# be modified. They are used by the tooling to maintain consistency when
# adding or updating assets for this project.
plugin:
platforms:
android:
package: kr.iamport.iamport_flutter
pluginClass: IamportFlutterPlugin
ios:
pluginClass: IamportFlutterPlugin

uses-material-design: true

# To add assets to your plugin package, add an assets section, like this:
assets:
- assets/images/iamport-logo.png

#
# For details regarding assets in packages, see
# https://flutter.dev/assets-and-images/#from-packages
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# To add custom fonts to your plugin package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/custom-fonts/#from-packages
2 changes: 2 additions & 0 deletions tests/test_exclude/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openpyxl
virtualenv
Loading

0 comments on commit ccae838

Please sign in to comment.