Пример #1
0
def main() -> None:
    parser = get_cli_parser()
    args = parser.parse_args()
    if args.version:
        print(version)
        return

    get_logger(verbose=args.debug)
    session = Session(region_name=DUMMY_REGION)
    args.output_path.mkdir(exist_ok=True)
    # available_services = session.get_available_services()

    if not args.skip_services:
        for service_name in args.service_names:
            service_output_path = (
                args.output_path
                / f"{service_name.module_name}_package"
                / service_name.module_name
            )
            service_output_path.parent.mkdir(exist_ok=True)
            service_output_path.mkdir(exist_ok=True)
            write_submodule(
                session, service_name=service_name, output_path=service_output_path,
            )
            write_submodule_assets(
                service_output_path=service_output_path, service_name=service_name,
            )
            if args.format:
                format_path(service_output_path)

    if not args.skip_master:
        master_output_path = args.output_path / f"{MODULE_NAME}_package" / MODULE_NAME
        master_output_path.parent.mkdir(exist_ok=True)
        master_output_path.mkdir(exist_ok=True)
        write_master_module(
            output_path=master_output_path, service_names=args.service_names,
        )
        for service_name in args.service_names:
            if not service_name.is_with_docs():
                continue

            service_output_path = (
                args.output_path
                / f"{service_name.module_name}_package"
                / service_name.module_name
            )
            write_master_module_service_stub(
                master_output_path, service_name, service_output_path,
            )

        if args.format:
            format_path(master_output_path.parent)
Пример #2
0
    def test_get_logger(self, logging_mock: MagicMock) -> None:
        logger_mock = MagicMock()
        logging_mock.getLogger.return_value = logger_mock
        logger_mock.handlers = []
        result = get_logger(logging_mock.DEBUG)
        assert result == logger_mock
        logging_mock.StreamHandler.assert_called_with()
        logger_mock.setLevel.assert_called_with(logging_mock.DEBUG)

        logging_mock.reset_mock()
        HandlerMock = MagicMock()
        logger_mock.handlers = [HandlerMock]
        result = get_logger()
        logging_mock.StreamHandler.assert_not_called()
        logger_mock.setLevel.assert_not_called()
Пример #3
0
def parse_method(parent_name: str, name: str, method: FunctionType,
                 service_name: ServiceName) -> Method:
    """
    Parse method to a structure.

    Arguments:
        parent_name -- Parent class name.
        method -- Inspect method.

    Returns:
        Method structure.
    """
    logger = get_logger()
    docstring = textwrap.dedent(inspect.getdoc(method) or "")
    method_name = f"{parent_name}.{name}"

    logger.debug(f"Slow parsing of {method_name}: {len(docstring)} chars")
    prefix = f"{get_class_prefix(parent_name)}{get_class_prefix(name)}"
    arg_spec_parser = ArgSpecParser(prefix, service_name)

    arguments = get_method_arguments_stub(service_name, parent_name, name)
    if arguments is None:
        arguments = arg_spec_parser.get_arguments(parent_name, name, method)
        docstring_parser = DocstringParser(service_name, parent_name, name,
                                           arguments)
        arguments = docstring_parser.get_arguments(docstring)

    return_type = arg_spec_parser.get_return_type(parent_name, name)
    if return_type is None:
        return_type = DocstringParser(service_name, parent_name, name,
                                      []).get_return_type(docstring)

    return Method(name=name, arguments=arguments, return_type=return_type)
Пример #4
0
def process_master(
    session: Session,
    output_path: Path,
    service_names: List[ServiceName],
    generate_setup: bool,
) -> MasterPackage:
    """
    Parse and write master package `mypy_boto3`.

    Arguments:
        session -- boto3 session.
        output_path -- Package output path.
        service_names -- List of known service names.
        generate_setup -- Generate ready-to-install or to-use package.

    Return:
        Parsed MasterPackage.
    """
    logger = get_logger()
    logger.debug("Parsing master")
    master_package = parse_master_package(session, service_names)
    logger.debug(f"Writing master to {NicePath(output_path)}")

    write_master_package(master_package,
                         output_path=output_path,
                         generate_setup=generate_setup)
    return master_package
