(cls, package_data, resource, codebase, package_adder)
| 166 | |
| 167 | @classmethod |
| 168 | def assemble(cls, package_data, resource, codebase, package_adder): |
| 169 | # a source distribution can have many manifests |
| 170 | datafile_name_patterns = ( |
| 171 | PipfileHandler.path_patterns + PipfileLockHandler.path_patterns |
| 172 | + PipRequirementsFileHandler.path_patterns + PyprojectTomlHandler.path_patterns |
| 173 | ) |
| 174 | |
| 175 | is_datafile_pypi = any(fnmatchcase(resource.path, pat) for pat in datafile_name_patterns) |
| 176 | |
| 177 | package_resource = None |
| 178 | if resource.name == 'PKG-INFO': |
| 179 | # Initially use current Resource as `package_resource`. |
| 180 | # We'll want update `package_resource` with the Resource of a |
| 181 | # PKG-INFO file that's in an .egg-info Directory. |
| 182 | package_resource = resource |
| 183 | # We want to use the PKG-INFO file from an .egg-info directory, as |
| 184 | # the package info collected from a *.egg_info/PKG-INFO file has |
| 185 | # dependency information that a PKG-INFO from the root of a Python |
| 186 | # project lacks. |
| 187 | parent_resource = resource.parent(codebase) |
| 188 | if not is_egg_info_directory(parent_resource): |
| 189 | # If we are not in an .egg-info directory, we assume we are at |
| 190 | # the root of a Python codebase and we want to find the |
| 191 | # .egg_info dir |
| 192 | egg_info_dir = None |
| 193 | for sibling in resource.siblings(codebase): |
| 194 | if sibling.path.endswith('.egg-info'): |
| 195 | egg_info_dir = sibling |
| 196 | break |
| 197 | |
| 198 | # If we find the .egg_info dir, then we look for the PKG-INFO |
| 199 | # file in it and use that as our package_resource |
| 200 | if egg_info_dir: |
| 201 | for child in egg_info_dir.children(codebase): |
| 202 | if not child.name == 'PKG-INFO': |
| 203 | continue |
| 204 | package_resource = child |
| 205 | break |
| 206 | |
| 207 | elif is_datafile_pypi: |
| 208 | if resource.has_parent(): |
| 209 | siblings = resource.siblings(codebase) |
| 210 | package_resources = [r for r in siblings if r.name == 'PKG-INFO'] |
| 211 | if package_resource: |
| 212 | package_resource = package_resources[0] |
| 213 | |
| 214 | package = None |
| 215 | if package_resource: |
| 216 | pkg_data = package_resource.package_data[0] |
| 217 | pkg_data = models.PackageData.from_dict(pkg_data) |
| 218 | if pkg_data.purl: |
| 219 | # We yield only the package and the resource, and not dependencies because |
| 220 | # PKG-INFO also has the dependencies from |
| 221 | package = create_package_from_package_data( |
| 222 | package_data=pkg_data, |
| 223 | datafile_path=package_resource.path |
| 224 | ) |
| 225 | yield package |
nothing calls this directly
no test coverage detected