-
Notifications
You must be signed in to change notification settings - Fork 23.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ansible-galaxy - enforce string versions and fix installing prereleases from scm sources #79112
Changes from all commits
2b0f4fb
05b40e0
432429a
ee54ce5
5d808ab
e68625f
f4aa56d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
minor_changes: | ||
- ansible-galaxy collection - consolidate message when an invalid version is encountered so it's | ||
the same regardless of codepath. | ||
bugfixes: | ||
- > | ||
ansible-galaxy collection - allow pre-releases without --pre if the pre-release is already installed | ||
or if the requirement is a pre-release. | ||
- > | ||
ansible-galaxy collection - enforce str versions when loading user-requested requirements | ||
(https://github.com/ansible/ansible/issues/78067, https://github.com/ansible/ansible/issues/79109). | ||
- > | ||
ansible-galaxy collection - fix installing pre-releases from virtual sources | ||
(https://github.com/ansible/ansible/issues/79168). |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,10 @@ | |
from ansible.galaxy.collection import HAS_PACKAGING, PkgReq | ||
from ansible.module_utils._text import to_bytes, to_native, to_text | ||
from ansible.module_utils.common.arg_spec import ArgumentSpecValidator | ||
from ansible.module_utils.six import string_types | ||
from ansible.utils.collection_loader import AnsibleCollectionRef | ||
from ansible.utils.display import Display | ||
from ansible.utils.version import SemanticVersion | ||
|
||
|
||
_ALLOW_CONCRETE_POINTER_IN_SOURCE = False # NOTE: This is a feature flag | ||
|
@@ -428,11 +430,13 @@ def from_requirement_dict(cls, collection_req, art_mgr, validate_signature_optio | |
if req_type not in {'galaxy', 'subdirs'} and req_version == '*': | ||
req_version = art_mgr.get_direct_collection_version(tmp_inst_req) | ||
|
||
return cls( | ||
req = cls( | ||
req_name, req_version, | ||
req_source, req_type, | ||
req_signature_sources, | ||
) | ||
req.assert_version() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making assertions when an object holding invalid data is already initialized is an anti-pattern. This should be checked in or before init... |
||
return req | ||
|
||
def __repr__(self): | ||
return ( | ||
|
@@ -551,6 +555,28 @@ def is_online_index_pointer(self): | |
def source_info(self): | ||
return self._source_info | ||
|
||
def assert_version(self): | ||
if not self.is_scm: | ||
version_req = "A SemVer-compliant version or '*' is required. See https://semver.org to learn how to compose it correctly." | ||
else: | ||
version_req = "A string version is required." | ||
|
||
name = self.fqcn if self.fqcn is not None else self | ||
version_err = f"Invalid version found for the collection '{name}': {self.ver} ({type(self.ver)}). {version_req}" | ||
if not isinstance(self.ver, string_types): | ||
raise TypeError(version_err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a less invasive approach? #81694 |
||
|
||
# FIXME: validate individual requirements are valid semver | ||
req_qualifiers = [">", "<", "!", "="] | ||
if any(qualifier in self.ver for qualifier in req_qualifiers): | ||
return | ||
|
||
if not (self.is_scm or self.ver == '*'): | ||
try: | ||
SemanticVersion(self.ver) | ||
except ValueError as ex: | ||
raise TypeError(version_err) from ex | ||
|
||
|
||
RequirementNamedTuple = namedtuple('Requirement', ('fqcn', 'ver', 'src', 'type', 'signature_sources')) # type: ignore[name-match] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't start scanning the disk
if force_deps
— all this is being discarded on the next line in 50% of cases.