Пример #5
0
def generate_docs(args: Namespace, service_names: List[ServiceName],
                  session: Session) -> None:
    """
    Generate service and master docs.

    Arguments:
        args -- Config namespace
        service_names -- Enabled service names
        session -- Botocore session
    """
    logger = get_logger()
    if not args.skip_services:
        total_str = f"{len(service_names)}"
        for index, service_name in enumerate(service_names):
            current_str = f"{{:0{len(total_str)}}}".format(index + 1)
            logger.info(
                f"[{current_str}/{total_str}] Generating {service_name.module_name} module"
            )
            process_service_docs(
                session=session,
                output_path=args.output_path,
                service_name=service_name,
            )

    if not args.skip_master:
        logger.info(f"Generating {BOTO3_STUBS_NAME} module")
        process_boto3_stubs_docs(
            session,
            args.output_path,
            service_names,
        )
Пример #6
0
def main() -> None:
    """
    Main entrypoint for builder.
    """
    parser = get_cli_parser()
    args = parser.parse_args()
    logger = get_logger(verbose=args.debug, panic=args.panic)
    session = Session(region_name=DUMMY_REGION)
    args.output_path.mkdir(exist_ok=True)
    service_names: List[ServiceName] = []
    master_service_names = []
    available_services = session.get_available_services()

    for available_service in available_services:
        try:
            service_name = ServiceNameCatalog.find(available_service)
            master_service_names.append(service_name)
        except ValueError:
            logger.info(f"Service {available_service} is not supported, skipping.")

    for service_name in args.service_names:
        if service_name.name not in available_services:
            logger.warning(f"Service {service_name.name} is not available, skipping.")
            continue

        service_name.boto3_version = boto3_version
        service_names.append(service_name)

    build_version = args.build_version or boto3_version
    JinjaManager.update_globals(
        master_pypi_name=PYPI_NAME,
        master_module_name=MODULE_NAME,
        boto3_stubs_name=BOTO3_STUBS_NAME,
        boto3_version=boto3_version,
        build_version=build_version,
        builder_version=version,
    )

    logger.info(f"Bulding version {build_version}")

    if not args.skip_services:
        for index, service_name in enumerate(service_names):
            logger.info(
                f"[{index + 1}/{len(service_names)}] Generating {service_name.module_name} module"
            )
            output_path = args.output_path / f"{service_name.module_name}_package"
            process_service(
                session=session, output_path=output_path, service_name=service_name
            )

    if not args.skip_master:
        logger.info(f"Generating {MODULE_NAME} module")
        output_path = args.output_path / "master_package"
        process_master(session, output_path, master_service_names)

        logger.info(f"Generating {BOTO3_STUBS_NAME} module")
        output_path = args.output_path / "boto3_stubs_package"
        process_boto3_stubs(output_path, master_service_names)

    logger.info("Completed")
Пример #7
0
def process_boto3_stubs_docs(
    session: Session,
    output_path: Path,
    service_names: Iterable[ServiceName],
) -> Boto3StubsPackage:
    """
    Parse and write master package docs.

    Arguments:
        session -- boto3 session
        output_path -- Package output path
        service_names -- List of known service names

    Return:
        Parsed Boto3StubsPackage.
    """
    logger = get_logger()
    package_data = Boto3StubsPackageData
    logger.debug(f"Parsing {package_data.PYPI_NAME}")
    boto3_stubs_package = parse_boto3_stubs_package(session, service_names,
                                                    package_data)
    logger.debug(
        f"Writing {package_data.PYPI_NAME} to {NicePath(output_path)}")

    package_writer = PackageWriter(output_path=output_path)
    package_writer.write_docs(
        boto3_stubs_package,
        templates_path=TEMPLATES_PATH / "boto3_stubs_docs",
    )

    return boto3_stubs_package
