Yield a Package. Note that ABOUT files do not carry dependencies.
(cls, package_data, resource, codebase, package_adder)
| 107 | |
| 108 | @classmethod |
| 109 | def assemble(cls, package_data, resource, codebase, package_adder): |
| 110 | """ |
| 111 | Yield a Package. Note that ABOUT files do not carry dependencies. |
| 112 | """ |
| 113 | datafile_path = resource.path |
| 114 | # do we have enough to create a package? |
| 115 | if package_data.purl: |
| 116 | package = models.Package.from_package_data( |
| 117 | package_data=package_data, |
| 118 | datafile_path=datafile_path, |
| 119 | ) |
| 120 | |
| 121 | package.populate_license_fields() |
| 122 | |
| 123 | yield package |
| 124 | |
| 125 | package_uid = package.package_uid |
| 126 | # NOTE: we do not attach files to the Package level. Instead we |
| 127 | # update `for_package` in the file |
| 128 | package_adder(package_uid, resource, codebase) |
| 129 | |
| 130 | if resource.has_parent() and package_data.file_references: |
| 131 | parent_resource = resource.parent(codebase) |
| 132 | if parent_resource and package_data.file_references: |
| 133 | root_path = Path(parent_resource.path) |
| 134 | |
| 135 | # FIXME: we should be able to get the path relatively to the |
| 136 | # ABOUT file resource a file ref extends from the root of |
| 137 | # the filesystem |
| 138 | file_references_by_path = { |
| 139 | str(root_path / ref.path): ref |
| 140 | for ref in package.file_references |
| 141 | } |
| 142 | |
| 143 | for res in parent_resource.walk(codebase): |
| 144 | ref = file_references_by_path.get(res.path) |
| 145 | if not ref: |
| 146 | continue |
| 147 | |
| 148 | # path is found and processed: remove it, so we can |
| 149 | # check if we found all of them |
| 150 | del file_references_by_path[res.path] |
| 151 | package_adder(package_uid, res, codebase) |
| 152 | |
| 153 | yield res |
| 154 | |
| 155 | # if we have left over file references, add these to extra data |
| 156 | if file_references_by_path: |
| 157 | missing = sorted(file_references_by_path.values(), key=lambda r: r.path) |
| 158 | package.extra_data['missing_file_references'] = missing |
| 159 | else: |
| 160 | package.extra_data['missing_file_references'] = package_data.file_references[:] |
| 161 | |
| 162 | # we yield this as we do not want this further processed |
| 163 | yield resource |
nothing calls this directly
no test coverage detected