diff --git a/changelogs/fragments/issue46937-pr46519-pr47449-fix-pip-multiple-extras.yaml b/changelogs/fragments/issue46937-pr46519-pr47449-fix-pip-multiple-extras.yaml new file mode 100644 index 00000000000..fcdab08a9fd --- /dev/null +++ b/changelogs/fragments/issue46937-pr46519-pr47449-fix-pip-multiple-extras.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fix pip module so that it can recognize multiple extras diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 2503a103517..5cc330cf5d5 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -292,11 +292,16 @@ def _recover_package_name(names): # reconstruct the names name_parts = [] package_names = [] + in_brackets = False for name in names: - if _is_package_name(name): + if _is_package_name(name) and not in_brackets: if name_parts: package_names.append(",".join(name_parts)) name_parts = [] + if "[" in name: + in_brackets = True + if in_brackets and "]" in name: + in_brackets = False name_parts.append(name) package_names.append(",".join(name_parts)) return package_names @@ -498,6 +503,7 @@ class Package: # old pkg_resource will replace 'setuptools' with 'distribute' when it already installed if self._requirement.project_name == "distribute": self.package_name = "setuptools" + self._requirement.project_name = "setuptools" else: self.package_name = self._requirement.project_name self._plain_package = True @@ -639,7 +645,7 @@ def main(): "Please keep the version specifier, but remove the 'version' argument." ) # if the version specifier is provided by version, append that into the package - packages[0] = Package(packages[0].package_name, version) + packages[0] = Package(to_native(packages[0]), version) if module.params['editable']: args_list = [] # used if extra_args is not used at all diff --git a/test/integration/targets/pip/tasks/pip.yml b/test/integration/targets/pip/tasks/pip.yml index e34e932d1ca..b13c3ac2a52 100644 --- a/test/integration/targets/pip/tasks/pip.yml +++ b/test/integration/targets/pip/tasks/pip.yml @@ -470,6 +470,10 @@ assert: that: "version13 is failed" +- name: try install package with setuptools extras + pip: + name: "{{pip_test_package}}[dev,test]" + - name: clean up pip: name: "{{ pip_test_packages }}"