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

Updated signatures to support sphinx domain #3615

Merged
merged 3 commits into from
Mar 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions boto3/docs/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def document_actions(self, section):
# Create a new DocumentStructure for each action and add contents.
action_doc = DocumentStructure(action_name, target='html')
action_doc.add_title_section(action_name)
action_section = action_doc.add_new_section(action_name)
action_section = action_doc.add_new_section(
action_name,
context={'qualifier': f'{self.class_name}.'},
)
if action_name in ['load', 'reload'] and self._resource_model.load:
document_load_reload_action(
section=action_section,
Expand Down Expand Up @@ -124,9 +127,12 @@ def document_action(
example_prefix = '{} = {}.{}'.format(
example_return_value, example_resource_name, action_model.name
)
full_action_name = (
f"{section.context.get('qualifier', '')}{action_model.name}"
)
document_model_driven_resource_method(
section=section,
method_name=action_model.name,
method_name=full_action_name,
operation_model=operation_model,
event_emitter=event_emitter,
method_description=operation_model.documentation,
Expand Down Expand Up @@ -176,9 +182,10 @@ def document_load_reload_action(
if service_model.service_name == resource_name:
example_resource_name = resource_name
example_prefix = f'{example_resource_name}.{action_name}'
full_action_name = f"{section.context.get('qualifier', '')}{action_name}"
document_model_driven_method(
section=section,
method_name=action_name,
method_name=full_action_name,
operation_model=OperationModel({}, service_model),
event_emitter=event_emitter,
method_description=description,
Expand Down
18 changes: 14 additions & 4 deletions boto3/docs/attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def document_attribute(
include_signature=True,
):
if include_signature:
section.style.start_sphinx_py_attr(attr_name)
full_attr_name = f"{section.context.get('qualifier', '')}{attr_name}"
section.style.start_sphinx_py_attr(full_attr_name)
# Note that an attribute may have one, may have many, or may have no
# operations that back the resource's shape. So we just set the
# operation_name to the resource name if we ever to hook in and modify
Expand All @@ -42,10 +43,16 @@ def document_attribute(


def document_identifier(
section, resource_name, identifier_model, include_signature=True
section,
resource_name,
identifier_model,
include_signature=True,
):
if include_signature:
section.style.start_sphinx_py_attr(identifier_model.name)
full_identifier_name = (
f"{section.context.get('qualifier', '')}{identifier_model.name}"
)
section.style.start_sphinx_py_attr(full_identifier_name)
description = get_identifier_description(
resource_name, identifier_model.name
)
Expand All @@ -54,7 +61,10 @@ def document_identifier(

def document_reference(section, reference_model, include_signature=True):
if include_signature:
section.style.start_sphinx_py_attr(reference_model.name)
full_reference_name = (
f"{section.context.get('qualifier', '')}{reference_model.name}"
)
section.style.start_sphinx_py_attr(full_reference_name)
reference_type = f'(:py:class:`{reference_model.resource.type}`) '
section.write(reference_type)
section.include_doc_string(
Expand Down
7 changes: 7 additions & 0 deletions boto3/docs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ def __init__(self, resource, root_docs_path):
self._resource_sub_path = self._resource_name.lower()
if self._resource_name == self._service_name:
self._resource_sub_path = 'service-resource'

@property
def class_name(self):
resource_class_name = self._resource_name
if self._resource_name == self._service_name:
resource_class_name = 'ServiceResource'
return f'{self._service_docs_name}.{resource_class_name}'
12 changes: 9 additions & 3 deletions boto3/docs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def document_collections(self, section):
collection_doc = DocumentStructure(collection.name, target='html')
collection_doc.add_title_section(collection.name)
collection_section = collection_doc.add_new_section(
collection.name
collection.name,
context={'qualifier': f'{self.class_name}.'},
)
self._document_collection(collection_section, collection)

Expand Down Expand Up @@ -90,7 +91,9 @@ def _document_collection(self, section, collection):


def document_collection_object(
section, collection_model, include_signature=True
section,
collection_model,
include_signature=True,
):
"""Documents a collection resource object

Expand All @@ -102,7 +105,10 @@ def document_collection_object(
It is useful for generating docstrings.
"""
if include_signature:
section.style.start_sphinx_py_attr(collection_model.name)
full_collection_name = (
f"{section.context.get('qualifier', '')}{collection_model.name}"
)
section.style.start_sphinx_py_attr(full_collection_name)
section.include_doc_string(
f'A collection of {collection_model.resource.type} resources.'
)
Expand Down
16 changes: 12 additions & 4 deletions boto3/docs/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def _add_identifiers(self, section):
identifier_doc = DocumentStructure(identifier.name, target='html')
identifier_doc.add_title_section(identifier.name)
identifier_section = identifier_doc.add_new_section(
identifier.name
identifier.name,
context={'qualifier': f'{self.class_name}.'},
)
document_identifier(
section=identifier_section,
Expand Down Expand Up @@ -209,7 +210,10 @@ def _add_attributes(self, section):
# Create a new DocumentStructure for each attribute and add contents.
attribute_doc = DocumentStructure(attr_name, target='html')
attribute_doc.add_title_section(attr_name)
attribute_section = attribute_doc.add_new_section(attr_name)
attribute_section = attribute_doc.add_new_section(
attr_name,
context={'qualifier': f'{self.class_name}.'},
)
document_attribute(
section=attribute_section,
service_name=self._service_name,
Expand Down Expand Up @@ -250,9 +254,13 @@ def _add_references(self, section):
# Create a new DocumentStructure for each reference and add contents.
reference_doc = DocumentStructure(reference.name, target='html')
reference_doc.add_title_section(reference.name)
reference_section = reference_doc.add_new_section(reference.name)
reference_section = reference_doc.add_new_section(
reference.name,
context={'qualifier': f'{self.class_name}.'},
)
document_reference(
section=reference_section, reference_model=reference
section=reference_section,
reference_model=reference,
)
# Write references in individual/nested files.
# Path: <root>/reference/services/<service>/<resource_name>/<reference_name>.rst
Expand Down
8 changes: 6 additions & 2 deletions boto3/docs/subresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def document_sub_resources(self, section):
)
sub_resource_doc.add_title_section(sub_resource.name)
sub_resource_section = sub_resource_doc.add_new_section(
sub_resource.name
sub_resource.name,
context={'qualifier': f'{self.class_name}.'},
)
document_sub_resource(
section=sub_resource_section,
Expand Down Expand Up @@ -99,8 +100,11 @@ def document_sub_resource(

if include_signature:
signature_args = get_identifier_args_for_signature(identifiers_needed)
full_sub_resource_name = (
f"{section.context.get('qualifier', '')}{sub_resource_model.name}"
)
section.style.start_sphinx_py_method(
sub_resource_model.name, signature_args
full_sub_resource_name, signature_args
)

method_intro_section = section.add_new_section('method-intro')
Expand Down
10 changes: 8 additions & 2 deletions boto3/docs/waiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def document_resource_waiters(self, section):
# Create a new DocumentStructure for each waiter and add contents.
waiter_doc = DocumentStructure(waiter.name, target='html')
waiter_doc.add_title_section(waiter.name)
waiter_section = waiter_doc.add_new_section(waiter.name)
waiter_section = waiter_doc.add_new_section(
waiter.name,
context={'qualifier': f'{self.class_name}.'},
)
document_resource_waiter(
section=waiter_section,
resource_name=self._resource_name,
Expand Down Expand Up @@ -101,9 +104,12 @@ def document_resource_waiter(
example_prefix = '{}.{}'.format(
xform_name(resource_name), resource_waiter_model.name
)
full_waiter_name = (
f"{section.context.get('qualifier', '')}{resource_waiter_model.name}"
)
document_model_driven_method(
section=section,
method_name=resource_waiter_model.name,
method_name=full_waiter_name,
operation_model=operation_model,
event_emitter=event_emitter,
example_prefix=example_prefix,
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/docs/test_dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_batch_writer_is_documented(self):
self.assert_contains_lines_in_order(
[
'************\nbatch_writer\n************',
'.. py:method:: batch_writer(overwrite_by_pkeys=None)',
'.. py:method:: DynamoDB.Table.batch_writer(overwrite_by_pkeys=None)',
],
self.get_nested_file_contents('dynamodb', 'table', 'batch_writer'),
)
Expand All @@ -61,7 +61,7 @@ def test_document_interface_is_documented(self):
'********',
'put_item',
'********',
'.. py:method:: put_item(**kwargs)',
'.. py:method:: DynamoDB.Table.put_item(**kwargs)',
# Make sure the request syntax is as expected.
'response = table.put_item(',
'Item={',
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/docs/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_delete_tags_method_is_documented(self):
self.assert_contains_lines_in_order(
[
'delete_tags',
'.. py:method:: delete_tags(**kwargs)',
'.. py:method:: EC2.Instance.delete_tags(**kwargs)',
'response = instance.delete_tags(',
'DryRun=True|False,',
'Tags=[',
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/docs/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ def test_file_transfer_methods_are_documented(self):
self.assert_contains_lines_in_order(
[
'download_file',
'.. py:method:: download_file(',
'.. py:method:: S3.Client.download_file(',
],
self.get_nested_file_contents('s3', 'client', 'download_file'),
)
self.assert_contains_lines_in_order(
[
'upload_file',
'.. py:method:: upload_file(',
'.. py:method:: S3.Client.upload_file(',
],
self.get_nested_file_contents('s3', 'client', 'upload_file'),
)
2 changes: 1 addition & 1 deletion tests/functional/docs/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _assert_has_client_documentation(generated_docs, service_name, client):
_assert_contains_lines_in_order(
[
f'{method_name}',
f'.. py:method:: {method_name}(',
f'.. py:method:: {client.__class__.__name__}.Client.{method_name}(',
],
get_nested_file_contents(service_name, 'client', method_name),
)
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/docs/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_document_service_resource_actions(self):
self.assert_contains_lines_in_order(
[
'sample_operation',
'.. py:method:: sample_operation(**kwargs)',
'.. py:method:: MyService.ServiceResource.sample_operation(**kwargs)',
' **Request Syntax**',
' ::',
' response = myservice.sample_operation(',
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_document_nonservice_resource_actions(self):
self.assert_contains_lines_in_order(
[
'load',
'.. py:method:: load()',
'.. py:method:: MyService.Sample.load()',
(
' Calls :py:meth:`MyService.Client.sample_operation` to update '
'the attributes of the Sample resource'
Expand All @@ -94,7 +94,7 @@ def test_document_nonservice_resource_actions(self):
self.assert_contains_lines_in_order(
[
'operate',
'.. py:method:: operate(**kwargs)',
'.. py:method:: MyService.Sample.operate(**kwargs)',
' **Request Syntax** ',
' ::',
' response = sample.operate(',
Expand All @@ -121,7 +121,7 @@ def test_document_nonservice_resource_actions(self):
self.assert_contains_lines_in_order(
[
'reload',
'.. py:method:: reload()',
'.. py:method:: MyService.Sample.reload()',
(
' Calls :py:meth:`MyService.Client.sample_operation` to update '
'the attributes of the Sample resource'
Expand All @@ -136,7 +136,7 @@ def test_document_nonservice_resource_actions(self):
self.assert_contains_lines_in_order(
[
'get_available_subresources',
'.. py:method:: get_available_subresources()',
'.. py:method:: MyService.Sample.get_available_subresources()',
'Returns a list of all the available sub-resources for this',
':returns: A list containing the name of each sub-resource for this',
':rtype: list of str',
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/docs/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_document_client(self):
self.assert_contains_lines_in_order(
[
'can_paginate',
'.. py:method:: can_paginate(operation_name)',
'.. py:method:: MyService.Client.can_paginate(operation_name)',
],
self.get_nested_service_contents(
'myservice', 'client', 'can_paginate'
Expand All @@ -55,7 +55,7 @@ def test_document_client(self):
self.assert_contains_lines_in_order(
[
'get_paginator',
'.. py:method:: get_paginator(operation_name)',
'.. py:method:: MyService.Client.get_paginator(operation_name)',
],
self.get_nested_service_contents(
'myservice', 'client', 'get_paginator'
Expand All @@ -64,7 +64,7 @@ def test_document_client(self):
self.assert_contains_lines_in_order(
[
'get_waiter',
'.. py:method:: get_waiter(waiter_name)',
'.. py:method:: MyService.Client.get_waiter(waiter_name)',
],
self.get_nested_service_contents(
'myservice', 'client', 'get_waiter'
Expand All @@ -73,7 +73,7 @@ def test_document_client(self):
self.assert_contains_lines_in_order(
[
'sample_operation',
'.. py:method:: sample_operation(**kwargs)',
'.. py:method:: MyService.Client.sample_operation(**kwargs)',
' **Request Syntax**',
' ::',
' response = client.sample_operation(',
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/docs/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_document_collections(self):
self.assert_contains_lines_in_order(
[
'samples',
'.. py:attribute:: samples',
'.. py:attribute:: MyService.ServiceResource.samples',
' A collection of Sample resources.'
'A Sample Collection will include all resources by default, '
'and extreme caution should be taken when performing actions '
Expand Down