Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add period to end of new plugin statements in changelog #162

Merged
merged 16 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ title: Ansible Changelog Tool
output_formats:
- rst
- md
add_plugin_period: false
2 changes: 2 additions & 0 deletions changelogs/fragments/162-add-plugin-period.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "Adds period where needed at end of new plugin short descriptions. Controlled by the ``add_plugin_period`` option in the config file (https://github.com/ansible-community/antsibull-changelog/issues/87)."
8 changes: 8 additions & 0 deletions docs/changelog-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ This document describes all settings that are supported in

## General options

### `add_plugin_period` (boolean)

The default value is `false` for existing configurations, and `true` for
new configurations.

If set to `false`, the plugin short description is used. If set to `true`, a period is added to the end of the plugin short description if no other end punctuation is present. Setting to `true` complies with the [Ansible changelog format](https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs-how-to-format).


### `always_refresh` (string)

Allowed values are `none`, `full`, or a comma-separated combination of
Expand Down
3 changes: 3 additions & 0 deletions src/antsibull_changelog/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ def _do_refresh( # pylint: disable=too-many-arguments
version=changes.latest_version,
force_reload=args.reload_plugins,
use_ansible_doc=args.use_ansible_doc,
add_plugin_period=config.add_plugin_period,
)
allow_removals = refresh_plugins == "allow-removal"

