-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implemented Nested Docs. #3597
Merged
Merged
Implemented Nested Docs. #3597
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d6d4594
Implemented Nested Docs.
jonathan343 4b65a5d
Forgot to run linter on 1 file
jonathan343 4ff9398
Forgot to run linter on 1 file: Part 2
jonathan343 ce76e5d
Manually included js/custom.js since Sphinx < 1.8 doesnt support cust…
jonathan343 1704cca
Added a new Resource section; Improved redirecting from old links.
jonathan343 2d9319d
Forgot linter :(
jonathan343 793b7aa
Ok I found the issue with my linter. Last one
jonathan343 6661128
Updated Resources notes & redirects; Updated copyright year.
jonathan343 dfa742f
ran pre-commit
jonathan343 3e6546b
Ran js file throught linter. Added copyright notice
jonathan343 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
import os | ||
|
||
from botocore import xform_name | ||
from botocore.docs.bcdoc.restdoc import DocumentStructure | ||
from botocore.docs.utils import get_official_service_name | ||
|
||
from boto3.docs.action import ActionDocumenter | ||
|
@@ -32,22 +35,25 @@ | |
|
||
|
||
class ResourceDocumenter(BaseDocumenter): | ||
def __init__(self, resource, botocore_session): | ||
def __init__(self, resource, botocore_session, root_docs_path): | ||
super().__init__(resource) | ||
self._botocore_session = botocore_session | ||
self._root_docs_path = root_docs_path | ||
self._resource_sub_path = self._resource_name.lower() | ||
if self._resource_name == self._service_name: | ||
self._resource_sub_path = 'service-resource' | ||
|
||
def document_resource(self, section): | ||
self._add_title(section) | ||
self._add_resource_note(section) | ||
self._add_intro(section) | ||
overview_section = section.add_new_section('member-overview') | ||
self._add_identifiers(section) | ||
self._add_attributes(section) | ||
self._add_references(section) | ||
self._add_actions(section) | ||
self._add_sub_resources(section) | ||
self._add_collections(section) | ||
self._add_waiters(section) | ||
self._add_overview_of_members(overview_section) | ||
|
||
def _add_title(self, section): | ||
section.style.h2(self._resource_name) | ||
|
@@ -60,23 +66,27 @@ def _add_intro(self, section): | |
|
||
# Write out the class signature. | ||
class_args = get_identifier_args_for_signature(identifier_names) | ||
section.style.start_sphinx_py_class( | ||
start_class = section.add_new_section('start_class') | ||
start_class.style.start_sphinx_py_class( | ||
class_name=f'{self.class_name}({class_args})' | ||
) | ||
|
||
# Add as short description about the resource | ||
description_section = section.add_new_section('description') | ||
description_section = start_class.add_new_section('description') | ||
self._add_description(description_section) | ||
|
||
# Add an example of how to instantiate the resource | ||
example_section = section.add_new_section('example') | ||
example_section = start_class.add_new_section('example') | ||
self._add_example(example_section, identifier_names) | ||
|
||
# Add the description for the parameters to instantiate the | ||
# resource. | ||
param_section = section.add_new_section('params') | ||
param_section = start_class.add_new_section('params') | ||
self._add_params_description(param_section, identifier_names) | ||
|
||
end_class = section.add_new_section('end_class') | ||
end_class.style.end_sphinx_py_class() | ||
|
||
def _add_description(self, section): | ||
official_service_name = get_official_service_name(self._service_model) | ||
section.write( | ||
|
@@ -118,23 +128,15 @@ def _add_params_description(self, section, identifier_names): | |
section.write(f':param {identifier_name}: {description}') | ||
section.style.new_line() | ||
|
||
def _add_overview_of_members(self, section): | ||
for resource_member_type in self.member_map: | ||
section.style.new_line() | ||
section.write( | ||
f'These are the resource\'s available {resource_member_type}:' | ||
) | ||
section.style.new_line() | ||
for member in self.member_map[resource_member_type]: | ||
if resource_member_type in ( | ||
'attributes', | ||
'collections', | ||
'identifiers', | ||
'references', | ||
): | ||
section.style.li(f':py:attr:`{member}`') | ||
else: | ||
section.style.li(f':py:meth:`{member}()`') | ||
def _add_overview_of_member_type(self, section, resource_member_type): | ||
section.style.new_line() | ||
section.write( | ||
f'These are the resource\'s available {resource_member_type}:' | ||
) | ||
section.style.new_line() | ||
section.style.toctree() | ||
for member in self.member_map[resource_member_type]: | ||
section.style.tocitem(f'{member}') | ||
|
||
def _add_identifiers(self, section): | ||
identifiers = self._resource.meta.resource_model.identifiers | ||
|
@@ -152,13 +154,29 @@ def _add_identifiers(self, section): | |
intro_link='identifiers_attributes_intro', | ||
) | ||
for identifier in identifiers: | ||
identifier_section = section.add_new_section(identifier.name) | ||
member_list.append(identifier.name) | ||
# Create a new DocumentStructure for each identifier and add contents. | ||
identifier_doc = DocumentStructure(identifier.name, target='html') | ||
identifier_doc.add_title_section(identifier.name) | ||
identifier_section = identifier_doc.add_new_section( | ||
identifier.name | ||
) | ||
document_identifier( | ||
section=identifier_section, | ||
resource_name=self._resource_name, | ||
identifier_model=identifier, | ||
) | ||
# Write identifiers in individual/nested files. | ||
# Path: <root>/reference/services/<service>/<resource_name>/<identifier_name>.rst | ||
identifiers_dir_path = os.path.join( | ||
self._root_docs_path, | ||
f'{self._service_name}', | ||
f'{self._resource_sub_path}', | ||
) | ||
identifier_doc.write_to_file(identifiers_dir_path, identifier.name) | ||
|
||
if identifiers: | ||
self._add_overview_of_member_type(section, 'identifiers') | ||
|
||
def _add_attributes(self, section): | ||
service_model = self._resource.meta.client.meta.service_model | ||
|
@@ -187,8 +205,11 @@ def _add_attributes(self, section): | |
self.member_map['attributes'] = attribute_list | ||
for attr_name in sorted(attributes): | ||
_, attr_shape = attributes[attr_name] | ||
attribute_section = section.add_new_section(attr_name) | ||
attribute_list.append(attr_name) | ||
# 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) | ||
document_attribute( | ||
section=attribute_section, | ||
service_name=self._service_name, | ||
|
@@ -197,6 +218,16 @@ def _add_attributes(self, section): | |
event_emitter=self._resource.meta.client.meta.events, | ||
attr_model=attr_shape, | ||
) | ||
# Write attributes in individual/nested files. | ||
# Path: <root>/reference/services/<service>/<resource_name>/<attribute_name>.rst | ||
attributes_dir_path = os.path.join( | ||
self._root_docs_path, | ||
f'{self._service_name}', | ||
f'{self._resource_sub_path}', | ||
) | ||
attribute_doc.write_to_file(attributes_dir_path, attr_name) | ||
if attributes: | ||
self._add_overview_of_member_type(section, 'attributes') | ||
|
||
def _add_references(self, section): | ||
section = section.add_new_section('references') | ||
|
@@ -213,36 +244,57 @@ def _add_references(self, section): | |
intro_link='references_intro', | ||
) | ||
self.member_map['references'] = reference_list | ||
self._add_overview_of_member_type(section, 'references') | ||
for reference in references: | ||
reference_section = section.add_new_section(reference.name) | ||
reference_list.append(reference.name) | ||
# 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) | ||
document_reference( | ||
section=reference_section, reference_model=reference | ||
) | ||
# Write references in individual/nested files. | ||
# Path: <root>/reference/services/<service>/<resource_name>/<reference_name>.rst | ||
references_dir_path = os.path.join( | ||
self._root_docs_path, | ||
f'{self._service_name}', | ||
f'{self._resource_sub_path}', | ||
) | ||
reference_doc.write_to_file(references_dir_path, reference.name) | ||
if references: | ||
self._add_overview_of_member_type(section, 'references') | ||
|
||
def _add_actions(self, section): | ||
section = section.add_new_section('actions') | ||
actions = self._resource.meta.resource_model.actions | ||
if actions: | ||
documenter = ActionDocumenter(self._resource) | ||
documenter = ActionDocumenter(self._resource, self._root_docs_path) | ||
documenter.member_map = self.member_map | ||
documenter.document_actions(section) | ||
self._add_overview_of_member_type(section, 'actions') | ||
|
||
def _add_sub_resources(self, section): | ||
section = section.add_new_section('sub-resources') | ||
sub_resources = self._resource.meta.resource_model.subresources | ||
if sub_resources: | ||
documenter = SubResourceDocumenter(self._resource) | ||
documenter = SubResourceDocumenter( | ||
self._resource, self._root_docs_path | ||
) | ||
documenter.member_map = self.member_map | ||
documenter.document_sub_resources(section) | ||
self._add_overview_of_member_type(section, 'sub-resources') | ||
|
||
def _add_collections(self, section): | ||
section = section.add_new_section('collections') | ||
collections = self._resource.meta.resource_model.collections | ||
if collections: | ||
documenter = CollectionDocumenter(self._resource) | ||
documenter = CollectionDocumenter( | ||
self._resource, self._root_docs_path | ||
) | ||
documenter.member_map = self.member_map | ||
documenter.document_collections(section) | ||
self._add_overview_of_member_type(section, 'collections') | ||
|
||
def _add_waiters(self, section): | ||
section = section.add_new_section('waiters') | ||
|
@@ -252,10 +304,21 @@ def _add_waiters(self, section): | |
self._service_name | ||
) | ||
documenter = WaiterResourceDocumenter( | ||
self._resource, service_waiter_model | ||
self._resource, service_waiter_model, self._root_docs_path | ||
) | ||
documenter.member_map = self.member_map | ||
documenter.document_resource_waiters(section) | ||
self._add_overview_of_member_type(section, 'waiters') | ||
|
||
def _add_resource_note(self, section): | ||
section = section.add_new_section('feature-freeze') | ||
section.style.start_note() | ||
section.write( | ||
"Before using anything on this page, please refer to the resources " | ||
":doc:`user guide <../../../../guide/resources>` for the most recent " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit; can we do this as an absolute path relative than relative to the resource page? |
||
"guidance on using resources." | ||
) | ||
section.style.end_note() | ||
|
||
|
||
class ServiceResourceDocumenter(ResourceDocumenter): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit; we can fix this in a follow up, but I think this is supposed to be "resources" plural rather than possessive?