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")
def generate_stubs(args: Namespace, service_names: List[ServiceName], session: Session) -> None: """ Generate service and master stubs. 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" ) service_name.boto3_version = boto3_version process_service( session=session, output_path=args.output_path, service_name=service_name, generate_setup=not args.installed, ) service_name.boto3_version = ServiceName.LATEST if not args.skip_master: if not args.installed: logger.info(f"Generating {MODULE_NAME} module") process_master( session, args.output_path, service_names, generate_setup=not args.installed, ) logger.info(f"Generating {BOTO3_STUBS_NAME} module") process_boto3_stubs( session, args.output_path, service_names, generate_setup=not args.installed, ) logger.info(f"Generating {BOTOCORE_STUBS_NAME} module") process_botocore_stubs( args.output_path, generate_setup=not args.installed, )
def test_process_boto3_stubs( self, _get_logger_mock: MagicMock, write_boto3_stubs_package_mock: MagicMock) -> None: write_boto3_stubs_package_mock.return_value = [Path("modified_path")] result = process_boto3_stubs(Path("my_path"), ["service_name"]) self.assertIsInstance(result, Boto3StubsPackage) write_boto3_stubs_package_mock.assert_called_with( result, Path("my_path"))
def _generate_boto3_stubs(self) -> None: package_data = Boto3StubsPackageData version = self._get_package_version(package_data.PYPI_NAME, self.version) if not version: self.logger.info( f"Skipping {package_data.PYPI_NAME} {self.version}, already on PyPI" ) return self.logger.info(f"Generating {package_data.PYPI_NAME} {version}") process_boto3_stubs( self.session, self.output_path, self.master_service_names, generate_setup=self.generate_setup, version=version, )
def test_process_boto3_stubs( self, _get_logger_mock: MagicMock, write_boto3_stubs_package_mock: MagicMock, parse_boto3_stubs_package_mock: MagicMock, ) -> None: write_boto3_stubs_package_mock.return_value = [Path("modified_path")] result = process_boto3_stubs("session", Path("my_path"), ["service_name"], True) write_boto3_stubs_package_mock.assert_called_with( result, Path("my_path"), generate_setup=True, ) parse_boto3_stubs_package_mock.assert_called_with( session="session", service_names=["service_name"]) assert result == parse_boto3_stubs_package_mock()
def test_process_boto3_stubs( self, write_boto3_stubs_package_mock: MagicMock, parse_boto3_stubs_package_mock: MagicMock, ) -> None: session_mock = MagicMock() service_name_mock = MagicMock() write_boto3_stubs_package_mock.return_value = [Path("modified_path")] result = process_boto3_stubs(session_mock, Path("my_path"), [service_name_mock], True) write_boto3_stubs_package_mock.assert_called_with( result, Path("my_path"), generate_setup=True, ) parse_boto3_stubs_package_mock.assert_called_with( session=session_mock, service_names=[service_name_mock] ) assert result == parse_boto3_stubs_package_mock()
def test_process_boto3_stubs( self, PackageWriterMock: MagicMock, parse_boto3_stubs_package_mock: MagicMock, ) -> None: session_mock = MagicMock() service_name_mock = MagicMock() PackageWriterMock().write_package.return_value = [ Path("modified_path") ] result = process_boto3_stubs( session_mock, Path("my_path"), [service_name_mock], True, version="1.2.3", ) PackageWriterMock().write_package.assert_called() parse_boto3_stubs_package_mock.assert_called_with( session_mock, [service_name_mock], Boto3StubsPackageData) assert result == parse_boto3_stubs_package_mock()
def main() -> None: """ Main entrypoint for builder. """ args = parse_args(sys.argv[1:]) 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: List[ServiceName] = [] available_services = session.get_available_services() for available_service in available_services: try: service_name = ServiceNameCatalog.find(available_service) except ValueError: logger.info(f"Service {available_service} is not fully supported.") continue service_name.boto3_version = boto3_version master_service_names.append(service_name) if args.service_names: for service_name in args.service_names: if service_name.name not in available_services: logger.info(f"Service {service_name.name} is not provided by boto3, skipping.") continue service_name.boto3_version = boto3_version service_names.append(service_name) else: service_names = master_service_names build_version = args.build_version or boto3_version version = (Path(__file__).parent / "version.txt").read_text().strip() 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: 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( session=session, output_path=args.output_path, service_name=service_name, generate_setup=not args.installed, ) if not args.skip_master: logger.info(f"Generating {MODULE_NAME} module") process_master( session, args.output_path, master_service_names, generate_setup=not args.installed, ) logger.info(f"Generating {BOTO3_STUBS_NAME} module") process_boto3_stubs( session, args.output_path, master_service_names, generate_setup=not args.installed, ) logger.info("Completed")