diff --git a/galaxy_ng/app/api/v1/serializers.py b/galaxy_ng/app/api/v1/serializers.py index ffa74bb60e..0388b97671 100644 --- a/galaxy_ng/app/api/v1/serializers.py +++ b/galaxy_ng/app/api/v1/serializers.py @@ -8,6 +8,7 @@ from galaxy_ng.app.api.v1.models import LegacyNamespace from galaxy_ng.app.api.v1.models import LegacyRole from galaxy_ng.app.api.v1.models import LegacyRoleDownloadCount +from galaxy_ng.app.api.v1.utils import sort_versions class LegacyNamespacesSerializer(serializers.ModelSerializer): @@ -296,7 +297,8 @@ def get_summary_fields(self, obj): versions = obj.full_metadata.get('versions', []) if versions: - # the versions data should have been sorted at sync or import time + # FIXME - we can't assume they're all sorted yet + versions = sort_versions(versions) versions = versions[::-1] if len(versions) > 10: versions = versions[:11] @@ -449,6 +451,7 @@ def get_previous_link(self, obj): def get_results(self, obj): versions = obj.full_metadata.get('versions', []) + versions = sort_versions(versions) results = [] diff --git a/galaxy_ng/app/api/v1/tasks.py b/galaxy_ng/app/api/v1/tasks.py index 7fd40138a7..edad540bbf 100644 --- a/galaxy_ng/app/api/v1/tasks.py +++ b/galaxy_ng/app/api/v1/tasks.py @@ -6,8 +6,6 @@ import tempfile import uuid -import semantic_version - from django.db import transaction from ansible.module_utils.compat.version import LooseVersion @@ -24,6 +22,8 @@ from galaxy_ng.app.api.v1.models import LegacyNamespace from galaxy_ng.app.api.v1.models import LegacyRole from galaxy_ng.app.api.v1.models import LegacyRoleDownloadCount +from galaxy_ng.app.api.v1.utils import sort_versions +from galaxy_ng.app.api.v1.utils import parse_version_tag from git import Repo @@ -31,15 +31,6 @@ logger = logging.getLogger(__name__) -def parse_version_tag(value): - value = str(value) - if not value: - raise ValueError('Empty version value') - if value[0].lower() == 'v': - value = value[1:] - return semantic_version.Version(value) - - def find_real_role(github_user, github_repo): """ Given the github_user and github_repo attributes, find a matching @@ -173,14 +164,6 @@ def do_git_checkout(clone_url, checkout_path, github_reference): return gitrepo, github_reference, last_commit -def sort_versions(versions): - """ - Use ansible-core's LooseVersion util to sort the versions. - """ - sorted_versions = sorted(versions, key=lambda x: LooseVersion(x['tag'].lower())) - return sorted_versions - - def normalize_versions(versions): # convert old integer based IDs to uuid @@ -206,7 +189,7 @@ def normalize_versions(versions): versions.remove(version) continue lver = LooseVersion(version['tag'].lower()) - if not all(isinstance(x, int) for x in lver.version): + if not any(isinstance(x, int) for x in lver.version): versions.remove(version) return versions diff --git a/galaxy_ng/app/api/v1/utils.py b/galaxy_ng/app/api/v1/utils.py new file mode 100644 index 0000000000..1435a9a899 --- /dev/null +++ b/galaxy_ng/app/api/v1/utils.py @@ -0,0 +1,19 @@ +import semantic_version +from ansible.module_utils.compat.version import LooseVersion + + +def parse_version_tag(value): + value = str(value) + if not value: + raise ValueError('Empty version value') + if value[0].lower() == 'v': + value = value[1:] + return semantic_version.Version(value) + + +def sort_versions(versions): + """ + Use ansible-core's LooseVersion util to sort the version dicts by the tag key. + """ + sorted_versions = sorted(versions, key=lambda x: LooseVersion(x['tag'].lower())) + return sorted_versions