Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pubdev/loader.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from distutils.version import LooseVersion | |||||
import json | import json | ||||
from pathlib import Path | from pathlib import Path | ||||
from typing import Any, Dict, Iterator, Optional, Sequence, Tuple | from typing import Any, Dict, Iterator, Optional, Sequence, Tuple | ||||
import attr | import attr | ||||
from packaging.version import parse as parse_version | |||||
import yaml | import yaml | ||||
from swh.loader.package.loader import BasePackageInfo, PackageLoader | from swh.loader.package.loader import BasePackageInfo, PackageLoader | ||||
from swh.loader.package.utils import ( | from swh.loader.package.utils import ( | ||||
EMPTY_AUTHOR, | EMPTY_AUTHOR, | ||||
Person, | Person, | ||||
api_info, | api_info, | ||||
cached_method, | cached_method, | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | def get_versions(self) -> Sequence[str]: | ||||
Returns: | Returns: | ||||
A sequence of versions | A sequence of versions | ||||
Example:: | Example:: | ||||
["0.1.1", "0.10.2"] | ["0.1.1", "0.10.2"] | ||||
""" | """ | ||||
versions = list(self.info()["versions"].keys()) | versions = list(self.info()["versions"].keys()) | ||||
versions.sort(key=LooseVersion) | versions.sort(key=parse_version) | ||||
return versions | return versions | ||||
anlambert: You can still use previous code here and replace the sort key by `parse_version`. | |||||
def get_default_version(self) -> str: | def get_default_version(self) -> str: | ||||
"""Get the newest release version of a PubDev package | """Get the newest release version of a PubDev package | ||||
Returns: | Returns: | ||||
A string representing a version | A string representing a version | ||||
Example:: | Example:: | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
You can still use previous code here and replace the sort key by parse_version.