Пример #8
0
    def __init__(self, service_name: ServiceName, prefix: str,
                 value: Dict[str, Any]) -> None:
        self.service_name = service_name
        self.logger = get_logger()
        self.prefix = prefix
        self.raw: Dict[str, Any] = value
        self.dict_items: Optional[List[Dict[str,
                                            Any]]] = value.get("dict_items")
        if value.get("empty_dict"):
            self.dict_items = []
        self.set_items: Optional[List[Any]] = value.get("set_items")
        self.list_items: Optional[List[Any]] = value.get("list_items")
        if value.get("empty_list"):
            self.list_items = []
        self.func_call: Optional[Dict[str, Any]] = value.get("func_call")
        self.union_items: List[Any] = []
        if value.get("union_first_item"):
            self.union_items.append(value["union_first_item"])
            self.union_items.extend(value["union_rest_items"])
        self.literal_items: List[Any] = []
        if value.get("literal_first_item"):
            self.literal_items.append(value["literal_first_item"])
            self.literal_items.extend(value["literal_rest_items"])

        self.value: Optional[str] = value.get("value")
Пример #9
0
def process_master(
    session: Session,
    output_path: Path,
    service_names: Iterable[ServiceName],
    generate_setup: bool,
    version: str,
) -> MasterPackage:
    """
    Parse and write master package `mypy_boto3`.

    Arguments:
        session -- boto3 session
        output_path -- Package output path
        service_names -- List of known service names
        generate_setup -- Generate ready-to-install or to-use package
        version -- Package version

    Return:
        Parsed MasterPackage.
    """
    logger = get_logger()
    logger.debug("Parsing master")
    master_package = parse_master_package(session, service_names)
    master_package.version = version
    logger.debug(f"Writing master to {NicePath(output_path)}")

    package_writer = PackageWriter(output_path=output_path,
                                   generate_setup=generate_setup)
    package_writer.write_package(
        master_package,
        templates_path=TEMPLATES_PATH / "master",
    )

    return master_package
Пример #10
0
    def generate_docs(self) -> None:
        """
        Generate service and master docs.
        """
        logger = get_logger()
        total_str = f"{len(self.service_names)}"

        logger.info(f"Generating {Boto3StubsPackageData.NAME} module docs")
        process_boto3_stubs_docs(
            self.session,
            self.output_path,
            self.service_names,
        )

        for index, service_name in enumerate(self.service_names):
            current_str = f"{{:0{len(total_str)}}}".format(index + 1)
            package_name = Boto3StubsPackageData.get_service_package_name(
                service_name)
            logger.info(
                f"[{current_str}/{total_str}] Generating {package_name} module docs"
            )
            process_service_docs(
                session=self.session,
                output_path=self.output_path,
                service_name=service_name,
                service_names=self.available_service_names,
            )
Пример #11
0
def process_botocore_stubs(
    output_path: Path,
    generate_setup: bool,
    version: str,
) -> None:
    """
    Parse and write stubs package `botocore_stubs`.

    Arguments:
        output_path -- Package output path
        generate_setup -- Generate ready-to-install or to-use package
        version -- Package version
    """
    logger = get_logger()
    logger.debug(f"Writing botocore stubs to {NicePath(output_path)}")

    botocore_stubs_package = BotocoreStubsPackage()
    botocore_stubs_package.version = version
    package_writer = PackageWriter(output_path=output_path,
                                   generate_setup=generate_setup)
    package_writer.write_package(
        botocore_stubs_package,
        templates_path=TEMPLATES_PATH / "botocore-stubs",
        static_files_path=BOTOCORE_STUBS_STATIC_PATH,
    )
