Example #1
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
Example #2
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 -- Whether to generate install or installed package.

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

    modified_paths = write_service_package(service_module,
                                           output_path=output_path,
                                           generate_setup=generate_setup)
    for modified_path in modified_paths:
        logger.debug(f"Updated {NicePath(modified_path)}")

    return service_module
Example #3
0
 def test_write_service_package(self,
                                render_jinja2_template_mock: MagicMock,
                                blackify_mock: MagicMock) -> None:
     package_mock = MagicMock()
     output_path_mock = MagicMock()
     output_path_mock.__truediv__.return_value = output_path_mock
     assert (write_service_package(
         package_mock, output_path_mock) == [output_path_mock] * 11)
     render_jinja2_template_mock.assert_called_with(
         Path("service/service/type_defs.py.jinja2"),
         package=package_mock,
         service_name=package_mock.service_name,
     )
     blackify_mock.assert_called_with(render_jinja2_template_mock(),
                                      output_path_mock)