Given a ``package_data`` PackageData found in the ``resource`` datafile of the ``codebase``, assemble package their files and dependencies from one or more datafiles. Update ``codebase`` Resources with the package they are for, using the function ``package_a
(cls, package_data, resource, codebase, package_adder=add_to_package)
| 1135 | |
| 1136 | @classmethod |
| 1137 | def assemble(cls, package_data, resource, codebase, package_adder=add_to_package): |
| 1138 | """ |
| 1139 | Given a ``package_data`` PackageData found in the ``resource`` datafile |
| 1140 | of the ``codebase``, assemble package their files and dependencies |
| 1141 | from one or more datafiles. |
| 1142 | |
| 1143 | Update ``codebase`` Resources with the package they are for, using the |
| 1144 | function ``package_adder`` to associate Resources to the Package they |
| 1145 | are part of. |
| 1146 | |
| 1147 | Yield items that can be of these types: |
| 1148 | |
| 1149 | - a Package to add to top-level packages with its list of Files. |
| 1150 | - Resources that have been handled --such as this datafiles-- that should |
| 1151 | not be further processed, |
| 1152 | - a Dependency to add to top-level dependencies |
| 1153 | |
| 1154 | Package items must be yielded before Dependency or Resource items. This |
| 1155 | is to ensure that a Package is created before we associate a Resource or |
| 1156 | Dependency to a Package. This is particulary important in the case where |
| 1157 | we are calling the `assemble()` method outside of the scancode-toolkit |
| 1158 | context. |
| 1159 | |
| 1160 | The approach is to find and process all the neighboring related datafiles |
| 1161 | to this datafile at once. |
| 1162 | |
| 1163 | The default implementation handles this datafile only: |
| 1164 | |
| 1165 | - It does not include other related datafiles and manifests. |
| 1166 | - It considers only this datafile as a package file |
| 1167 | - It returns only this datafile resource as having been processed |
| 1168 | |
| 1169 | Subclasses should override to implement more complex cases where |
| 1170 | multiple datafiles are combined and some files can be ignored. |
| 1171 | """ |
| 1172 | datafile_path = resource.path |
| 1173 | # do we have enough to create a package? |
| 1174 | if package_data.purl: |
| 1175 | package = Package.from_package_data( |
| 1176 | package_data=package_data, |
| 1177 | datafile_path=datafile_path, |
| 1178 | ) |
| 1179 | package_uid = package.package_uid |
| 1180 | |
| 1181 | package.populate_license_fields() |
| 1182 | |
| 1183 | yield package |
| 1184 | |
| 1185 | cls.assign_package_to_resources( |
| 1186 | package=package, |
| 1187 | resource=resource, |
| 1188 | codebase=codebase, |
| 1189 | package_adder=package_adder, |
| 1190 | ) |
| 1191 | else: |
| 1192 | # we have no package, so deps are not for a specific package uid |
| 1193 | package_uid = None |
| 1194 |
nothing calls this directly
no test coverage detected