Пример #12
0
    def __init__(self, session: Session, service_name: ServiceName):
        loader = session._loader  # pylint: disable=protected-access
        botocore_session: BotocoreSession = session._session  # pylint: disable=protected-access
        service_data = botocore_session.get_service_data(service_name.boto3_name)
        self.service_name = service_name
        self.service_model = ServiceModel(service_data, service_name.boto3_name)
        self._typed_dict_map: Dict[str, TypeTypedDict] = {}
        self._waiters_shape: Shape = {}
        try:
            self._waiters_shape = loader.load_service_model(
                service_name.boto3_name, "waiters-2"
            )
        except UnknownServiceError:
            pass
        self._paginators_shape: Shape = {}
        try:
            self._paginators_shape = loader.load_service_model(
                service_name.boto3_name, "paginators-1"
            )
        except UnknownServiceError:
            pass
        self._resources_shape: Shape = {}
        try:
            self._resources_shape = loader.load_service_model(
                service_name.boto3_name, "resources-1"
            )
        except UnknownServiceError:
            pass

        self.logger = get_logger()
Пример #13
0
def process_aiobotocore_stubs_docs(
    session: Session,
    output_path: Path,
    service_names: Iterable[ServiceName],
) -> AioBotocoreStubsPackage:
    """
    Parse and write master package docs.

    Arguments:
        session -- boto3 session
        output_path -- Package output path
        service_names -- List of known service names

    Return:
        Parsed AioBotocoreStubsPackage.
    """
    logger = get_logger()
    aiobotocore_stubs_package = parse_aiobotocore_stubs_package(
        session, service_names, TypesAioBotocorePackageData)

    logger.debug(
        f"Writing {aiobotocore_stubs_package.pypi_name} to {NicePath(output_path)}"
    )

    package_writer = PackageWriter(output_path=output_path)
    package_writer.write_docs(
        aiobotocore_stubs_package,
        templates_path=TEMPLATES_PATH / "aiobotocore_stubs_docs",
    )

    return aiobotocore_stubs_package
Пример #14
0
def process_boto3_stubs(
    session: Session,
    output_path: Path,
    service_names: List[ServiceName],
    generate_setup: bool,
) -> Boto3StubsPackage:
    """
    Parse and write stubs package `boto3_stubs`.

    Arguments:
        session -- boto3 session.
        output_path -- Package output path.
        service_names -- List of known service names.
        generate_setup -- Generate ready-to-install or to-use package.

    Return:
        Parsed Boto3StubsPackage.
    """
    logger = get_logger()
    logger.debug("Parsing boto3 stubs")
    boto3_stubs_package = parse_boto3_stubs_package(
        session=session, service_names=service_names)
    logger.debug(f"Writing boto3 stubs to {NicePath(output_path)}")

    write_boto3_stubs_package(boto3_stubs_package,
                              output_path,
                              generate_setup=generate_setup)
    return boto3_stubs_package
Пример #15
0
def process_service(
    session: Session,
    service_name: ServiceName,
    output_path: Path,
    generate_setup: bool,
) -> ServicePackage:
    """
    Parse and write service package `mypy_boto3_*`.

    Arguments:
        session -- boto3 session.
        service_name -- Target service name.
        output_path -- Package output path.
        generate_setup -- Generate ready-to-install or to-use package.

    Return:
        Parsed ServicePackage.
    """
    logger = get_logger()
    logger.debug(f"Parsing {service_name.boto3_name}")
    service_module = parse_service_package(session, service_name)
    for typed_dict in service_module.typed_dicts:
        typed_dict.replace_self_references()
    logger.debug(
        f"Writing {service_name.boto3_name} to {NicePath(output_path)}")

    write_service_package(service_module,
                          output_path=output_path,
                          generate_setup=generate_setup)
    return service_module
Пример #16
0
    def test_get_logger(self, logging_mock: MagicMock,
                        logger_mock: MagicMock) -> None:
        logger_mock.handlers = []
        result = get_logger(verbose=True)
        assert result == logger_mock
        logging_mock.StreamHandler.assert_called_with()
        logger_mock.set_level.assert_called_with(logging_mock.DEBUG)

        logging_mock.reset_mock()
        HandlerMock = MagicMock()
        logger_mock.handlers = [HandlerMock]
        result = get_logger()
        logging_mock.StreamHandler.assert_not_called()
        logger_mock.setLevel.assert_not_called()

        result = get_logger(verbose=True, panic=True)
        result.panic = True
