Return a PackageData object from a PKG-INFO or METADATA file at ``location`` which is a path string or pathlib.Path-like object (including a possible zip file ZipPath for a wheel) Looks in neighboring files as needed when an installed layout is found.
(location, datasource_id, package_type, package_only=False)
| 1252 | |
| 1253 | |
| 1254 | def parse_metadata(location, datasource_id, package_type, package_only=False): |
| 1255 | """ |
| 1256 | Return a PackageData object from a PKG-INFO or METADATA file at ``location`` |
| 1257 | which is a path string or pathlib.Path-like object (including a possible zip |
| 1258 | file ZipPath for a wheel) |
| 1259 | |
| 1260 | Looks in neighboring files as needed when an installed layout is found. |
| 1261 | """ |
| 1262 | path = location |
| 1263 | if not isinstance(location, (Path, ZipPath)): |
| 1264 | path = Path(location) |
| 1265 | |
| 1266 | # build from dir if we are an installed distro |
| 1267 | parent = path.parent |
| 1268 | if parent.name.endswith(META_DIR_SUFFIXES): |
| 1269 | path = parent |
| 1270 | |
| 1271 | dist = importlib_metadata.PathDistribution(path) |
| 1272 | |
| 1273 | meta = dist.metadata |
| 1274 | |
| 1275 | name = get_attribute(meta, 'Name') |
| 1276 | version = get_attribute(meta, 'Version') |
| 1277 | |
| 1278 | urls, extra_data = get_urls(metainfo=meta, name=name, version=version) |
| 1279 | |
| 1280 | extracted_license_statement, license_file = get_declared_license(metainfo=meta) |
| 1281 | if license_file: |
| 1282 | extra_data['license_file'] = license_file |
| 1283 | |
| 1284 | # FIXME: We are getting dependencies from other sibling files, this is duplicated |
| 1285 | # data at the package_data level, is this necessary? We also have the entire dependency |
| 1286 | # relationships here at requires.txt present in ``.egg-info`` should we store these |
| 1287 | # nicely? |
| 1288 | dependencies = get_dist_dependencies(dist) |
| 1289 | file_references = list(get_file_references(dist)) |
| 1290 | |
| 1291 | package_data = dict( |
| 1292 | datasource_id=datasource_id, |
| 1293 | type=package_type, |
| 1294 | primary_language='Python', |
| 1295 | name=name, |
| 1296 | version=version, |
| 1297 | extracted_license_statement=extracted_license_statement, |
| 1298 | description=get_description(metainfo=meta, location=str(location)), |
| 1299 | keywords=get_keywords(meta), |
| 1300 | parties=get_parties(meta), |
| 1301 | dependencies=dependencies, |
| 1302 | file_references=file_references, |
| 1303 | extra_data=extra_data, |
| 1304 | **urls, |
| 1305 | ) |
| 1306 | return models.PackageData.from_data(package_data, package_only) |
| 1307 | |
| 1308 | |
| 1309 | def urlsafe_b64decode(data): |
no test coverage detected