diff --git a/swh/loader/package/debian/loader.py b/swh/loader/package/debian/loader.py --- a/swh/loader/package/debian/loader.py +++ b/swh/loader/package/debian/loader.py @@ -72,13 +72,18 @@ files = attr.ib(type=Dict[str, DebianFileMetadata]) """Metadata of the files (.deb, .dsc, ...) of the package.""" name = attr.ib(type=str) - full_version = attr.ib(type=str) - """eg. stretch/contrib/0.7.2-3""" + intrinsic_version = attr.ib(type=str) + """eg. ``0.7.2-3``, while :attr:`version` would be ``stretch/contrib/0.7.2-3``""" @classmethod def from_metadata( cls, a_metadata: Dict[str, Any], url: str, version: str ) -> "DebianPackageInfo": + intrinsic_version = a_metadata["version"] + assert "/" in version and "/" not in intrinsic_version, ( + version, + intrinsic_version, + ) return cls( url=url, filename=None, @@ -89,7 +94,7 @@ for (file_name, file_metadata) in a_metadata.get("files", {}).items() }, name=a_metadata["name"], - full_version=a_metadata["version"], + intrinsic_version=intrinsic_version, ) def extid(self) -> Optional[PartialExtID]: @@ -228,7 +233,7 @@ msg = ( f"Synthetic release for Debian source package {p_info.name} " - f"version {p_info.full_version}\n" + f"version {p_info.intrinsic_version}\n" ) author = prepare_person(intrinsic_metadata.changelog.person) @@ -335,7 +340,7 @@ if dsc_name: raise DscCountError( "Package %s_%s references several dsc files." - % (p_info.name, p_info.version) + % (p_info.name, p_info.intrinsic_version) ) dsc_url = fileinfo.uri dsc_name = filename @@ -460,7 +465,7 @@ return IntrinsicPackageMetadata( name=p_info.name, - version=str(p_info.version), + version=str(p_info.intrinsic_version), changelog=changelog, maintainers=maintainers, ) diff --git a/swh/loader/package/debian/tests/test_debian.py b/swh/loader/package/debian/tests/test_debian.py --- a/swh/loader/package/debian/tests/test_debian.py +++ b/swh/loader/package/debian/tests/test_debian.py @@ -282,7 +282,9 @@ def test_debian_download_package(datadir, tmpdir, requests_mock_datadir): tmpdir = str(tmpdir) # py3.5 work around (LocalPath issue) - p_info = DebianPackageInfo.from_metadata(PACKAGE_FILES, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + PACKAGE_FILES, url=URL, version="stretch/contrib/0.7.2-3" + ) all_hashes = download_package(p_info, tmpdir) assert all_hashes == { "cicero_0.7.2-3.diff.gz": { @@ -325,7 +327,9 @@ def test_debian_dsc_information_ok(): fname = "cicero_0.7.2-3.dsc" - p_info = DebianPackageInfo.from_metadata(PACKAGE_FILES, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + PACKAGE_FILES, url=URL, version="stretch/contrib/0.7.2-3" + ) dsc_url, dsc_name = dsc_information(p_info) assert dsc_url == PACKAGE_FILES["files"][fname]["uri"] @@ -334,7 +338,9 @@ def test_debian_dsc_information_not_found(): fname = "cicero_0.7.2-3.dsc" - p_info = DebianPackageInfo.from_metadata(PACKAGE_FILES, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + PACKAGE_FILES, url=URL, version="stretch/contrib/0.7.2-3" + ) p_info.files.pop(fname) dsc_url, dsc_name = dsc_information(p_info) @@ -349,7 +355,9 @@ for package_metadata in package_files["files"].values(): del package_metadata["md5sum"] - p_info = DebianPackageInfo.from_metadata(package_files, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + package_files, url=URL, version="stretch/contrib/0.7.2-3" + ) for debian_file_metadata in p_info.files.values(): assert not debian_file_metadata.md5sum @@ -362,7 +370,9 @@ file_bytes = requests.get(package_metadata["uri"]).content package_metadata["sha1"] = hashlib.sha1(file_bytes).hexdigest() - p_info = DebianPackageInfo.from_metadata(package_files, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + package_files, url=URL, version="stretch/contrib/0.7.2-3" + ) for debian_file_metadata in p_info.files.values(): assert debian_file_metadata.sha1 @@ -371,7 +381,9 @@ def test_debian_dsc_information_too_many_dsc_entries(): # craft an extra dsc file fname = "cicero_0.7.2-3.dsc" - p_info = DebianPackageInfo.from_metadata(PACKAGE_FILES, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + PACKAGE_FILES, url=URL, version="stretch/contrib/0.7.2-3" + ) data = p_info.files[fname] fname2 = fname.replace("cicero", "ciceroo") p_info.files[fname2] = data @@ -388,7 +400,9 @@ requests_mock_datadir, datadir, tmp_path ): tmp_path = str(tmp_path) # py3.5 compat. - p_info = DebianPackageInfo.from_metadata(PACKAGE_FILES, url=URL, version="0.7.2-3") + p_info = DebianPackageInfo.from_metadata( + PACKAGE_FILES, url=URL, version="stretch/contrib/0.7.2-3" + ) logger.debug("p_info: %s", p_info)