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

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

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

    return master_package
Beispiel #3
0
 def test_write_master_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_master_package(
         package_mock, output_path_mock) == [output_path_mock] * 10)
     render_jinja2_template_mock.assert_called_with(
         Path("master/master/submodules.py.jinja2"),
         package=package_mock,
     )
     blackify_mock.assert_called_with(render_jinja2_template_mock(),
                                      output_path_mock)
Beispiel #4
0
    def test_write_master_package(
        self,
        render_jinja2_template_mock: MagicMock,
        blackify_mock: MagicMock,
        sort_imports_mock: MagicMock,
    ) -> None:
        package_mock = MagicMock()
        package_mock.name = "package"
        package_mock.service_name.module_name = "module"

        blackify_mock.return_value = "blackify"
        sort_imports_mock.return_value = "sort_imports"
        render_jinja2_template_mock.return_value = "render_jinja2_template_mock"

        with tempfile.TemporaryDirectory() as output_dir:
            output_path = Path(output_dir)
            write_master_package(package_mock, output_path, True)
            render_jinja2_template_mock.assert_called_with(
                Path("master/master/submodules.py.jinja2"),
                package=package_mock,
            )
            assert len(blackify_mock.mock_calls) == 12
            assert len(sort_imports_mock.mock_calls) == 12
            blackify_mock.reset_mock()
            sort_imports_mock.reset_mock()

        with tempfile.TemporaryDirectory() as output_dir:
            output_path = Path(output_dir)
            (output_path / "package").mkdir(parents=True, exist_ok=True)
            (output_path / "package" / "unknown.txt").touch()
            write_master_package(package_mock, output_path, False)
            render_jinja2_template_mock.assert_called_with(
                Path("master/master/submodules.py.jinja2"),
                package=package_mock,
            )
            assert len(blackify_mock.mock_calls) == 11
            assert len(sort_imports_mock.mock_calls) == 11
Beispiel #5
0
 def test_write_master_package(
     self,
     render_jinja2_template_mock: MagicMock,
     blackify_mock: MagicMock,
     sort_imports_mock: MagicMock,
 ) -> None:
     package_mock = MagicMock()
     output_path_mock = MagicMock()
     output_path_mock.exists.return_value = False
     output_path_mock.__truediv__.return_value = output_path_mock
     assert write_master_package(package_mock, output_path_mock,
                                 True) == [output_path_mock] * 14
     render_jinja2_template_mock.assert_called_with(
         Path("master/master/submodules.py.jinja2"),
         package=package_mock,
     )
     blackify_mock.assert_called_with(render_jinja2_template_mock(),
                                      output_path_mock)
     sort_imports_mock.assert_called()
Beispiel #6
0
def process_master(session: Session, output_path: Path,
                   service_names: List[ServiceName]) -> MasterPackage:
    """
    Parse and write master package `mypy_boto3`.

    Arguments:
        session -- boto3 session.
        output_path -- Package output path.

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

    modified_paths = write_master_package(master_package, output_path)
    for modified_path in modified_paths:
        logger.debug(f"Updated {NicePath(modified_path)}")

    return master_package