From b697da39c832e5b61f947121e9fcafecb69dab7d Mon Sep 17 00:00:00 2001 From: Zhikang Zhang Date: Mon, 22 Oct 2018 16:21:45 -0400 Subject: [PATCH] Fix problem where pip module cannot accept multiple extras PR #46937 Fixes #46519 --- lib/ansible/modules/packaging/language/pip.py | 10 ++++++++-- test/integration/targets/pip/tasks/pip.yml | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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 2c650eab385..dd84724f262 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 }}"