Skip to content
Snippets Groups Projects
Commit a63b39e5 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

conda: Fix versions sorting and update release names

Release 22.0 of packaging module can no longer parse invalid Python version
number, an exception is now raised.

Conda loader used the keys of the packages dict as version numbers to sort,
which are in the form "<arch>/<version>-<build>", but those cannot be parsed
anymore.

So extract intrinsic version numbers of packages instead to sort the list of
versions.

Also update snapshot release names to "<version>-<build>-<arch>" as each
release for a given architecture targets a different directory.
parent b6231045
No related branches found
No related tags found
1 merge request!351conda, rpm: Fix package versions sorting
......@@ -29,7 +29,11 @@ class CondaPackageInfo(BasePackageInfo):
"""Archive (tar.gz) file name"""
version = attr.ib(type=str)
"""Complete version and distribution name. Ex: 'linux-64/0.1.1-py37'
"""Complete version and distribution name used as branch name. Ex: 'linux-64/0.1.1-py37'
"""
release_version = attr.ib(type=str)
"""Version number used as release name. Ex: '0.1.1-py37-linux-64'
"""
last_modified: Optional[datetime] = attr.ib()
......@@ -102,7 +106,11 @@ class CondaLoader(PackageLoader[CondaPackageInfo]):
["0.1.1", "0.10.2"]
"""
versions = list(self.artifacts.keys())
versions.sort(key=parse_version)
versions.sort(
key=lambda version_key: parse_version(
version_key.split("/", 1)[1].split("-", 1)[0]
)
)
return versions
def get_default_version(self) -> str:
......@@ -135,11 +143,14 @@ class CondaLoader(PackageLoader[CondaPackageInfo]):
if data.get("date"):
last_modified = iso8601.parse_date(data["date"])
arch, version_and_build = data["version"].split("/", 1)
p_info = CondaPackageInfo(
name=pkgname,
filename=filename,
url=url,
version=version,
release_version=f"{version_and_build}-{arch}",
last_modified=last_modified,
checksums=data["checksums"],
)
......@@ -170,7 +181,7 @@ class CondaLoader(PackageLoader[CondaPackageInfo]):
)
return Release(
name=p_info.version.encode(),
name=p_info.release_version.encode(),
author=author,
date=last_modified,
message=message.encode(),
......
......@@ -5,7 +5,7 @@
from swh.loader.package.conda.loader import CondaLoader
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats
from swh.model.hashutil import hash_to_bytes
from swh.model.hashutil import hash_to_bytes, hash_to_hex
from swh.model.model import (
ObjectType,
Person,
......@@ -72,19 +72,39 @@ def test_conda_loader_load_multiple_version(
assert load_status["status"] == "eventful"
assert load_status["snapshot_id"] is not None
expected_snapshot_id = "9c20bedf9af54ef7b3937fe4675f9f17b9331b7b"
first_release = Release(
name=b"0.11.1-py36h9f0ad1d_1-linux-64",
message=b"Synthetic release for Conda source package lifetimes version"
b" linux-64/0.11.1-py36h9f0ad1d_1\n",
target=hash_to_bytes("0c63e5f909e481d8e5832bac8abbd089bca42993"),
target_type=ObjectType.DIRECTORY,
synthetic=True,
author=Person(
fullname=b"CamDavidsonPilon", name=b"CamDavidsonPilon", email=None
),
date=TimestampWithTimezone.from_iso8601("2020-07-06T12:19:36.425000+00:00"),
)
assert expected_snapshot_id == load_status["snapshot_id"]
# This one have empty author and date
second_release = Release(
name=b"0.11.1-py36hc560c46_1-linux-64",
message=b"Synthetic release for Conda source package lifetimes version"
b" linux-64/0.11.1-py36hc560c46_1\n",
target=hash_to_bytes("45ca406aeb31f51836a8593b619ab216403ce489"),
target_type=ObjectType.DIRECTORY,
synthetic=True,
author=Person(fullname=b"", name=None, email=None),
date=None,
)
expected_snapshot = Snapshot(
id=hash_to_bytes(load_status["snapshot_id"]),
branches={
b"releases/linux-64/0.11.1-py36h9f0ad1d_1": SnapshotBranch(
target=hash_to_bytes("9848f61b501801799025d632221833a0f988dca2"),
target=first_release.id,
target_type=TargetType.RELEASE,
),
b"releases/linux-64/0.11.1-py36hc560c46_1": SnapshotBranch(
target=hash_to_bytes("fad38f867db9311504a4c340f2b32dcdffa46e27"),
target=second_release.id,
target_type=TargetType.RELEASE,
),
b"HEAD": SnapshotBranch(
......@@ -94,6 +114,8 @@ def test_conda_loader_load_multiple_version(
},
)
assert hash_to_hex(expected_snapshot.id) == load_status["snapshot_id"]
check_snapshot(expected_snapshot, swh_storage)
stats = get_stats(swh_storage)
......@@ -108,45 +130,6 @@ def test_conda_loader_load_multiple_version(
"snapshot": 1,
} == stats
assert swh_storage.release_get(
[hash_to_bytes("9848f61b501801799025d632221833a0f988dca2")]
)[0] == Release(
name=b"linux-64/0.11.1-py36h9f0ad1d_1",
message=b"Synthetic release for Conda source package lifetimes version"
b" linux-64/0.11.1-py36h9f0ad1d_1\n",
target=hash_to_bytes("0c63e5f909e481d8e5832bac8abbd089bca42993"),
target_type=ObjectType.DIRECTORY,
synthetic=True,
author=Person(
fullname=b"CamDavidsonPilon", name=b"CamDavidsonPilon", email=None
),
date=TimestampWithTimezone.from_iso8601("2020-07-06T12:19:36.425000+00:00"),
id=hash_to_bytes("9848f61b501801799025d632221833a0f988dca2"),
)
assert_last_visit_matches(
swh_storage,
url=ORIGINS[0]["url"],
status="full",
type="conda",
snapshot=hash_to_bytes(load_status["snapshot_id"]),
)
# This one have empty author and date
assert swh_storage.release_get(
[hash_to_bytes("fad38f867db9311504a4c340f2b32dcdffa46e27")]
)[0] == Release(
name=b"linux-64/0.11.1-py36hc560c46_1",
message=b"Synthetic release for Conda source package lifetimes version"
b" linux-64/0.11.1-py36hc560c46_1\n",
target=hash_to_bytes("45ca406aeb31f51836a8593b619ab216403ce489"),
target_type=ObjectType.DIRECTORY,
synthetic=True,
author=Person(fullname=b"", name=None, email=None),
date=None,
id=hash_to_bytes("fad38f867db9311504a4c340f2b32dcdffa46e27"),
)
assert_last_visit_matches(
swh_storage,
url=ORIGINS[0]["url"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment