fosslight-dependency 4.1.1__py3-none-any.whl → 4.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ from fosslight_dependency.package_manager.Go import Go
19
19
  from fosslight_dependency.package_manager.Nuget import Nuget
20
20
  from fosslight_dependency.package_manager.Helm import Helm
21
21
  from fosslight_dependency.package_manager.Unity import Unity
22
+ from fosslight_dependency.package_manager.Cargo import Cargo
22
23
  import fosslight_util.constant as constant
23
24
 
24
25
  logger = logging.getLogger(constant.LOGGER_NAME)
@@ -57,6 +58,8 @@ def analyze_dependency(package_manager_name, input_dir, output_dir, pip_activate
57
58
  package_manager = Helm(input_dir, output_dir)
58
59
  elif package_manager_name == const.UNITY:
59
60
  package_manager = Unity(input_dir, output_dir)
61
+ elif package_manager_name == const.CARGO:
62
+ package_manager = Cargo(input_dir, output_dir)
60
63
  else:
61
64
  logger.error(f"Not supported package manager name: {package_manager_name}")
62
65
  ret = False
@@ -24,13 +24,15 @@ _HELP_MESSAGE_DEPENDENCY = """
24
24
  Nuget (.NET)
25
25
  Helm (Kubernetes)
26
26
  Unity (Unity)
27
+ Cargo (Rust)
27
28
 
28
29
  Options:
29
30
  Optional
30
31
  -h\t\t\t\t Print help message.
31
32
  -v\t\t\t\t Print the version of the script.
32
33
  -m <package_manager>\t Enter the package manager.
33
- \t(npm, maven, gradle, pypi, pub, cocoapods, android, swift, carthage, go, nuget, helm)
34
+ \t(npm, maven, gradle, pypi, pub, cocoapods, android, swift, carthage,
35
+ \t go, nuget, helm, unity, cargo)
34
36
  -p <input_path>\t\t Enter the path where the script will be run.
35
37
  -e <exclude_path>\t\t Enter the path where the analysis will not be performed.
36
38
  -o <output_path>\t\t Output path
@@ -286,6 +286,8 @@ def get_url_to_purl(url, pkg_manager, oss_name='', oss_version=''):
286
286
  elif pkg_manager == 'carthage':
287
287
  if oss_version:
288
288
  purl = f'{purl}@{oss_version}'
289
+ elif pkg_manager == 'cargo':
290
+ purl = f'{purl_prefix}/{oss_name}@{oss_version}'
289
291
  except Exception:
290
292
  logger.debug('Fail to get purl. So use the link purl({purl}).')
291
293
  return purl
@@ -23,6 +23,7 @@ GO = 'go'
23
23
  NUGET = 'nuget'
24
24
  HELM = 'helm'
25
25
  UNITY = 'unity'
26
+ CARGO = 'cargo'
26
27
 
27
28
  # Supported package name and manifest file
28
29
  SUPPORT_PACKAE = {
@@ -38,7 +39,8 @@ SUPPORT_PACKAE = {
38
39
  GO: 'go.mod',
39
40
  NUGET: ['packages.config', os.path.join('obj', 'project.assets.json')],
40
41
  HELM: 'Chart.yaml',
41
- UNITY: os.path.join('Library', 'PackageManager', 'ProjectCache')
42
+ UNITY: os.path.join('Library', 'PackageManager', 'ProjectCache'),
43
+ CARGO: 'Cargo.toml'
42
44
  }
43
45
 
44
46
  # default android app name
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2021 LG Electronics Inc.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ import os
7
+ import logging
8
+ import json
9
+ import re
10
+ import subprocess
11
+ import fosslight_util.constant as constant
12
+ import fosslight_dependency.constant as const
13
+ from fosslight_dependency._package_manager import PackageManager
14
+ from fosslight_dependency._package_manager import get_url_to_purl
15
+ from fosslight_dependency.dependency_item import DependencyItem, change_dependson_to_purl
16
+ from fosslight_util.oss_item import OssItem
17
+ logger = logging.getLogger(constant.LOGGER_NAME)
18
+
19
+
20
+ class Cargo(PackageManager):
21
+ package_manager_name = const.CARGO
22
+
23
+ dn_url = 'https://crates.io/crates/'
24
+ input_file_name = 'tmp_cargo_fosslight_output.json'
25
+ tmp_input_file_flag = False
26
+ cur_path = ''
27
+ cargo_lock_f = 'Cargo.lock'
28
+
29
+ def __init__(self, input_dir, output_dir):
30
+ super().__init__(self.package_manager_name, self.dn_url, input_dir, output_dir)
31
+ self.append_input_package_list_file(self.input_file_name)
32
+
33
+ def __del__(self):
34
+ if self.tmp_input_file_flag:
35
+ os.remove(self.input_file_name)
36
+
37
+ def run_plugin(self):
38
+ if os.path.exists(self.input_file_name):
39
+ logger.info(f"Found {self.input_file_name}, skip the flutter cmd to analyze dependency.")
40
+ return True
41
+
42
+ if not os.path.exists(const.SUPPORT_PACKAE.get(self.package_manager_name)):
43
+ logger.error(f"Cannot find the file({const.SUPPORT_PACKAE.get(self.package_manager_name)})")
44
+ return False
45
+
46
+ if os.path.exists(self.cargo_lock_f):
47
+ cmd = f'cargo metadata --locked --format-version 1 > {self.input_file_name}'
48
+ else:
49
+ cmd = f'cargo metadata --format-version 1 > {self.input_file_name}'
50
+ ret = subprocess.call(cmd, shell=True)
51
+ if ret != 0:
52
+ logger.error(f"Failed to run: {cmd}")
53
+ os.chdir(self.cur_path)
54
+ return False
55
+ self.tmp_input_file_flag = True
56
+ return True
57
+
58
+ def parse_oss_information(self, f_name):
59
+ json_data = ''
60
+
61
+ with open(f_name, 'r', encoding='utf8') as cargo_file:
62
+ json_f = json.load(cargo_file)
63
+ try:
64
+ purl_dict = {}
65
+ workspace_members_key = 'workspace_members'
66
+ resolve_key = 'resolve'
67
+ root_key = 'root'
68
+ nodes_key = 'nodes'
69
+ workspace_members = []
70
+ root = ''
71
+ resolve_node = []
72
+
73
+ if workspace_members_key in json_f:
74
+ workspace_members = json_f[workspace_members_key]
75
+
76
+ if resolve_key in json_f:
77
+ if root_key in json_f[resolve_key]:
78
+ root = json_f[resolve_key][root_key]
79
+ if nodes_key in json_f[resolve_key]:
80
+ resolve_node = json_f[resolve_key][nodes_key]
81
+ if root and resolve_node:
82
+ self.direct_dep_list.extend(get_matched_dependencies(root, resolve_node))
83
+ else:
84
+ self.direct_dep = False
85
+ logger.info('Cannot find dependencies relationship (no resolve nodes.)')
86
+
87
+ for json_data in json_f['packages']:
88
+ dep_item = DependencyItem()
89
+ oss_item = OssItem()
90
+ pkg_id = json_data['id']
91
+ oss_origin_name = json_data['name']
92
+
93
+ oss_item.name = f"{self.package_manager_name}:{oss_origin_name}"
94
+ oss_item.version = json_data['version']
95
+ oss_item.homepage = f"{self.dn_url}{oss_origin_name}"
96
+ oss_item.download_location = json_data['repository']
97
+ if oss_item.download_location is None:
98
+ oss_item.download_location = oss_item.homepage
99
+ dep_item.purl = get_url_to_purl(oss_item.homepage, self.package_manager_name, oss_origin_name, oss_item.version)
100
+ purl_dict[f'{oss_origin_name}({oss_item.version})'] = dep_item.purl
101
+ if json_data['license'] is not None:
102
+ oss_item.license = json_data['license']
103
+
104
+ if self.direct_dep:
105
+ if pkg_id == root:
106
+ oss_item.comment = 'root package'
107
+ if pkg_id in workspace_members:
108
+ oss_item.comment = 'local package'
109
+ if len(self.direct_dep_list) > 0:
110
+ if pkg_id != root:
111
+ if f'{oss_origin_name}({oss_item.version})' in self.direct_dep_list:
112
+ oss_item.comment = 'direct'
113
+ else:
114
+ oss_item.comment = 'transitive'
115
+ dep_item.depends_on_raw.extend(get_matched_dependencies(pkg_id, resolve_node))
116
+
117
+ dep_item.oss_items.append(oss_item)
118
+ self.dep_items.append(dep_item)
119
+ except Exception as e:
120
+ logger.error(f"Fail to parse pub oss information: {e}")
121
+ if self.direct_dep:
122
+ self.dep_items = change_dependson_to_purl(purl_dict, self.dep_items)
123
+
124
+ return
125
+
126
+
127
+ def get_matched_dependencies(match_id, resolve_node):
128
+ dependencies_list = []
129
+ for node in resolve_node:
130
+ if match_id == node['id']:
131
+ for dep_pkg in node['dependencies']:
132
+ try:
133
+ match = re.findall(r'^.*#(\S*)@(\S*)', dep_pkg)
134
+ dependencies_list.append(f'{match[0][0]}({match[0][1]})')
135
+ except:
136
+ try:
137
+ match = re.findall(r'^(\S*)\s(\S*)\s', dep_pkg)
138
+ dependencies_list.append(f'{match[0][0]}({match[0][1]})')
139
+ except:
140
+ logger.info(f'cannot find name and version for dependencies: {match_id}')
141
+ pass
142
+ break
143
+ return dependencies_list
@@ -156,7 +156,7 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
156
156
  support_packagemanager = list(const.SUPPORT_PACKAE.keys())
157
157
 
158
158
  if package_manager not in support_packagemanager:
159
- logger.error(f"You entered the unsupported package manager({package_manager}).")
159
+ logger.error(f"(-m option) You entered the unsupported package manager({package_manager}).")
160
160
  logger.error("Please enter the supported package manager({0}) with '-m' option."
161
161
  .format(", ".join(support_packagemanager)))
162
162
  return False, scan_item
@@ -166,7 +166,7 @@ def run_dependency_scanner(package_manager='', input_dir='', output_dir_file='',
166
166
  os.chdir(input_dir)
167
167
  input_dir = os.getcwd()
168
168
  else:
169
- logger.error(f"You entered the wrong input path({input_dir}) to run the script.")
169
+ logger.error(f"(-p option) You entered the wrong input path({input_dir}) to run the script.")
170
170
  logger.error("Please enter the existed input path with '-p' option.")
171
171
  return False, scan_item
172
172
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-dependency
3
- Version: 4.1.1
3
+ Version: 4.1.2
4
4
  Summary: FOSSLight Dependency Scanner
5
5
  Home-page: https://github.com/fosslight/fosslight_dependency_scanner
6
6
  Author: LG Electronics
@@ -32,23 +32,22 @@ Requires-Dist: matplotlib
32
32
  Copyright (c) 2021 LG Electronics
33
33
  SPDX-License-Identifier: Apache-2.0
34
34
  -->
35
- # FOSSLight Dependency Scanner
36
35
 
37
- <img src="https://img.shields.io/pypi/l/fosslight_dependency" alt="License" /> <a href="https://pypi.org/project/fosslight-dependency/"><img src="https://img.shields.io/pypi/v/fosslight_dependency" alt="Current python package version." /></a> <img src="https://img.shields.io/pypi/pyversions/fosslight_dependency" /> [![REUSE status](https://api.reuse.software/badge/github.com/fosslight/fosslight_dependency_scanner)](https://api.reuse.software/info/github.com/fosslight/fosslight_dependency_scanner)
36
+ # FOSSLight Dependency Scanner
38
37
 
38
+ `<img src="https://img.shields.io/pypi/l/fosslight_dependency" alt="License" />` `<a href="https://pypi.org/project/fosslight-dependency/"><img src="https://img.shields.io/pypi/v/fosslight_dependency" alt="Current python package version." />``</a>` `<img src="https://img.shields.io/pypi/pyversions/fosslight_dependency" />` [![REUSE status](https://api.reuse.software/badge/github.com/fosslight/fosslight_dependency_scanner)](https://api.reuse.software/info/github.com/fosslight/fosslight_dependency_scanner)
39
39
 
40
40
  ## 💡 Introduction
41
41
 
42
42
  This is the tool that supports the analysis of dependencies for multiple package managers. It detects the manifest file of package managers automatically and analyzes the dependencies with using open source tools. Then, it generates the report file that contains OSS information of dependencies.
43
43
 
44
-
45
44
  ## 📖 User Guide
46
45
 
47
- We describe the user guide in the [**FOSSLight Guide page**](https://fosslight.org/fosslight-guide-en/scanner/3_dependency.html).
46
+ We describe the user guide in the [**FOSSLight Guide page**](https://fosslight.org/fosslight-guide-en/scanner/3_dependency.html).
48
47
  In this user guide, you can see how to install the FOSSLight Dependency Scanner and how to set up the prerequisite step and run it according to the package manager of your project. Also, you can check the results of the FOSSLight Dependency Scanner.
49
48
 
50
-
51
49
  ## 👀 Package Support Level
50
+
52
51
  <table>
53
52
  <thead>
54
53
  <tr>
@@ -163,19 +162,25 @@ In this user guide, you can see how to install the FOSSLight Dependency Scanner
163
162
  <td>O</td>
164
163
  <td>X</td>
165
164
  </tr>
165
+ <tr>
166
+ <td>Rust</td>
167
+ <td>Cargo</td>
168
+ <td>Cargo.toml</td>
169
+ <td>O</td>
170
+ <td>O</td>
171
+ <td>O</td>
172
+ </tr>
166
173
  </tbody>
167
174
  </table>
168
175
 
169
-
170
176
  ## 👏 Contributing Guide
171
177
 
172
- We always welcome your contributions.
178
+ We always welcome your contributions.
173
179
  Please see the [CONTRIBUTING guide](https://github.com/fosslight/fosslight_dependency_scanner/blob/main/CONTRIBUTING.md) for how to contribute.
174
180
 
175
-
176
181
  ## 📄 License
177
182
 
178
- Copyright (c) 2020 LG Electronics, Inc.
183
+ Copyright (c) 2020 LG Electronics, Inc.
179
184
  FOSSLight Dependency Scanner is licensed under Apache-2.0, as found in the [LICENSE](https://github.com/fosslight/fosslight_dependency_scanner/blob/main/LICENSE) file.
180
185
 
181
186
 
@@ -1,14 +1,15 @@
1
1
  fosslight_dependency/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_dependency/_analyze_dependency.py,sha256=gwdOrwn31sI9Fk5_ZBBbryA1-hCfHdtfqS8QePF7poo,4064
2
+ fosslight_dependency/_analyze_dependency.py,sha256=uYbHDlFfEf-LsCWc6hTKN-QCD1T_2jaEgBf3z4M_4Lk,4226
3
3
  fosslight_dependency/_graph_convertor.py,sha256=D8GwmJfuj9Wg3_DeKRPLGGdyHSLcoU2Q0VzKQbkJG4g,2267
4
- fosslight_dependency/_help.py,sha256=EG-ojJ3Fyn3iYrd_4mGtyMLMefOqf7_AF21q3-jf2Y8,3258
5
- fosslight_dependency/_package_manager.py,sha256=0_A4axLLa-fZ1bNelM4oO0ouV25AHI1TRrHBEKqv6hw,17151
6
- fosslight_dependency/constant.py,sha256=1mJGu1SYyxVKo0W_pCIt-ANp52E_I5ovXFvpl2OMmjU,1039
4
+ fosslight_dependency/_help.py,sha256=INeP24fFfV2HPhZJMqk_KCu08X7nneAumBqMWQ7Sbw8,3336
5
+ fosslight_dependency/_package_manager.py,sha256=TDYP0tlqr7A346BoC2EKEZSq7Eua2cWdJQ5YvMIc9Wc,17265
6
+ fosslight_dependency/constant.py,sha256=FAkzrW1S6Ua_TAbvQ2y6d0dhEZcgonB11miKUj7lB98,1080
7
7
  fosslight_dependency/dependency_item.py,sha256=wNLWcsNycf3HQ5Pib2WrMeo2dn0eHCRg20NLcL95Qew,3345
8
- fosslight_dependency/run_dependency_scanner.py,sha256=K5H_GavKDF_ISIEKBX7Z5awwSDzY1X4pZtLOOZITxbg,15221
8
+ fosslight_dependency/run_dependency_scanner.py,sha256=ybENV3yIzCo8PrJ-3J-1v1JkL0Jrjlzu-yCRKsEwnHs,15245
9
9
  fosslight_dependency/LICENSES/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
10
10
  fosslight_dependency/LICENSES/LicenseRef-3rd_party_licenses.txt,sha256=EcsFt7aE1rp3OXAdJgmXayfOZdpRdBMcmRnyoqWMCsw,95687
11
11
  fosslight_dependency/package_manager/Android.py,sha256=0UZFvbLxDIreerK4fR316YPyhUpPliV_kfZulrxkUyo,3218
12
+ fosslight_dependency/package_manager/Cargo.py,sha256=I27IKtUFf2fOr9ZngB8T9x6pPYhpk1m5CxbwM1dw9rk,5898
12
13
  fosslight_dependency/package_manager/Carthage.py,sha256=qCHH6bhdowgPR5mS89AQLl_0Z5LRoyMZU4vAVHzPNCM,6390
13
14
  fosslight_dependency/package_manager/Cocoapods.py,sha256=k_URV1ekMOU8l_y9_KIp_luu96ZGOl1xLIkH737VREA,8524
14
15
  fosslight_dependency/package_manager/Go.py,sha256=O-6DTTRM2EoTpCVmlIPKFy8ZTz64EHTooOAoUimjeyk,6491
@@ -25,12 +26,12 @@ fosslight_dependency/package_manager/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeu
25
26
  fosslight_dependency/third_party/askalono/askalono.exe,sha256=NyngElHbrg3zLFRVwn6fPDZE_EDAEb1N8tiwWoCm4pQ,4743680
26
27
  fosslight_dependency/third_party/askalono/askalono_macos,sha256=cYSNXhAQpkdd8lkgnY5skNeDmU_8DIuP84eFi0OXKkE,5589868
27
28
  fosslight_dependency/third_party/nomos/nomossa,sha256=oFF9I-fhug6AVNyFnWeVXwDRin6NWSvk1g7mHBotB3Q,866408
28
- fosslight_dependency-4.1.1.dist-info/Apache-2.0.txt,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
29
- fosslight_dependency-4.1.1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
30
- fosslight_dependency-4.1.1.dist-info/LicenseRef-3rd_party_licenses.txt,sha256=EcsFt7aE1rp3OXAdJgmXayfOZdpRdBMcmRnyoqWMCsw,95687
31
- fosslight_dependency-4.1.1.dist-info/METADATA,sha256=e_xrAdGXgg5nJrYKw4les0HgU6xJ9peR3Dt5SHcpWnE,4844
32
- fosslight_dependency-4.1.1.dist-info/MIT.txt,sha256=9cx4CbArgByWvkoEZNqpzbpJgA9TUe2D62rMocQpgfs,1082
33
- fosslight_dependency-4.1.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
34
- fosslight_dependency-4.1.1.dist-info/entry_points.txt,sha256=e1QZbnCrQvfbwe9L6PxXnkRZMhl-PSo0QyUes0dGjU8,91
35
- fosslight_dependency-4.1.1.dist-info/top_level.txt,sha256=Jc0V7VcVCH0TEM8ksb8dwroTYz4AmRaQnlr3FB71Hcs,21
36
- fosslight_dependency-4.1.1.dist-info/RECORD,,
29
+ fosslight_dependency-4.1.2.dist-info/Apache-2.0.txt,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
30
+ fosslight_dependency-4.1.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
31
+ fosslight_dependency-4.1.2.dist-info/LicenseRef-3rd_party_licenses.txt,sha256=EcsFt7aE1rp3OXAdJgmXayfOZdpRdBMcmRnyoqWMCsw,95687
32
+ fosslight_dependency-4.1.2.dist-info/METADATA,sha256=7AUZDIFshZXWyFbFnHcCpB7rgyu6rTgX8GsPnMGl6U4,4964
33
+ fosslight_dependency-4.1.2.dist-info/MIT.txt,sha256=9cx4CbArgByWvkoEZNqpzbpJgA9TUe2D62rMocQpgfs,1082
34
+ fosslight_dependency-4.1.2.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
35
+ fosslight_dependency-4.1.2.dist-info/entry_points.txt,sha256=e1QZbnCrQvfbwe9L6PxXnkRZMhl-PSo0QyUes0dGjU8,91
36
+ fosslight_dependency-4.1.2.dist-info/top_level.txt,sha256=Jc0V7VcVCH0TEM8ksb8dwroTYz4AmRaQnlr3FB71Hcs,21
37
+ fosslight_dependency-4.1.2.dist-info/RECORD,,