Skip to content

Commit

Permalink
Allow to specify constraints.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Sep 26, 2023
1 parent 43c8401 commit adc766d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/99-constraints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Allow to specify constraints when determining the latest version of a collection from Galaxy (https://github.com/ansible-community/antsibull-core/pull/99)."
9 changes: 8 additions & 1 deletion src/antsibull_core/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ async def get_release_info(
return collection_info

async def get_latest_matching_version(
self, collection: str, version_spec: str, pre: bool = False
self,
collection: str,
version_spec: str,
pre: bool = False,
constraint: semver.SimpleSpec | None = None,
) -> semver.Version:
"""
Get the latest version of a collection that matches a specification.
Expand All @@ -338,6 +342,7 @@ async def get_latest_matching_version(
and pre=True, if the available versions are 2.0.0-a1 and 2.0.0-a2, then 2.0.0-a2
will be returned. If the available versions are 2.0.0 and 2.1.0-b2, 2.0.0 will be
returned since non-pre-releases are preferred. The default is False
:kwarg constraint: If provided, only consider versions that match this specification.
:returns: :obj:`semantic_version.Version` of the latest collection version that satisfied
the specification.
Expand All @@ -356,6 +361,8 @@ async def get_latest_matching_version(
spec = semver.SimpleSpec(version_spec)
prereleases = []
for version in (v for v in sem_versions if v in spec):
if constraint is not None and version not in constraint:
continue
# If this is a pre-release, first check if there's a non-pre-release that
# will satisfy the version_spec.
if version.prerelease:
Expand Down

0 comments on commit adc766d

Please sign in to comment.