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

Function get_dependent_packages

src/packagedcode/spec.py:181–209  ·  view source on GitHub ↗

Yield DependentPackage from the file at ``location`` for the given ``package_type``.

(lines, location, package_type)

Source from the content-addressed store, hash-verified

179
180
181def get_dependent_packages(lines, location, package_type):
182 """
183 Yield DependentPackage from the file at ``location`` for the given
184 ``package_type``.
185 """
186 flags_by_scope = {
187 'runtime': dict(is_runtime=True, is_optional=False),
188 'dependency': dict(is_runtime=True, is_optional=False),
189 'production': dict(is_runtime=True, is_optional=False),
190
191 'development': dict(is_runtime=False, is_optional=True),
192 'test': dict(is_runtime=False, is_optional=True),
193 'metrics': dict(is_runtime=False, is_optional=True),
194 }
195
196 dependencies = LinesBasedGemfileParser(lines=lines, filepath=location).parse()
197
198 for key in dependencies:
199 depends = dependencies.get(key, []) or []
200 for dep in depends:
201 flags = flags_by_scope.get(key, 'runtime')
202
203 yield models.DependentPackage(
204 purl=PackageURL(type=package_type, name=dep.name).to_string(),
205 extracted_requirement=', '.join(dep.requirement),
206 scope=key,
207 is_pinned=False,
208 **flags,
209 )
210
211
212class LinesBasedGemfileParser(GemfileParser):

Callers 1

parse_specFunction · 0.85

Calls 5

to_stringMethod · 0.80
getMethod · 0.65
parseMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected