1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

python_requirements_info - fail when version operator used without version (#3785) (#3793)

* python_requirements_info - fail when version operator used without version

* added changelog fragment

* simplified way of achieving the same result

(cherry picked from commit 59c1859fb3)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-11-26 20:53:58 +01:00 committed by GitHub
parent 35fd4700bf
commit 3d1ca5638b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- python_requirements_info - fails if version operator used without version (https://github.com/ansible-collections/community.general/pull/3785).

View file

@ -121,7 +121,7 @@ def main():
python_version=sys.version,
python_system_path=sys.path,
)
pkg_dep_re = re.compile(r'(^[a-zA-Z][a-zA-Z0-9_-]+)(==|[><]=?)?([0-9.]+)?$')
pkg_dep_re = re.compile(r'(^[a-zA-Z][a-zA-Z0-9_-]+)(?:(==|[><]=?)([0-9.]+))?$')
results = dict(
not_found=[],
@ -131,7 +131,7 @@ def main():
for dep in (module.params.get('dependencies') or []):
match = pkg_dep_re.match(dep)
if match is None:
if not match:
module.fail_json(msg="Failed to parse version requirement '{0}'. Must be formatted like 'ansible>2.6'".format(dep))
pkg, op, version = match.groups()
if op is not None and op not in operations:

View file

@ -25,3 +25,15 @@
that:
- "'installed' in dep_info.valid.pip"
- "'notreal' in dep_info.not_found"
- name: wrong specs
python_requirements_info:
dependencies:
- ansible<
register: wrong_spec1
ignore_errors: true
- name: ensure wrong specs return error
assert:
that:
- wrong_spec1 is failed