From 01887bf3593373b3be873caff842986b6b79fda3 Mon Sep 17 00:00:00 2001
From: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Date: Mon, 1 Nov 2021 19:59:15 +1300
Subject: [PATCH] pipx: minor refactor (#3647)

* pipx: minor refactor

* added changelog fragment
---
 changelogs/fragments/3634-pipx-improve-changed.yaml |  2 ++
 plugins/modules/packaging/language/pipx.py          | 11 +++++------
 2 files changed, 7 insertions(+), 6 deletions(-)
 create mode 100644 changelogs/fragments/3634-pipx-improve-changed.yaml

diff --git a/changelogs/fragments/3634-pipx-improve-changed.yaml b/changelogs/fragments/3634-pipx-improve-changed.yaml
new file mode 100644
index 0000000000..09c3ceee30
--- /dev/null
+++ b/changelogs/fragments/3634-pipx-improve-changed.yaml
@@ -0,0 +1,2 @@
+minor_changes:
+    - pipx - minor refactor on the ``changed`` logic (https://github.com/ansible-collections/community.general/pull/3647).
diff --git a/plugins/modules/packaging/language/pipx.py b/plugins/modules/packaging/language/pipx.py
index 53c085ed61..5458941eec 100644
--- a/plugins/modules/packaging/language/pipx.py
+++ b/plugins/modules/packaging/language/pipx.py
@@ -215,7 +215,6 @@ class PipX(CmdStateModuleHelper):
             facts = ansible_facts(self.module, gather_subset=['python'])
             self.command = [facts['python']['executable'], '-m', 'pipx']
 
-        self.vars.set('will_change', False, output=False, change=True)
         self.vars.set('application', self._retrieve_installed(), change=True, diff=True)
 
     def __quit_module__(self):
@@ -223,7 +222,7 @@ class PipX(CmdStateModuleHelper):
 
     def state_install(self):
         if not self.vars.application or self.vars.force:
-            self.vars.will_change = True
+            self.changed = True
             if not self.module.check_mode:
                 self.run_command(params=['state', 'index_url', 'install_deps', 'force', 'python',
                                          {'name_source': [self.vars.name, self.vars.source]}])
@@ -235,7 +234,7 @@ class PipX(CmdStateModuleHelper):
             raise ModuleHelperException(
                 "Trying to upgrade a non-existent application: {0}".format(self.vars.name))
         if self.vars.force:
-            self.vars.will_change = True
+            self.changed = True
         if not self.module.check_mode:
             self.run_command(params=['state', 'index_url', 'install_deps', 'force', 'name'])
 
@@ -249,7 +248,7 @@ class PipX(CmdStateModuleHelper):
         if not self.vars.application:
             raise ModuleHelperException(
                 "Trying to reinstall a non-existent application: {0}".format(self.vars.name))
-        self.vars.will_change = True
+        self.changed = True
         if not self.module.check_mode:
             self.run_command(params=['state', 'name', 'python'])
 
@@ -258,7 +257,7 @@ class PipX(CmdStateModuleHelper):
             raise ModuleHelperException(
                 "Trying to inject packages into a non-existent application: {0}".format(self.vars.name))
         if self.vars.force:
-            self.vars.will_change = True
+            self.changed = True
         if not self.module.check_mode:
             self.run_command(params=['state', 'index_url', 'force', 'name', 'inject_packages'])
 
@@ -272,7 +271,7 @@ class PipX(CmdStateModuleHelper):
 
     def state_upgrade_all(self):
         if self.vars.force:
-            self.vars.will_change = True
+            self.changed = True
         if not self.module.check_mode:
             self.run_command(params=['state', 'include_injected', 'force'])