From 93c5781f61aa13c951c06840f5c611698710461c Mon Sep 17 00:00:00 2001 From: Zhikang Zhang Date: Mon, 26 Nov 2018 11:12:36 -0500 Subject: [PATCH] pip: Fix the mistake replacement from 'distribute' to 'setuptools' (#47403) * Fix the mistake replace from distribute to setuptools * Add a testcase for this bug --- lib/ansible/modules/packaging/language/pip.py | 4 ++-- test/integration/targets/pip/tasks/pip.yml | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 9b39cd3fd33..c58ce92f016 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -513,8 +513,8 @@ class Package: name_string = separator.join((name_string, version_string)) try: self._requirement = Requirement.parse(name_string) - # old pkg_resource will replace 'setuptools' with 'distribute' when it already installed - if self._requirement.project_name == "distribute": + # old pkg_resource will replace 'setuptools' with 'distribute' when it's already installed + if self._requirement.project_name == "distribute" and "setuptools" in name_string: self.package_name = "setuptools" self._requirement.project_name = "setuptools" else: diff --git a/test/integration/targets/pip/tasks/pip.yml b/test/integration/targets/pip/tasks/pip.yml index b7036de99de..7c924d5a0ed 100644 --- a/test/integration/targets/pip/tasks/pip.yml +++ b/test/integration/targets/pip/tasks/pip.yml @@ -499,3 +499,15 @@ pip: name: "{{ pip_test_packages }}" state: absent + +# https://github.com/ansible/ansible/issues/47198 +- name: try to remove distribute + pip: + state: "absent" + name: "distribute" + ignore_errors: yes + register: remove_distribute + +- name: inspect the cmd + assert: + that: "'distribute' in remove_distribute.cmd"