def write_service_docs(package: ServicePackage, output_path: Path) -> None:
    """
    Create service docs files.

    Arguments:
        package -- Service package.
        output_path -- Path to output folder.
    """
    logger = get_logger()
    docs_path = output_path / f"{package.service_name.module_name}"
    docs_path.mkdir(exist_ok=True)
    templates_path = Path("service_docs")
    file_paths = [
        (docs_path / "README.md", templates_path / "README.md.jinja2"),
        (docs_path / "client.md", templates_path / "client.md.jinja2"),
    ]

    if package.literals:
        file_paths.append(
            (docs_path / "literals.md", templates_path / "literals.md.jinja2"))

    if package.typed_dicts:
        file_paths.append((docs_path / "type_defs.md",
                           templates_path / "type_defs.md.jinja2"))

    if package.waiters:
        file_paths.append(
            (docs_path / "waiters.md", templates_path / "waiters.md.jinja2"))

    if package.paginators:
        file_paths.append((docs_path / "paginators.md",
                           templates_path / "paginators.md.jinja2"))

    if package.service_resource:
        file_paths.append((docs_path / "service_resource.md",
                           templates_path / "service_resource.md.jinja2"))

    for file_path, template_path in file_paths:
        content = render_jinja2_template(
            template_path,
            package=package,
            service_name=package.service_name,
        )
        content = insert_md_toc(content)
        content = format_md(content)
        if not file_path.exists() or file_path.read_text() != content:
            file_path.write_text(content)
            logger.debug(f"Updated {NicePath(file_path)}")

    valid_paths = dict(file_paths).keys()
    for unknown_path in NicePath(docs_path).walk(valid_paths):
        unknown_path.unlink()
        logger.debug(f"Deleted {NicePath(unknown_path)}")
Пример #18
0
 def __init__(
         self,
         data: type[BasePackageData],
         service_names: Iterable[ServiceName] = tuple(),
 ) -> None:
     self.data = data
     self.name = data.NAME
     self.pypi_name = data.PYPI_NAME
     self.library_name = data.LIBRARY_NAME
     self.library_version = data.get_library_version()
     self.version = "0.0.0"
     self.service_names: list[ServiceName] = list(service_names)
     self.logger = get_logger()
Пример #19
0
 def __init__(
     self,
     service_name: ServiceName,
     class_name: str,
     method_name: str,
     arguments: List[Argument],
 ) -> None:
     self.prefix = f"{get_class_prefix(class_name)}{get_class_prefix(method_name)}"
     self.service_name = service_name
     self.class_name = class_name
     self.method_name = method_name
     self.logger = get_logger()
     self.arguments_map: Dict[str, Argument] = {a.name: a for a in arguments if not a.prefix}
Пример #20
0
def process_botocore_stubs(
    output_path: Path,
    generate_setup: bool,
) -> None:
    """
    Parse and write stubs package `botocore_stubs`.

    Arguments:
        output_path -- Package output path.
        generate_setup -- Generate ready-to-install or to-use package.
    """
    logger = get_logger()
    logger.debug(f"Writing botocore stubs to {NicePath(output_path)}")

    write_botocore_stubs_package(output_path, generate_setup=generate_setup)
