예제 #1
0
    def _document_collection(self, section, collection):
        methods = get_instance_public_methods(
            getattr(self._resource, collection.name))
        document_collection_object(section, collection)
        batch_actions = {}
        for batch_action in collection.batch_actions:
            batch_actions[batch_action.name] = batch_action

        for method in sorted(methods):
            method_section = section.add_new_section(method)
            if method in batch_actions:
                document_batch_action(
                    section=method_section,
                    resource_name=self._resource_name,
                    event_emitter=self._resource.meta.client.meta.events,
                    batch_action_model=batch_actions[method],
                    collection_model=collection,
                    service_model=self._resource.meta.client.meta.
                    service_model,
                )
            else:
                document_collection_method(
                    section=method_section,
                    resource_name=self._resource_name,
                    action_name=method,
                    event_emitter=self._resource.meta.client.meta.events,
                    collection_model=collection,
                    service_model=self._resource.meta.client.meta.
                    service_model,
                )
예제 #2
0
 def test_get_instance_methods(self):
     instance = self.MySampleClass()
     instance_methods = get_instance_public_methods(instance)
     self.assertEqual(len(instance_methods), 1)
     self.assertIn('public_method', instance_methods)
     self.assertEqual(
         instance.public_method, instance_methods['public_method'])
예제 #3
0
def parse_service_resource(
        session: Session,
        service_name: ServiceName) -> Optional[ServiceResource]:
    try:
        service_resource = session.resource(service_name.boto3_name)
    except boto3.exceptions.ResourceNotExistsError:
        return None

    methods = list(parse_methods(
        get_instance_public_methods(service_resource)))

    attributes: List[Attribute] = []
    for attribute in parse_attributes(service_resource):
        attributes.append(attribute)
    for attribute in parse_identifiers(service_resource):
        attributes.append(attribute)

    collections = list(parse_collections(service_resource))

    sub_resources = []
    for sub_resource in retrieve_sub_resources(session, service_name,
                                               service_resource):
        sub_resources.append(parse_resource(sub_resource))

    return ServiceResource(
        service_name=service_name,
        docstring=clean_doc(getdoc(service_resource)),
        methods=methods,
        attributes=attributes,
        collections=collections,
        sub_resources=sub_resources,
    )
예제 #4
0
def parse_client(session: Session, service_name: ServiceName) -> Client:
    client = session.client(service_name.boto3_name)
    return Client(
        service_name=service_name,
        docstring=clean_doc(getdoc(client)),
        methods=list(parse_methods(get_instance_public_methods(client))),
    )
예제 #5
0
 def test_get_instance_methods(self):
     instance = self.MySampleClass()
     instance_methods = get_instance_public_methods(instance)
     self.assertEqual(len(instance_methods), 1)
     self.assertIn('public_method', instance_methods)
     self.assertEqual(instance.public_method,
                      instance_methods['public_method'])
예제 #6
0
    def _document_collection(self, section, collection):
        methods = get_instance_public_methods(
            getattr(self._resource, collection.name))
        document_collection_object(section, collection)
        batch_actions = {}
        for batch_action in collection.batch_actions:
            batch_actions[batch_action.name] = batch_action

        for method in sorted(methods):
            method_section = section.add_new_section(method)
            if method in batch_actions:
                document_batch_action(
                    section=method_section,
                    resource_name=self._resource_name,
                    event_emitter=self._resource.meta.client.meta.events,
                    batch_action_model=batch_actions[method],
                    collection_model=collection,
                    service_model=self._resource.meta.client.meta.service_model
                )
            else:
                document_collection_method(
                    section=method_section,
                    resource_name=self._resource_name,
                    action_name=method,
                    event_emitter=self._resource.meta.client.meta.events,
                    collection_model=collection,
                    service_model=self._resource.meta.client.meta.service_model
                )
예제 #7
0
def parse_paginators(
    client: BaseClient, service_paginator_model: PaginatorModel
) -> Generator[Paginator, None, None]:
    for paginator_name in sorted(service_paginator_model._paginator_config):
        paginator = client.get_paginator(xform_name(paginator_name))
        yield Paginator(
            paginator._model.name,
            list(parse_methods(get_instance_public_methods(paginator))))
예제 #8
0
def parse_waiters(client: BaseClient) -> Generator[Waiter, None, None]:
    for waiter_name in client.waiter_names:
        waiter = client.get_waiter(waiter_name)
        yield Waiter(
            name=waiter.name,
            docstring=clean_doc(getdoc(waiter)),
            methods=list(parse_methods(get_instance_public_methods(waiter))),
        )
예제 #9
0
def parse_client_types(session: Session) -> Set[str]:
    types = set()
    for name in session.get_available_services():
        print(f'Parsing: {name}')
        client = session.client(name)
        types = types.union(
            types.union(parse_method_types(
                get_instance_public_methods(client))))
    return types
예제 #10
0
def parse_collections(
        resource: Boto3ServiceResource) -> Generator[Collection, None, None]:
    for collection in resource.meta.resource_model.collections:
        yield Collection(
            collection.name,
            list(
                parse_methods(
                    get_instance_public_methods(
                        getattr(resource, collection.name)))))
