Skip to content

Commit 9bfdd20

Browse files
committed
Improves auto-generated wording of method references.
1 parent 444d7f6 commit 9bfdd20

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

scripts/generate_module_hints.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
core_version_hint_above = (2, 13)
3131
ansible_version_hint_above = (6, )
3232
reference_re = re.compile(r'([MLBIUROCVEP]|RV)\(([^)]+)\)')
33+
meth_module_re = re.compile(r'(:meth:`[^`]*`\s+)module')
3334
modules_py = StringIO()
3435
modules_header_py = StringIO()
3536
types_py = StringIO()
@@ -272,10 +273,13 @@ def replace(match: re.Match[str]) -> str:
272273
else:
273274
raise ValueError(f'Unknown reference mode {mode}')
274275

275-
return reference_re.sub(
276-
replace,
277-
# remove any raw sphinx references
278-
content.replace(':ref:', '')
276+
return meth_module_re.sub(
277+
lambda match: match.group(1) + 'method',
278+
reference_re.sub(
279+
replace,
280+
# remove any raw sphinx references
281+
content.replace(':ref:', '')
282+
)
279283
).replace('\\', '\\\\')
280284

281285

src/suitable/_modules.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ def copy(
968968
Works only when ``dest`` is a file. Creates the file if it does
969969
not exist.
970970
For advanced formatting or if ``content`` contains a variable, use
971-
the :meth:`template` module.
971+
the :meth:`template` method.
972972
:param dest:
973973
Remote absolute path where the file should be copied to.
974974
If ``src`` is a directory, this must be a directory too.
@@ -1725,7 +1725,7 @@ def dnf5(
17251725
This is effectively a no-op in the dnf5 module as dnf5 itself
17261726
handles downloading a https url as the source of the rpm, but is
17271727
an accepted parameter for feature parity/compatibility with the
1728-
:meth:`dnf` module.
1728+
:meth:`dnf` method.
17291729
:param sslverify:
17301730
Disables SSL validation of the repository server for this
17311731
transaction.
@@ -1957,7 +1957,7 @@ def file(
19571957
If ``file``, even with other options (such as ``mode``), the file
19581958
will be modified if it exists but will NOT be created if it does
19591959
not exist. Set to ``touch`` or use the :meth:`copy` or
1960-
:meth:`template` module if you want to create the file if it does
1960+
:meth:`template` method if you want to create the file if it does
19611961
not exist.
19621962
If ``hard``, the hard link will be created or changed.
19631963
If ``link``, the symbolic link will be created or changed.
@@ -4012,7 +4012,7 @@ def replace(
40124012
can get the original file back if you somehow clobbered it
40134013
incorrectly.
40144014
:param others:
4015-
All arguments accepted by the :meth:`file` module also work here.
4015+
All arguments accepted by the :meth:`file` method also work here.
40164016
:param encoding:
40174017
The character encoding for reading and writing the file.
40184018
:param mode:
@@ -4262,7 +4262,7 @@ def set_fact(
42624262
:ref:`ansible.builtin <ansible_collections.ansible.builtin.set_fact_module>`
42634263
42644264
:param key_value:
4265-
The :meth:`set_fact` module takes ``key=value`` pairs or
4265+
The :meth:`set_fact` method takes ``key=value`` pairs or
42664266
``key: value`` (YAML notation) as variables to set in the playbook
42674267
scope. The 'key' is the resulting variable name and the value is,
42684268
of course, the value of said variable.
@@ -5027,7 +5027,7 @@ def unarchive(
50275027
If ``remote_src=yes`` and ``src`` contains ``://``, the remote
50285028
machine will download the file from the URL first. (version_added
50295029
2.0). This is only for simple cases, for full download support use
5030-
the :meth:`get_url` module.
5030+
the :meth:`get_url` method.
50315031
:param dest:
50325032
Remote absolute path where the archive should be unpacked.
50335033
The given path must exist. Base directory is not created by this
@@ -8314,7 +8314,7 @@ def win_copy(
83148314
When used instead of ``src``, sets the contents of a file directly
83158315
to the specified value.
83168316
This is for simple values, for anything complex or with formatting
8317-
please switch to the :meth:`win_template` module.
8317+
please switch to the :meth:`win_template` method.
83188318
:param decrypt:
83198319
This option controls the autodecryption of source files using
83208320
vault.
@@ -8728,7 +8728,7 @@ def win_file(
87288728
If ``directory``, all immediate subdirectories will be created if
87298729
they do not exist.
87308730
If ``file``, the file will NOT be created if it does not exist,
8731-
see the :meth:`win_copy` or :meth:`win_template` module if you
8731+
see the :meth:`win_copy` or :meth:`win_template` method if you
87328732
want that behavior.
87338733
If ``absent``, directories will be recursively deleted, and files
87348734
will be removed.
@@ -9880,7 +9880,7 @@ def win_service(
98809880
A newly created service will default to ``LocalSystem``.
98819881
If using a custom user account, it must have the
98829882
``SeServiceLogonRight`` granted to be able to start up. You can
9883-
use the :meth:`win_user_right` module to grant this user right for
9883+
use the :meth:`win_user_right` method to grant this user right for
98849884
you.
98859885
Set to ``NT SERVICE\\service name`` to run as the NT SERVICE
98869886
account for that service.

0 commit comments

Comments
 (0)