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

Show ansible-core compatibility in collection index page #49

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
3 changes: 3 additions & 0 deletions changelogs/fragments/49-collection-supported-ansible-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- "Antsibull-docs now depends on `packaging <https://pypi.org/project/packaging/>`__ (https://github.com/ansible-community/antsibull-docs/pull/49)."
- "The collection index pages now contain the supported versions of ansible-core of the collection in case collection's ``meta/runtime.yml`` specifies ``requires_ansible`` (https://github.com/ansible-community/antsibull-docs/issues/48, https://github.com/ansible-community/antsibull-docs/pull/49)."
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ antsibull-core = ">= 1.2.0, < 2.0.0"
asyncio-pool = "*"
docutils = "*"
jinja2 = "*"
packaging = "*"
rstcheck = ">= 3.0.0, < 7.0.0"
sphinx = "*"

Expand Down
10 changes: 9 additions & 1 deletion src/antsibull_docs/data/docsite/plugins_by_collection.rst.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Collection version @{ collection_version }@
:local:
:depth: 1

{% if collection_description or collection_authors or collection_links %}
{% if collection_description or collection_authors or collection_links or requires_ansible %}
Description
-----------

Expand All @@ -43,6 +43,14 @@ Description
{% endfor %}
{% endif %}

{% if requires_ansible %}
**Supported ansible-core versions:**

{% for part in requires_ansible %}
* @{ part | rst_escape }@
{% endfor %}
{% endif %}

{% if collection_links %}
.. raw:: html

Expand Down
7 changes: 6 additions & 1 deletion src/antsibull_docs/docs_parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ def _get_environment(collection_dir: t.Optional[str]) -> t.Dict[str, str]:
class AnsibleCollectionMetadata:
path: str
version: t.Optional[str]
requires_ansible: t.Optional[str]

def __init__(self, path: str, version: t.Optional[str]):
def __init__(self,
path: str,
version: t.Optional[str] = None,
requires_ansible: t.Optional[str] = None):
self.path = path
self.version = version
self.requires_ansible = requires_ansible

