MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / parse

Method parse

src/packagedcode/nuget.py:110–181  ·  view source on GitHub ↗
(cls, location, package_only=False)

Source from the content-addressed store, hash-verified

108
109 @classmethod
110 def parse(cls, location, package_only=False):
111 with open(location, 'rb') as loc:
112 parsed = xmltodict.parse(loc)
113
114 if not parsed:
115 return
116
117 pack = parsed.get('package') or {}
118 nuspec = pack.get('metadata')
119 if not nuspec:
120 return
121
122 name = nuspec.get('id')
123 version = nuspec.get('version')
124
125 # Summary: A short description of the package for UI display. If omitted, a
126 # truncated version of description is used.
127 description = build_description(nuspec.get('summary'), nuspec.get('description'))
128
129 # title: A human-friendly title of the package, typically used in UI
130 # displays as on nuget.org and the Package Manager in Visual Studio. If not
131 # specified, the package ID is used.
132 title = nuspec.get('title')
133 if title and title != name:
134 description = build_description(title, description)
135
136 parties = []
137 authors = nuspec.get('authors')
138 if authors:
139 parties.append(models.Party(name=authors, role='author'))
140
141 owners = nuspec.get('owners')
142 if owners:
143 parties.append(models.Party(name=owners, role='owner'))
144
145 vcs_url = None
146
147 repo = nuspec.get('repository') or {}
148 vcs_repository = repo.get('@url') or ''
149 if vcs_repository:
150 vcs_tool = repo.get('@type') or ''
151 if vcs_tool:
152 vcs_url = f'{vcs_tool}+{vcs_repository}'
153 else:
154 vcs_url = vcs_repository
155
156 urls = get_urls(name, version)
157
158 extracted_license_statement = None
159 # See https://docs.microsoft.com/en-us/nuget/reference/nuspec#license
160 # This is a SPDX license expression
161 if 'license' in nuspec:
162 extracted_license_statement = nuspec.get('license')
163 # Deprecated and not a license expression, just a URL
164 elif 'licenseUrl' in nuspec:
165 extracted_license_statement = nuspec.get('licenseUrl')
166
167 package_data = dict(

Callers

nothing calls this directly

Calls 6

build_descriptionFunction · 0.90
from_dataMethod · 0.80
get_urlsFunction · 0.70
get_dependenciesFunction · 0.70
getMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected