Yield DependentPackage from the file at ``location`` for the given ``package_type``.
(lines, location, package_type)
| 179 | |
| 180 | |
| 181 | def 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 | |
| 212 | class LinesBasedGemfileParser(GemfileParser): |
no test coverage detected