def __repr__(self):
return f'AnsibleCollectionMetadata({repr(self.path)}, {repr(self.version)})'
Expand Down
3 changes: 2 additions & 1 deletion src/antsibull_docs/docs_parsing/ansible_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ def get_collection_metadata(venv: t.Union['VenvRunner', 'FakeVenvRunner'],
raw_result = ansible_collection_list_cmd.stdout.decode('utf-8', errors='surrogateescape')
collection_list = parse_ansible_galaxy_collection_list(raw_result, collection_names)
for namespace, name, path, version in collection_list:
collection_metadata[f'{namespace}.{name}'] = AnsibleCollectionMetadata(
collection_name = f'{namespace}.{name}'
collection_metadata[collection_name] = AnsibleCollectionMetadata(
path=path, version=version)

return collection_metadata
Expand Down
16 changes: 14 additions & 2 deletions src/antsibull_docs/docs_parsing/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ def remove_flatmapping_artifacts(plugin_routing: t.Dict[str, t.Dict[str, t.Dict[
plugin_routing_type.pop(plugin_name, None)


def calculate_meta_runtime(collection_name, collection_metadata):
def load_meta_runtime(collection_name: str,
collection_metadata: AnsibleCollectionMetadata) -> t.Mapping[str, t.Any]:
'''
Load meta/runtime.yml for collections, and ansible_builtin_runtime.yml for ansible-core.

Also extracts additional metadata stored in meta/runtime.yml, like requires_ansible,
and stores it in collection_metadata
'''
if collection_name == 'ansible.builtin':
meta_runtime_path = os.path.join(
collection_metadata.path, 'config', 'ansible_builtin_runtime.yml')
Expand All @@ -201,6 +208,11 @@ def calculate_meta_runtime(collection_name, collection_metadata):
else:
meta_runtime = {}

if collection_name != 'ansible.builtin':
requires_ansible = meta_runtime.get('requires_ansible')
if isinstance(requires_ansible, str):
collection_metadata.requires_ansible = requires_ansible

return meta_runtime


Expand All @@ -210,7 +222,7 @@ async def load_collection_routing(collection_name: str,
"""
Load plugin routing for a collection.
"""
meta_runtime = calculate_meta_runtime(collection_name, collection_metadata)
meta_runtime = load_meta_runtime(collection_name, collection_metadata)
plugin_routing_out: t.Dict[str, t.Dict[str, t.Dict[str, t.Any]]] = {}
plugin_routing_in = meta_runtime.get('plugin_routing') or {}
for plugin_type in DOCUMENTABLE_PLUGINS:
Expand Down
42 changes: 42 additions & 0 deletions src/antsibull_docs/write_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import asyncio_pool # type: ignore[import]

from jinja2 import Template
from packaging.specifiers import SpecifierSet

from antsibull_core import app_context
from antsibull_core.logging import log
Expand Down Expand Up @@ -602,6 +603,29 @@ async def write_plugin_type_index(plugin_type: str,
await write_file(dest_filename, index_contents)


def _parse_required_ansible(requires_ansible: str) -> t.List[str]:
result = []
for specifier in reversed(sorted(
SpecifierSet(requires_ansible),
key=lambda specifier: (specifier.operator, specifier.version)
)):
if specifier.operator == '>=':
result.append(f'{specifier.version} or newer')
elif specifier.operator == '>':
result.append(f'newer than {specifier.version}')
elif specifier.operator == '<=':
result.append(f'{specifier.version} or older')
elif specifier.operator == '<':
result.append(f'older than {specifier.version}')
elif specifier.operator == '!=':
result.append(f'version {specifier.version} is specifically not supported')
elif specifier.operator == '==':
result.append(f'version {specifier.version} is specifically supported')
else:
result.append(f'{specifier.operator} {specifier.version}')
return result


async def write_plugin_lists(collection_name: str,
plugin_maps: t.Mapping[str, t.Mapping[str, str]],
template: Template,
Expand All @@ -627,12 +651,28 @@ async def write_plugin_lists(collection_name: str,
:kwarg for_official_docsite: Default False. Set to True to use wording specific for the
official docsite on docs.ansible.com.
"""
flog = mlog.fields(func='write_plugin_lists')
flog.debug('Enter')

requires_ansible = []
if collection_name != 'ansible.builtin' and collection_meta.requires_ansible:
try:
requires_ansible = _parse_required_ansible(collection_meta.requires_ansible)
except Exception as exc: # pylint:disable=broad-except
flog.fields(
collection_name=collection_name,
exception=exc,
).error(
'Cannot parse required_ansible specifier set for {collection_name}',
collection_name=collection_name,
)
index_contents = _render_template(
template,
dest_dir,
collection_name=collection_name,
plugin_maps=plugin_maps,
collection_version=collection_meta.version,
requires_ansible=requires_ansible,
link_data=link_data,
breadcrumbs=breadcrumbs,
extra_docs_sections=extra_docs_data[0],
Expand All @@ -650,6 +690,8 @@ async def write_plugin_lists(collection_name: str,

await write_file(index_file, index_contents)

flog.debug('Leave')

felixfontein marked this conversation as resolved.
Show resolved Hide resolved

async def output_collection_index(collection_to_plugin_info: CollectionInfoT,
collection_namespaces: t.Mapping[str, t.List[str]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ A short description.




.. toctree::
:maxdepth: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Description

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* newer than 2.11.0




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ With multiple paragraphs.

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* 2.11.0 or newer
* older than 2.99.0
* version 2.12.2 is specifically not supported

.. raw:: html

<p class="ansible-links">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ A short description.




.. toctree::
:maxdepth: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Description

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* newer than 2.11.0




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ With multiple paragraphs.

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* 2.11.0 or newer
* older than 2.99.0
* version 2.12.2 is specifically not supported

.. raw:: html

<p class="ansible-links">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ A short description.




.. toctree::
:maxdepth: 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Description

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* newer than 2.11.0




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ With multiple paragraphs.

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* 2.11.0 or newer
* older than 2.99.0
* version 2.12.2 is specifically not supported

.. raw:: html

<p class="ansible-links">
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/baseline-squash-hierarchy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ With multiple paragraphs.

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* 2.11.0 or newer
* older than 2.99.0
* version 2.12.2 is specifically not supported

.. raw:: html

<p class="ansible-links">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ With multiple paragraphs.

* Ansible (https://github.com/ansible)

**Supported ansible-core versions:**

* 2.11.0 or newer
* older than 2.99.0
* version 2.12.2 is specifically not supported

.. raw:: html

<p class="ansible-links">
Expand Down