Пример #21
0
def process_aiobotocore_service(
    session: Session,
    service_name: ServiceName,
    output_path: Path,
    generate_setup: bool,
    service_names: Iterable[ServiceName],
    version: str,
) -> ServicePackage:
    """
    Parse and write service package `types_aiobotocore_*`.

    Arguments:
        session -- boto3 session
        service_name -- Target service name
        output_path -- Package output path
        generate_setup -- Generate ready-to-install or to-use package
        service_names -- List of known service names
        version -- Package version

    Return:
        Parsed ServicePackage.
    """
    logger = get_logger()
    logger.debug(f"Parsing {service_name.boto3_name}")
    service_package = parse_service_package(session, service_name,
                                            TypesAioBotocorePackageData)
    service_package.version = version
    service_package.extend_literals(service_names)

    postprocessor = ServicePackagePostprocessor(service_package)
    postprocessor.generate_docstrings()
    postprocessor.make_async()
    postprocessor.add_contextmanager_methods()

    for typed_dict in service_package.typed_dicts:
        typed_dict.replace_self_references()
    logger.debug(
        f"Writing {service_name.boto3_name} to {NicePath(output_path)}")

    package_writer = PackageWriter(output_path=output_path,
                                   generate_setup=generate_setup)
    package_writer.write_service_package(
        service_package,
        templates_path=TEMPLATES_PATH / "aiobotocore_service",
    )
    return service_package
Пример #22
0
def process_boto3_stubs_lite(
    session: Session,
    output_path: Path,
    service_names: Iterable[ServiceName],
    generate_setup: bool,
    version: str,
) -> Boto3StubsPackage:
    """
    Parse and write stubs package `boto3-stubs-lite`.

    Arguments:
        session -- boto3 session
        output_path -- Package output path
        service_names -- List of known service names
        generate_setup -- Generate ready-to-install or to-use package
        version -- Package version

    Return:
        Parsed Boto3StubsPackage.
    """
    logger = get_logger()
    package_data = Boto3StubsLitePackageData
    logger.debug(f"Parsing {package_data.PYPI_NAME}")
    boto3_stubs_package = parse_boto3_stubs_package(
        session=session,
        service_names=service_names,
        package_data=package_data,
    )
    boto3_stubs_package.version = version
    logger.debug(
        f"Writing {package_data.PYPI_NAME} to {NicePath(output_path)}")

    package_writer = PackageWriter(output_path=output_path,
                                   generate_setup=generate_setup)
    package_writer.write_package(
        boto3_stubs_package,
        templates_path=TEMPLATES_PATH / "boto3-stubs",
        static_files_path=BOTO3_STUBS_STATIC_PATH,
        exclude_template_names=[
            "session.pyi.jinja2",
            "__init__.pyi.jinja2",
        ],
    )

    return boto3_stubs_package
Пример #23
0
def parse_method(
    parent_name: str, name: str, method: MethodType, service_name: ServiceName
) -> Method:
    """
    Parse method to a structure.

    Arguments:
        parent_name -- Parent class name.
        method -- Inspect method.

    Returns:
        Method structure.
    """
    logger = get_logger()
    docstring = textwrap.dedent(inspect.getdoc(method) or "")
    method_name = f"{parent_name}.{name}"

    logger.debug(f"Slow parsing of {method_name}: {len(docstring)} chars")
    prefix = f"{get_class_prefix(parent_name)}{get_class_prefix(name)}"
    arg_spec_parser = ArgSpecParser(prefix, service_name)

    arguments = get_method_arguments_stub(service_name, parent_name, name)
    if arguments is None:
        arguments = arg_spec_parser.get_arguments(parent_name, name, method)
        docstring_parser = DocstringParser(service_name, parent_name, name, arguments)
        arguments = docstring_parser.get_arguments(docstring)

    # do not add kwonly flag to resource generators
    if len(arguments) > 1 and not name[0].isupper():
        arguments.insert(1, Argument.kwflag())

    return_type = arg_spec_parser.get_return_type(parent_name, name)
    if return_type is None:
        return_type = DocstringParser(service_name, parent_name, name, []).get_return_type(
            docstring
        )

    result = Method(name=name, arguments=arguments, return_type=return_type)
    result.request_type_annotation = result.get_request_type_annotation(
        f"{parent_name}{get_class_prefix(name)}RequestTypeDef"
    )
    return result
