optimize check_packages lists construction

master
kewl fft 2023-07-08 18:51:35 +01:00
parent 8d177a7550
commit 2a076dc6a0
1 changed files with 2 additions and 12 deletions

View File

@ -138,18 +138,8 @@ def check_packages(module, packages):
"""
Inform the user what would change if the module were run
"""
would_be_changed = []
diff = {
'before': '',
'after': '',
}
for package in packages:
installed = package_installed(module, package)
if not installed:
would_be_changed.append(package)
if module._diff:
diff['after'] += package + "\n"
would_be_changed = [package for package in packages if not package_installed(module, package)]
diff = {'before': '', 'after': '\n'.join(package for package in would_be_changed if module._diff)}
if would_be_changed:
status = True