Expand Down Expand Up @@ -665,6 +666,7 @@ def command_release(args: Any) -> int:
version=version,
force_reload=args.reload_plugins,
use_ansible_doc=args.use_ansible_doc,
add_plugin_period=config.add_plugin_period,
)
fragments = load_fragments(paths, config)
lint_rc = lint_fragments(config, fragments, [])
Expand Down Expand Up @@ -749,6 +751,7 @@ def command_generate(args: Any) -> int: # pylint: disable=too-many-locals
collection_details=collection_details,
version=changes.latest_version,
force_reload=args.reload_plugins,
add_plugin_period=config.add_plugin_period,
)
if output and len(config.output_formats) > 1 and not output_format:
print(
Expand Down
5 changes: 5 additions & 0 deletions src/antsibull_changelog/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class ChangelogConfig:
is_other_project: bool
sections: Mapping[str, str]
output_formats: set[TextFormat]
add_plugin_period: bool

def __init__(
self,
Expand Down Expand Up @@ -465,6 +466,8 @@ def __init__(
f"Found unknown extension in output_formats: {exc}"
) from exc

self.add_plugin_period = self.config.get("add_plugin_period", False)

self._validate_config(ignore_is_other_project)

def _validate_config(self, ignore_is_other_project: bool) -> None:
Expand Down Expand Up @@ -514,6 +517,7 @@ def store(self) -> None: # noqa: C901
"trivial_section_name": self.trivial_section_name,
"ignore_other_fragment_extensions": self.ignore_other_fragment_extensions,
"sanitize_changelog": self.sanitize_changelog,
"add_plugin_period": self.add_plugin_period,
}
if not self.is_collection:
if self.use_semantic_versioning:
Expand Down Expand Up @@ -592,6 +596,7 @@ def default(
"use_fqcn": True,
"ignore_other_fragment_extensions": True,
"sanitize_changelog": True,
"add_plugin_period": True,
}
if title is not None:
config["title"] = title
Expand Down
27 changes: 22 additions & 5 deletions src/antsibull_changelog/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def __init__(

@staticmethod
def from_dict(
data: dict[str, dict[str, dict[str, Any]]], category: str = "plugin"
data: dict[str, dict[str, dict[str, Any]]],
category: str = "plugin",
add_plugin_period: bool = False,
) -> list[PluginDescription]:
"""
Return a list of ``PluginDescription`` objects from the given data.
Expand All @@ -79,12 +81,19 @@ def from_dict(

for plugin_type, plugin_data in data.items():
for plugin_name, plugin_details in plugin_data.items():
description = plugin_details["description"]
if (
add_plugin_period
and description
and not description.endswith((".", ",", "!", "?"))
):
description += "."
plugins.append(
PluginDescription(
plugin_type=plugin_type,
name=plugin_name,
namespace=plugin_details.get("namespace"),
description=plugin_details["description"],
description=description,
version_added=plugin_details["version_added"],
category=category,
)
Expand Down Expand Up @@ -543,12 +552,13 @@ def _refresh_plugin_cache(
return plugins_data


def load_plugins(
def load_plugins( # pylint: disable=too-many-arguments
paths: PathsConfig,
collection_details: CollectionDetails,
version: str,
force_reload: bool = False,
use_ansible_doc: bool = False,
add_plugin_period: bool = False,
) -> list[PluginDescription]:
"""
Load plugins from ansible-doc.
Expand Down Expand Up @@ -582,10 +592,17 @@ def load_plugins(
)
store_yaml(plugin_cache_path, plugins_data)

plugins = PluginDescription.from_dict(plugins_data["plugins"])
plugins = PluginDescription.from_dict(
plugins_data["plugins"],
add_plugin_period=add_plugin_period,
)
if "objects" in plugins_data:
plugins.extend(
PluginDescription.from_dict(plugins_data["objects"], category="object")
PluginDescription.from_dict(
plugins_data["objects"],
category="object",
add_plugin_period=add_plugin_period,
)
)

return plugins
36 changes: 19 additions & 17 deletions tests/functional/test_changelog_basic_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
notesdir: fragments
prelude_section_name: release_summary
new_plugins_after_name: removed_features
add_plugin_period: true
sections:
- ['major_changes', 'Major Changes']
- ['minor_changes', 'Minor Changes']
Expand Down Expand Up @@ -264,15 +265,15 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
assert changelog["releases"]["2.10"]["modules"] == [
{
"name": "test",
"description": "This is a test module",
"description": "This is a test module.",
"namespace": "",
},
]
assert changelog["releases"]["2.10"]["plugins"] == {
"lookup": [
{
"name": "bar",
"description": "A foo bar lookup",
"description": "A foo bar lookup.",
"namespace": None,
},
],
Expand Down Expand Up @@ -308,12 +309,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo bar lookup
- bar - A foo bar lookup.

New Modules
-----------

- test - This is a test module
- test - This is a test module.
"""
)

Expand Down Expand Up @@ -399,15 +400,15 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
assert changelog["releases"]["2.10"]["modules"] == [
{
"name": "test",
"description": "This is a TEST module",
"description": "This is a TEST module.",
"namespace": "",
},
]
assert changelog["releases"]["2.10"]["plugins"] == {
"lookup": [
{
"name": "bar",
"description": "A foo_bar lookup",
"description": "A foo_bar lookup.",
"namespace": None,
},
],
Expand Down Expand Up @@ -441,12 +442,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo_bar lookup
- bar - A foo_bar lookup.

New Modules
-----------

- test - This is a TEST module
- test - This is a TEST module.
"""
)

Expand Down Expand Up @@ -539,7 +540,7 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
assert changelog["releases"]["2.10.1b1"]["modules"] == [
{
"name": "test_new",
"description": "This is ANOTHER test module",
"description": "This is ANOTHER test module.",
"namespace": "",
},
]
Expand Down Expand Up @@ -569,7 +570,7 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
New Modules
-----------

- test_new - This is ANOTHER test module
- test_new - This is ANOTHER test module.

v2.10
=====
Expand All @@ -592,12 +593,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo_bar lookup
- bar - A foo_bar lookup.

New Modules
-----------

- test - This is a TEST module
- test - This is a TEST module.
"""
)

Expand Down Expand Up @@ -706,7 +707,7 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
assert changelog["releases"]["2.10.1"]["modules"] == [
{
"name": "test_new2",
"description": "This is ANOTHER test module!!!11",
"description": "This is ANOTHER test module!!!11.",
"namespace": "",
},
{
Expand Down Expand Up @@ -747,8 +748,8 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
New Modules
-----------

- test_new - This is ANOTHER test module
- test_new2 - This is ANOTHER test module!!!11
- test_new - This is ANOTHER test module.
- test_new2 - This is ANOTHER test module!!!11.
- test_new3 - This is yet another test module.

v2.10
Expand All @@ -772,12 +773,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo_bar lookup
- bar - A foo_bar lookup.

New Modules
-----------

- test - This is a TEST module
- test - This is a TEST module.
"""
)

Expand Down Expand Up @@ -899,6 +900,7 @@ def test_changelog_release_ansible_plugin_cache( # pylint: disable=redefined-ou
notesdir: fragments
prelude_section_name: release_summary
new_plugins_after_name: removed_features
add_plugin_period: false
sections:
- ['major_changes', 'Major Changes']
- ['minor_changes', 'Minor Changes']
Expand Down
23 changes: 12 additions & 11 deletions tests/functional/test_changelog_basic_ansible_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
notesdir: fragments
prelude_section_name: release_summary
new_plugins_after_name: removed_features
add_plugin_period: true
sections:
- ['major_changes', 'Major Changes']
- ['minor_changes', 'Minor Changes']
Expand Down Expand Up @@ -291,12 +292,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo bar lookup
- bar - A foo bar lookup.

New Modules
-----------

- test - This is a test module
- test - This is a test module.
"""
)

Expand Down Expand Up @@ -405,12 +406,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo_bar lookup
- bar - A foo_bar lookup.

New Modules
-----------

- test - This is a TEST module
- test - This is a TEST module.
"""
)

Expand Down Expand Up @@ -521,7 +522,7 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
New Modules
-----------

- test_new - This is ANOTHER test module
- test_new - This is ANOTHER test module.

v2.9
====
Expand All @@ -544,12 +545,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo_bar lookup
- bar - A foo_bar lookup.

New Modules
-----------

- test - This is a TEST module
- test - This is a TEST module.
"""
)

Expand Down Expand Up @@ -683,8 +684,8 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
New Modules
-----------

- test_new - This is ANOTHER test module
- test_new2 - This is ANOTHER test module!!!11
- test_new - This is ANOTHER test module.
- test_new2 - This is ANOTHER test module!!!11.
- test_new3 - This is yet another test module.

v2.9
Expand All @@ -708,12 +709,12 @@ def test_changelog_release_ansible_simple( # pylint: disable=redefined-outer-na
Lookup
~~~~~~

- bar - A foo_bar lookup
- bar - A foo_bar lookup.

New Modules
-----------

- test - This is a TEST module
- test - This is a TEST module.
"""
)

Expand Down
Loading