forked from teemtee/tmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate plugin documentation from their sources (teemtee#2549)
This required a small refactoring of how field properties were stored. Instead of treating them as something owned by CLI options, they have their use outside of CLI area, and must exist in field metadata to be consumable in general. Now we have a template, a script, a section in docs. Fixing the content would be the next step...
- Loading branch information
Showing
14 changed files
with
332 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.. _plugins: | ||
.. _plugin_introduction: | ||
|
||
=========================== | ||
Plugin Introduction | ||
|
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,24 @@ | ||
.. _plugins: | ||
|
||
Plugins | ||
======= | ||
|
||
Here you will find documentation for plugins shipped with tmt. | ||
|
||
.. warning:: | ||
|
||
Please, be aware that the documentation below is a work in progress. We are | ||
working on fixing it, adding missing bits and generally making it better. | ||
Also, it was originaly used for command line help only, therefore the | ||
formatting is often suboptional. | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
Discover <discover> | ||
Provision <provision> | ||
Prepare <prepare> | ||
Execute <execute> | ||
Finish <finish> | ||
Report <report> | ||
Test Checks <test-checks> |
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,72 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
import textwrap | ||
|
||
import tmt.log | ||
import tmt.plugins | ||
import tmt.steps.discover | ||
import tmt.steps.execute | ||
import tmt.steps.finish | ||
import tmt.steps.prepare | ||
import tmt.steps.provision | ||
import tmt.steps.report | ||
import tmt.utils | ||
from tmt.utils import Path, render_template_file | ||
|
||
HELP = textwrap.dedent(""" | ||
Usage: generate-plugins.py <STEP-NAME> <TEMPLATE-PATH> <OUTPUT-PATH> | ||
Generate pages for step plugins sources. | ||
""").strip() | ||
|
||
|
||
def main() -> None: | ||
if len(sys.argv) != 4: | ||
print(HELP) | ||
|
||
sys.exit(1) | ||
|
||
step_name = sys.argv[1] | ||
template_filepath = Path(sys.argv[2]) | ||
output_filepath = Path(sys.argv[3]) | ||
|
||
# We will need a logger... | ||
logger = tmt.log.Logger.create() | ||
logger.add_console_handler() | ||
|
||
# ... explore available plugins... | ||
tmt.plugins.explore(logger) | ||
|
||
if step_name == 'discover': | ||
registry = tmt.steps.discover.DiscoverPlugin._supported_methods | ||
|
||
elif step_name == 'execute': | ||
registry = tmt.steps.execute.ExecutePlugin._supported_methods | ||
|
||
elif step_name == 'finish': | ||
registry = tmt.steps.finish.FinishPlugin._supported_methods | ||
|
||
elif step_name == 'prepare': | ||
registry = tmt.steps.prepare.PreparePlugin._supported_methods | ||
|
||
elif step_name == 'provision': | ||
registry = tmt.steps.provision.ProvisionPlugin._supported_methods | ||
|
||
elif step_name == 'report': | ||
registry = tmt.steps.report.ReportPlugin._supported_methods | ||
|
||
else: | ||
raise tmt.utils.GeneralError(f"Unhandled step name '{step_name}'.") | ||
|
||
# ... and render the template. | ||
output_filepath.write_text(render_template_file( | ||
template_filepath, | ||
STEP=step_name, | ||
REGISTRY=registry, | ||
container_fields=tmt.utils.container_fields, | ||
container_field=tmt.utils.container_field)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,62 @@ | ||
:tocdepth: 0 | ||
|
||
.. _/plugins/{{ STEP }}: | ||
|
||
{{ STEP | capitalize }} Plugins | ||
{{ '=' * (8 + (STEP | length)) }} | ||
|
||
{% for PLUGIN_ID in REGISTRY.iter_plugin_ids() %} | ||
{% set method = REGISTRY.get_plugin(PLUGIN_ID) %} | ||
{% set PLUGIN = method.class_ %} | ||
|
||
.. _plugins/{{ STEP }}/{{ PLUGIN_ID | strip }}: | ||
|
||
{{ PLUGIN_ID }} | ||
{{ '^' * (PLUGIN_ID | length)}} | ||
|
||
{# | ||
TODO: once we start getting reviewed and polished plugins, drop the warning | ||
for those that would be done and ready. Probably with some temporary list | ||
to which we would add their names. | ||
#} | ||
.. warning:: | ||
|
||
Please, be aware that the documentation below is a work in progress. We are | ||
working on fixing it, adding missing bits and generally making it better. | ||
Also, it was originaly used for command line help only, therefore the | ||
formatting is often suboptional. | ||
|
||
{% if PLUGIN.__doc__ %} | ||
{{ PLUGIN.__doc__ | dedent | strip }} | ||
{% endif %} | ||
|
||
**Configuration** | ||
|
||
{% for field in container_fields(PLUGIN._data_class) %} | ||
{% if ( | ||
field.name not in ('how', 'name', 'where', '_OPTIONLESS_FIELDS') | ||
and field.internal != true | ||
and ( | ||
not PLUGIN._data_class._OPTIONLESS_FIELDS | ||
or field.name not in PLUGIN._data_class._OPTIONLESS_FIELDS | ||
) | ||
) %} | ||
{% set _, option, _, metadata = container_field(PLUGIN._data_class, field.name) %} | ||
|
||
{% if metadata.metavar %} | ||
{{ option }}: ``{{ metadata.metavar }}`` | ||
{% elif metadata.default is boolean %} | ||
{{ option }}: ``true|false`` | ||
{% else %} | ||
{{ option }}: | ||
{% endif %} | ||
{% if metadata.help %} | ||
{{ metadata.help | strip | indent(4, first=true) }} | ||
{% endif %} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% if not loop.last %} | ||
---- | ||
{% endif %} | ||
{% endfor %} |
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
Oops, something went wrong.