예제 #11
0
    def document_client(self, section):
        """Documents a client and its methods

        :param section: The section to write to.
        """
        self._add_title(section)
        self._add_class_signature(section)
        client_methods = get_instance_public_methods(self._client)
        self._add_client_intro(section, client_methods)
        self._add_client_methods(section, client_methods)
예제 #12
0
    def document_client(self, section):
        """Documents a client and its methods

        :param section: The section to write to.
        """
        self._add_title(section)
        self._add_class_signature(section)
        client_methods = get_instance_public_methods(self._client)
        self._add_client_intro(section, client_methods)
        self._add_client_methods(section, client_methods)
예제 #13
0
def parse_clients(session: Session,
                  config: Config) -> Generator[Client, None, None]:
    for name in [
            service for service in session.get_available_services()
            if service in config.services
    ]:
        print(f'Parsing: {name}')
        client = session.client(name)
        yield Client(name,
                     list(parse_methods(get_instance_public_methods(client))))
예제 #14
0
    def _document_collection(self, section, collection):
        section.style.start_sphinx_py_attr(collection.name)
        methods = get_instance_public_methods(getattr(self._resource, collection.name))
        batch_actions = {}
        for batch_action in collection.batch_actions:
            batch_actions[batch_action.name] = batch_action

        for method in sorted(methods):
            method_section = section.add_new_section(method)
            if method in batch_actions:
                self._document_batch_action(method_section, batch_actions[method], collection)
            else:
                self._document_custom_action(method_section, method, collection)
예제 #15
0
def parse_service_resource_types(session: Session) -> Set[str]:
    types = set()
    for resource_name in session.get_available_resources():
        service_resource = session.resource(resource_name)
        types = types.union(
            parse_method_types(get_resource_public_actions(service_resource)))
        types = types.union(parse_attribute_types(service_resource))
        for collection in service_resource.meta.resource_model.collections:
            types = types.union(
                parse_method_types(
                    get_instance_public_methods(
                        getattr(service_resource, collection.name))))
        for resource in retrieve_sub_resources(session, service_resource):
            types = types.union(
                parse_method_types(
                    get_resource_public_actions(resource.__class__)))
            types = types.union(parse_attribute_types(resource))
            for collection in resource.meta.resource_model.collections:
                types = types.union(
                    parse_method_types(
                        get_instance_public_methods(
                            getattr(resource, collection.name))))
    return types
예제 #16
0
def parse_collections(
    resource: Boto3ServiceResource, ) -> Generator[Collection, None, None]:
    for collection in resource.meta.resource_model.collections:
        yield Collection(
            name=collection.name,
            docstring=clean_doc(getdoc(collection)),
            type=InternalImport(
                name=collection.name,
                service_name=ServiceName(resource.meta.service_name),
            ),
            methods=list(
                parse_methods(
                    get_instance_public_methods(
                        getattr(resource, collection.name)))),
        )
예제 #17
0
def parse_paginators(
    client: BaseClient, service_paginator_model: PaginatorModel
) -> Generator[Paginator, None, None]:
    paginator_config = (
        service_paginator_model._paginator_config  # pylint: disable=protected-access
    )
    for paginator_name in sorted(paginator_config):
        paginator = client.get_paginator(xform_name(paginator_name))
        paginator_model = paginator._model  # pylint: disable=protected-access
        yield Paginator(
            name=paginator_model.name,
            docstring=clean_doc(getdoc(paginator)),
            methods=list(parse_methods(
                get_instance_public_methods(paginator))),
        )
예제 #18
0
    def _document_collection(self, section, collection):
        section.style.start_sphinx_py_attr(collection.name)
        methods = get_instance_public_methods(
            getattr(self._resource, collection.name))
        batch_actions = {}
        for batch_action in collection.batch_actions:
            batch_actions[batch_action.name] = batch_action

        for method in sorted(methods):
            method_section = section.add_new_section(method)
            if method in batch_actions:
                self._document_batch_action(method_section,
                                            batch_actions[method], collection)
            else:
                self._document_custom_action(method_section, method,
                                             collection)
예제 #19
0
def parse_service_resources(
        session: Session,
        config: Config) -> Generator[ServiceResource, None, None]:
    for resource_name in [
            service for service in session.get_available_resources()
            if service in config.services
    ]:
        service_resource = session.resource(resource_name)
        print(f'Parsing: {resource_name}')
        yield ServiceResource(
            resource_name,
            list(parse_methods(get_instance_public_methods(service_resource))),
            list(parse_attributes(service_resource)) +
            list(parse_identifiers(service_resource)),
            list(parse_collections(service_resource)), [
                parse_resource(resource) for resource in
                retrieve_sub_resources(session, service_resource)
            ])
 def _get_client_methods(self):
     client_methods = get_instance_public_methods(self._client)
     return self._filter_client_methods(client_methods)
예제 #21
0
def parse_waiters(client: BaseClient) -> Generator[Waiter, None, None]:
    for waiter_name in client.waiter_names:
        waiter = client.get_waiter(waiter_name)
        yield Waiter(waiter.name,
                     list(parse_methods(get_instance_public_methods(waiter))))