Пример #24
0
    def __init__(self, session: Session, service_name: ServiceName):
        loader = session._loader
        botocore_session: BotocoreSession = session._session
        service_data = botocore_session.get_service_data(
            service_name.boto3_name)
        self.service_name = service_name
        self.service_model = ServiceModel(service_data,
                                          service_name.boto3_name)
        self._typed_dict_map: dict[str, TypeTypedDict] = {}
        self._waiters_shape: Mapping[str, Any] | None = None
        try:
            self._waiters_shape = loader.load_service_model(
                service_name.boto3_name, "waiters-2")
        except UnknownServiceError:
            pass
        self._paginators_shape: Mapping[str, Any] | None = None
        try:
            self._paginators_shape = loader.load_service_model(
                service_name.boto3_name, "paginators-1")
        except UnknownServiceError:
            pass
        self._resources_shape: Mapping[str, Any] | None = None
        try:
            self._resources_shape = loader.load_service_model(
                service_name.boto3_name, "resources-1")
        except UnknownServiceError:
            pass

        self.logger = get_logger()
        self.response_metadata_typed_dict = TypeTypedDict(
            "ResponseMetadataTypeDef",
            [
                TypedDictAttribute("RequestId", Type.str, True),
                TypedDictAttribute("HostId", Type.str, True),
                TypedDictAttribute("HTTPStatusCode", Type.int, True),
                TypedDictAttribute("HTTPHeaders", Type.DictStrStr, True),
                TypedDictAttribute("RetryAttempts", Type.int, True),
            ],
        )
        self.proxy_operation_model = OperationModel({}, self.service_model)
Пример #25
0
def get_selected_service_names(
    selected: Iterable[str],
    available: Iterable[ServiceName],
) -> list[ServiceName]:
    """
    Get a list of selected service names.

    Supports `updated` to select only services updated in currect `boto3` release.
    Supports `all` to select all available service names.

    Arguments:
        selected -- Selected service names as strings.
        available -- All ServiceNames available in current boto3 release.

    Returns:
        A list of selected ServiceNames.
    """
    logger = get_logger()
    available_map = {i.name: i for i in available}
    result: list[ServiceName] = []
    selected_service_names = list(selected)
    botocore_version = get_botocore_version()
    if ServiceName.ALL in selected_service_names:
        return list(available)
    if ServiceName.UPDATED in selected_service_names:
        selected_service_names.remove(ServiceName.UPDATED)
        for updated_service_name in BotocoreChangelog(
        ).get_updated_service_names(botocore_version):
            if updated_service_name in available_map:
                selected_service_names.append(updated_service_name)

    for service_name_str in selected_service_names:
        if service_name_str not in available_map:
            logger.info(
                f"Service {service_name_str} is not provided by botocore, skipping"
            )
            continue
        result.append(available_map[service_name_str])

    return result
Пример #26
0
 def __init__(
     self,
     service_names: Sequence[ServiceName],
     available_service_names: Iterable[ServiceName],
     master_service_names: Sequence[ServiceName],
     session: Session,
     output_path: Path,
     generate_setup: bool,
     skip_published: bool,
     disable_smart_version: bool,
     version: str,
 ):
     self.session = session
     self.service_names = service_names
     self.available_service_names = available_service_names
     self.master_service_names = master_service_names
     self.output_path = output_path
     self.logger = get_logger()
     self.generate_setup = generate_setup
     self.skip_published = skip_published
     self.disable_smart_version = disable_smart_version
     self.version = version or get_boto3_version()
Пример #27
0
def process_service_docs(
    session: Session,
    service_name: ServiceName,
    output_path: Path,
    service_names: Iterable[ServiceName],
) -> ServicePackage:
    """
    Parse and write service package docs.

    Arguments:
        session -- boto3 session
        service_name -- Target service name
        output_path -- Package output path
        service_names -- List of known service names

    Return:
        Parsed ServicePackage.
    """
    logger = get_logger()
    logger.debug(f"Parsing {service_name.boto3_name}")
    service_package = parse_service_package(session, service_name,
                                            Boto3StubsPackageData)
    service_package.extend_literals(service_names)

    postprocessor = ServicePackagePostprocessor(service_package)
    postprocessor.generate_docstrings()

    for typed_dict in service_package.typed_dicts:
        typed_dict.replace_self_references()

    logger.debug(
        f"Writing {service_name.boto3_name} to {NicePath(output_path)}")

    package_writer = PackageWriter(output_path=output_path)
    package_writer.write_service_docs(
        service_package,
        templates_path=TEMPLATES_PATH / "boto3_service_docs",
    )
    return service_package
