-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move label generating code to one place.
- Loading branch information
1 parent
5ef98a4
commit 8709d51
Showing
11 changed files
with
187 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Author: Felix Fontein <[email protected]> | ||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or | ||
# https://www.gnu.org/licenses/gpl-3.0.txt) | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# SPDX-FileCopyrightText: 2023, Ansible Project | ||
""" | ||
Label helpers. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from antsibull_docs.utils.rst import massage_rst_label | ||
|
||
|
||
def get_plugin_ref(plugin_fqcn: str, plugin_type: str) -> str: | ||
return f"ansible_collections.{plugin_fqcn}_{plugin_type}" | ||
|
||
|
||
def get_attribute_ref( | ||
plugin_fqcn: str, | ||
plugin_type: str, | ||
role_entrypoint: str | None, | ||
attribute: str, | ||
) -> str: | ||
ref = massage_rst_label(attribute) | ||
ep = ( | ||
f"{role_entrypoint}__" | ||
if role_entrypoint is not None and plugin_type == "role" | ||
else "" | ||
) | ||
return f"{get_plugin_ref(plugin_fqcn, plugin_type)}__attribute-{ep}{ref}" | ||
|
||
|
||
def get_option_ref( | ||
plugin_fqcn: str, | ||
plugin_type: str, | ||
role_entrypoint: str | None, | ||
option: list[str], | ||
) -> str: | ||
ref = "/".join(massage_rst_label(part) for part in option) | ||
ep = ( | ||
f"{role_entrypoint}__" | ||
if role_entrypoint is not None and plugin_type == "role" | ||
else "" | ||
) | ||
return f"{get_plugin_ref(plugin_fqcn, plugin_type)}__parameter-{ep}{ref}" | ||
|
||
|
||
def get_return_value_ref( | ||
plugin_fqcn: str, | ||
plugin_type: str, | ||
role_entrypoint: str | None, | ||
return_value: list[str], | ||
) -> str: | ||
ref = "/".join(massage_rst_label(part) for part in return_value) | ||
ep = ( | ||
f"{role_entrypoint}__" | ||
if role_entrypoint is not None and plugin_type == "role" | ||
else "" | ||
) | ||
return f"{get_plugin_ref(plugin_fqcn, plugin_type)}__return-{ep}{ref}" | ||
|
||
|
||
def get_requirements_ref( | ||
plugin_fqcn: str, | ||
plugin_type: str, | ||
role_entrypoint: str | None = None, | ||
) -> str: | ||
ep = ( | ||
f"-{role_entrypoint}" | ||
if role_entrypoint is not None and plugin_type == "role" | ||
else "" | ||
) | ||
return f"{get_plugin_ref(plugin_fqcn, plugin_type)}_requirements{ep}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.