Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pubdev/loader.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | def extract_intrinsic_metadata(dir_path: Path) -> Dict[str, Any]: | ||||
""" | """ | ||||
pubspec_path = dir_path / "pubspec.yaml" | pubspec_path = dir_path / "pubspec.yaml" | ||||
return yaml.safe_load(pubspec_path.read_text()) | return yaml.safe_load(pubspec_path.read_text()) | ||||
class PubDevLoader(PackageLoader[PubDevPackageInfo]): | class PubDevLoader(PackageLoader[PubDevPackageInfo]): | ||||
visit_type = "pubdev" | visit_type = "pubdev" | ||||
PUBDEV_BASE_URL = "https://pub.dev/" | |||||
def __init__( | def __init__( | ||||
self, | self, | ||||
storage: StorageInterface, | storage: StorageInterface, | ||||
url: str, | url: str, | ||||
**kwargs, | **kwargs, | ||||
): | ): | ||||
super().__init__(storage=storage, url=url, **kwargs) | super().__init__(storage=storage, url=url, **kwargs) | ||||
self.url = url | self.url = url | ||||
assert url.startswith(self.PUBDEV_BASE_URL) | |||||
self.package_info_url = url.replace( | |||||
vlorentz: you should assert the URL starts with the expected prefix | |||||
Done Inline Actionsright anlambert: right | |||||
self.PUBDEV_BASE_URL, f"{self.PUBDEV_BASE_URL}api/" | |||||
) | |||||
def _raw_info(self) -> bytes: | def _raw_info(self) -> bytes: | ||||
return api_info(self.url) | return api_info(self.package_info_url) | ||||
@cached_method | @cached_method | ||||
def info(self) -> Dict: | def info(self) -> Dict: | ||||
"""Return the project metadata information (fetched from pub.dev registry)""" | """Return the project metadata information (fetched from pub.dev registry)""" | ||||
# Use strict=False in order to correctly manage case where \n is present in a string | # Use strict=False in order to correctly manage case where \n is present in a string | ||||
info = json.loads(self._raw_info(), strict=False) | info = json.loads(self._raw_info(), strict=False) | ||||
# Arrange versions list as a new dict with `version` as key | # Arrange versions list as a new dict with `version` as key | ||||
versions = {v["version"]: v for v in info["versions"]} | versions = {v["version"]: v for v in info["versions"]} | ||||
▲ Show 20 Lines • Show All 105 Lines • Show Last 20 Lines |
you should assert the URL starts with the expected prefix