Пример #28
0
    def __init__(self, session: Session, service_name: ServiceName):
        loader = session._loader  # pylint: disable=protected-access
        botocore_session: BotocoreSession = session._session  # pylint: disable=protected-access
        service_data = botocore_session.get_service_data(
            service_name.boto3_name)
        self.service_name = service_name
        self.service_model = ServiceModel(service_data,
                                          service_name.boto3_name)
        self._typed_dict_map: Dict[str, TypeTypedDict] = {}
        self._waiters_shape: Optional[Shape] = None
        try:
            self._waiters_shape = loader.load_service_model(
                service_name.boto3_name, "waiters-2")
        except UnknownServiceError:
            pass
        self._paginators_shape: Optional[Shape] = None
        try:
            self._paginators_shape = loader.load_service_model(
                service_name.boto3_name, "paginators-1")
        except UnknownServiceError:
            pass
        self._resources_shape: Optional[Shape] = None
        try:
            self._resources_shape = loader.load_service_model(
                service_name.boto3_name, "resources-1")
        except UnknownServiceError:
            pass

        self.logger = get_logger()
        self.response_metadata_typed_dict = TypeTypedDict(
            "ResponseMetadata",
            [
                TypedDictAttribute("RequestId", Type.str, True),
                TypedDictAttribute("HostId", Type.str, True),
                TypedDictAttribute("HTTPStatusCode", Type.int, True),
                TypedDictAttribute("HTTPHeaders", Type.DictStrAny, True),
                TypedDictAttribute("RetryAttempts", Type.int, True),
            ],
        )
Пример #29
0
def process_boto3_stubs_docs(
    session: Session,
    output_path: Path,
    service_names: List[ServiceName],
) -> Boto3StubsPackage:
    """
    Parse and write master package docs.

    Arguments:
        session -- boto3 session.
        output_path -- Package output path.
        service_names -- List of known service names.

    Return:
        Parsed Boto3StubsPackage.
    """
    logger = get_logger()
    logger.debug("Parsing boto3 stubs")
    boto3_stubs_package = parse_boto3_stubs_package(session, service_names)
    logger.debug(f"Writing boto3 stubs to {NicePath(output_path)}")

    write_boto3_stubs_docs(boto3_stubs_package, output_path=output_path)
    return boto3_stubs_package
Пример #30
0
def process_aiobotocore_stubs_lite(
    session: Session,
    output_path: Path,
    service_names: Iterable[ServiceName],
    generate_setup: bool,
    version: str,
) -> AioBotocoreStubsPackage:
    """
    Parse and write stubs package `aiobotocore-stubs-lite`.

    Arguments:
        session -- boto3 session
        output_path -- Package output path
        service_names -- List of known service names
        generate_setup -- Generate ready-to-install or to-use package
        version -- Package version

    Return:
        Parsed AioBotocoreStubsPackage.
    """
    logger = get_logger()
    aiobotocore_stubs_package = parse_aiobotocore_stubs_package(
        session, service_names, TypesAioBotocoreLitePackageData)
    aiobotocore_stubs_package.version = version
    logger.debug(
        f"Writing {aiobotocore_stubs_package.pypi_name} to {NicePath(output_path)}"
    )

    package_writer = PackageWriter(output_path=output_path,
                                   generate_setup=generate_setup)
    package_writer.write_package(
        aiobotocore_stubs_package,
        templates_path=TEMPLATES_PATH / "aiobotocore-stubs",
        static_files_path=AIOBOTOCORE_STUBS_STATIC_PATH,
        exclude_template_names=["session.pyi.jinja2"],
    )
    return aiobotocore_stubs_package