replace concatenations with f-string in plugins (#10285)
Some checks are pending
EOL CI / EOL Sanity (Ⓐ2.16) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py2.7) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.11) (push) Waiting to run
EOL CI / EOL Units (Ⓐ2.16+py3.6) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+alpine3+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+fedora38+py:azp/posix/3/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/1/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/2/) (push) Waiting to run
EOL CI / EOL I (Ⓐ2.16+opensuse15+py:azp/posix/3/) (push) Waiting to run
nox / Run extra sanity tests (push) Waiting to run

* replace concatenations with f-string in plugins

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-06-24 07:10:19 +12:00 committed by GitHub
parent d4f2b2fb55
commit 3ab7a898c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 20 additions and 14 deletions

View file

@ -0,0 +1,7 @@
minor_changes:
- dense callback plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
- mail callback plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
- wsl connection plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
- jc filter plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
- iocage inventory plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).
- xen_orchestra inventory plugin - use f-strings instead of concatenation (https://github.com/ansible-collections/community.general/pull/10285).

View file

@ -263,12 +263,8 @@ class CallbackModule(CallbackModule_default):
sys.stdout.write(colors[self.hosts[name]['state']] + name + vt100.reset) sys.stdout.write(colors[self.hosts[name]['state']] + name + vt100.reset)
sys.stdout.flush() sys.stdout.flush()
# if result._result.get('diff', False):
# sys.stdout.write('\n' + vt100.linewrap)
sys.stdout.write(vt100.linewrap) sys.stdout.write(vt100.linewrap)
# self.keep = True
def _display_task_banner(self): def _display_task_banner(self):
if not self.shown_title: if not self.shown_title:
self.shown_title = True self.shown_title = True
@ -312,12 +308,12 @@ class CallbackModule(CallbackModule_default):
delegated_vars = result._result.get('_ansible_delegated_vars', None) delegated_vars = result._result.get('_ansible_delegated_vars', None)
if delegated_vars: if delegated_vars:
sys.stdout.write(f"{vt100.reset + result._host.get_name()}>{colors[status]}{delegated_vars['ansible_host']}") sys.stdout.write(f"{vt100.reset}{result._host.get_name()}>{colors[status]}{delegated_vars['ansible_host']}")
else: else:
sys.stdout.write(result._host.get_name()) sys.stdout.write(result._host.get_name())
sys.stdout.write(f": {dump}\n") sys.stdout.write(f": {dump}\n")
sys.stdout.write(vt100.reset + vt100.save + vt100.clearline) sys.stdout.write(f"{vt100.reset}{vt100.save}{vt100.clearline}")
sys.stdout.flush() sys.stdout.flush()
if status == 'changed': if status == 'changed':

View file

@ -212,7 +212,8 @@ class CallbackModule(CallbackBase):
if self.itembody: if self.itembody:
body += self.itembody body += self.itembody
elif result._result.get('failed_when_result') is True: elif result._result.get('failed_when_result') is True:
fail_cond = self.indent('failed_when:\n- ' + '\n- '.join(result._task.failed_when)) fail_cond_list = '\n- '.join(result._task.failed_when)
fail_cond = self.indent(f"failed_when:\n- {fail_cond_list}")
body += f"due to the following condition:\n\n{fail_cond}\n\n" body += f"due to the following condition:\n\n{fail_cond}\n\n"
elif result._result.get('msg'): elif result._result.get('msg'):
body += self.body_blob(result._result['msg'], 'message') body += self.body_blob(result._result['msg'], 'message')

View file

@ -522,8 +522,10 @@ class Connection(ConnectionBase):
if u'PID check failed' in msg: if u'PID check failed' in msg:
raise AnsibleError('paramiko version issue, please upgrade paramiko on the machine running ansible') raise AnsibleError('paramiko version issue, please upgrade paramiko on the machine running ansible')
elif u'Private key file is encrypted' in msg: elif u'Private key file is encrypted' in msg:
msg = f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : ' + \ msg = (
f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : '
f'{msg}\nTo connect as a different user, use -u <username>.' f'{msg}\nTo connect as a different user, use -u <username>.'
)
raise AnsibleConnectionFailure(msg) raise AnsibleConnectionFailure(msg)
else: else:
raise AnsibleConnectionFailure(msg) raise AnsibleConnectionFailure(msg)
@ -656,7 +658,7 @@ class Connection(ConnectionBase):
chan.shutdown_write() chan.shutdown_write()
except socket.timeout: except socket.timeout:
raise AnsibleError('ssh timed out waiting for privilege escalation.\n' + to_text(become_output)) raise AnsibleError(f'ssh timed out waiting for privilege escalation.\n{to_text(become_output)}')
stdout = b''.join(chan.makefile('rb', bufsize)) stdout = b''.join(chan.makefile('rb', bufsize))
stderr = b''.join(chan.makefile_stderr('rb', bufsize)) stderr = b''.join(chan.makefile_stderr('rb', bufsize))

View file

@ -143,11 +143,11 @@ def jc_filter(data, parser, quiet=True, raw=False):
# old API (jc v1.17.7 and lower) # old API (jc v1.17.7 and lower)
else: else:
jc_parser = importlib.import_module('jc.parsers.' + parser) jc_parser = importlib.import_module(f'jc.parsers.{parser}')
return jc_parser.parse(data, quiet=quiet, raw=raw) return jc_parser.parse(data, quiet=quiet, raw=raw)
except Exception as e: except Exception as e:
raise AnsibleFilterError('Error in jc filter plugin: %s' % e) raise AnsibleFilterError(f'Error in jc filter plugin: {e}')
class FilterModule(object): class FilterModule(object):

View file

@ -350,7 +350,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
for hostname, host_vars in results['_meta']['hostvars'].items(): for hostname, host_vars in results['_meta']['hostvars'].items():
iocage_hooks = [] iocage_hooks = []
for hook in hooks_results: for hook in hooks_results:
path = "/" + iocage_pool + "/iocage/jails/" + hostname + "/root" + hook path = f"/{iocage_pool}/iocage/jails/{hostname}/root{hook}"
cmd_cat_hook = cmd.copy() cmd_cat_hook = cmd.copy()
cmd_cat_hook.append('cat') cmd_cat_hook.append('cat')
cmd_cat_hook.append(path) cmd_cat_hook.append(path)

View file

@ -224,7 +224,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
vm_name_list.append(vm['name_label']) vm_name_list.append(vm['name_label'])
else: else:
vm_duplicate_count = vm_name_list.count(vm['name_label']) vm_duplicate_count = vm_name_list.count(vm['name_label'])
entry_name = vm['name_label'] + "_" + str(vm_duplicate_count) entry_name = f"{vm['name_label']}_{vm_duplicate_count}"
vm_name_list.append(vm['name_label']) vm_name_list.append(vm['name_label'])
else: else:
entry_name = uuid entry_name = uuid
@ -284,7 +284,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
host_name_list.append(host['name_label']) host_name_list.append(host['name_label'])
else: else:
host_duplicate_count = host_name_list.count(host['name_label']) host_duplicate_count = host_name_list.count(host['name_label'])
entry_name = host['name_label'] + "_" + str(host_duplicate_count) entry_name = f"{host['name_label']}_{host_duplicate_count}"
host_name_list.append(host['name_label']) host_name_list.append(host['name_label'])
else: else:
entry_name = host['uuid'] entry_name = host['uuid']