Skip to content

Commit

Permalink
Move mypy-boto3 to a separate product
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Jan 9, 2025
1 parent 1d6ff84 commit f58bef7
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 122 deletions.
6 changes: 3 additions & 3 deletions mypy_boto3_builder/chat/prompts/base_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from abc import ABC, abstractmethod
from collections.abc import Iterator
from contextlib import contextmanager
from typing import Any, ClassVar, Final, Generic, TypeVar
from typing import Any, ClassVar, Final, Generic, NoReturn, TypeVar
from unittest.mock import patch

from prompt_toolkit import PromptSession
Expand Down Expand Up @@ -82,7 +82,7 @@ def get_prompt_tokens(self) -> list[tuple[str, str]]:
return TextStyle.text.stylize(self._get_prompt_tokens())

@abstractmethod
def _get_prompt_tokens(self) -> Message:
def _get_prompt_tokens(self) -> NoReturn:
raise NotImplementedError("Method is not implemented")

def _is_answered(self) -> bool:
Expand All @@ -100,7 +100,7 @@ def get_question(self) -> Question:
return self._question

@abstractmethod
def _create_question(self) -> Question:
def _create_question(self) -> NoReturn:
raise NotImplementedError("Method is not implemented")

def _patch_answer(self) -> None:
Expand Down
5 changes: 5 additions & 0 deletions mypy_boto3_builder/enums/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class Product(Enum):
boto3_stubs_custom = "boto3-custom"
boto3_stubs_docs = "boto3-docs"

mypy_boto3 = "mypy-boto3"

def __str__(self) -> str:
"""
Get string representation for debugging.
Expand Down Expand Up @@ -86,6 +88,8 @@ def get_library(self) -> ProductLibrary:
| Product.types_aioboto3_custom
):
return ProductLibrary.aioboto3
case Product.mypy_boto3:
return ProductLibrary.mypy_boto3

def get_type(self) -> ProductType:
"""
Expand All @@ -97,6 +101,7 @@ def get_type(self) -> ProductType:
| Product.boto3_stubs
| Product.types_aiobotocore
| Product.types_aioboto3
| Product.mypy_boto3
):
return ProductType.stubs
case (
Expand Down
7 changes: 3 additions & 4 deletions mypy_boto3_builder/enums/product_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ class ProductLibrary(Enum):
boto3_legacy = "boto3-legacy"
aiobotocore = "aiobotocore"
aioboto3 = "aioboto3"
mypy_boto3 = "mypy_boto3"

def get_library_name(self) -> str:
"""
Get library name.
"""
match self:
case ProductLibrary.boto3:
return "boto3"
case ProductLibrary.boto3_legacy:
case ProductLibrary.boto3 | ProductLibrary.boto3_legacy | ProductLibrary.mypy_boto3:
return "boto3"
case ProductLibrary.aiobotocore:
return "aiobotocore"
Expand All @@ -36,7 +35,7 @@ def get_chat_choice(self) -> str:
Get chat choice.
"""
match self:
case ProductLibrary.boto3:
case ProductLibrary.boto3 | ProductLibrary.mypy_boto3:
return "boto3"
case ProductLibrary.boto3_legacy:
return "boto3-stubs"
Expand Down
36 changes: 19 additions & 17 deletions mypy_boto3_builder/generators/aioboto3_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

from pathlib import Path
from typing import NoReturn

from mypy_boto3_builder.constants import (
StaticStubsPath,
Expand All @@ -24,8 +25,8 @@
parse_types_aiobotocore_package,
)
from mypy_boto3_builder.postprocessors.aioboto3 import AioBoto3Postprocessor
from mypy_boto3_builder.structures.package import Package
from mypy_boto3_builder.structures.packages.service_package import ServicePackage
from mypy_boto3_builder.structures.packages.types_aioboto3_package import TypesAioBoto3Package
from mypy_boto3_builder.writers.package_writer import PackageWriter


Expand Down Expand Up @@ -55,16 +56,16 @@ def _get_postprocessor(self, service_package: ServicePackage) -> AioBoto3Postpro
"""
return AioBoto3Postprocessor(service_package, self.main_service_names)

def generate_stubs(self) -> list[Package]:
def generate_stubs(self) -> TypesAioBoto3Package | None:
"""
Generate `types-aioboto3` package.
"""
package_data = TypesAioBoto3PackageData()
try:
version = self._get_package_version(package_data.pypi_name, self.version)
except AlreadyPublishedError:
self.logger.info(f"Skipping {package_data.pypi_name} {self.version}, already on PyPI")
return []
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
package = parse_types_aioboto3_package(
Expand All @@ -79,17 +80,17 @@ def generate_stubs(self) -> list[Package]:
template_path=TemplatePath.types_aioboto3,
static_files_path=self._get_static_files_path(),
)
return [package]
return package

def generate_stubs_lite(self) -> Package | None:
def generate_stubs_lite(self) -> TypesAioBoto3Package | None:
"""
Generate `types-aioboto3-lite` package.
"""
package_data = TypesAioBoto3LitePackageData()
try:
version = self._get_package_version(package_data.pypi_name, self.version)
except AlreadyPublishedError:
self.logger.info(f"Skipping {package_data.pypi_name} {self.version}, already on PyPI")
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
Expand Down Expand Up @@ -137,18 +138,19 @@ def generate_docs(self) -> None:
version=self.version,
)

def generate_service_stubs(self) -> list[ServicePackage]:
def generate_service_stubs(self) -> NoReturn:
"""
Do nothing.
Not implemented.
"""
return []
raise NotImplementedError("Should never be called")

def generate_full_stubs(self) -> None:
def generate_full_stubs(self) -> NoReturn:
"""
Do nothing.
Not implemented.
"""
raise NotImplementedError("Should never be called")

def generate_custom_stubs(self) -> Package:
def generate_custom_stubs(self) -> TypesAioBoto3Package:
"""
Generate `types-aioboto3-custom` package.
"""
Expand Down
32 changes: 16 additions & 16 deletions mypy_boto3_builder/generators/aiobotocore_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
)
from mypy_boto3_builder.parsers.parse_wrapper_package import parse_types_aiobotocore_package
from mypy_boto3_builder.postprocessors.aiobotocore import AioBotocorePostprocessor
from mypy_boto3_builder.structures.package import Package
from mypy_boto3_builder.structures.packages.service_package import ServicePackage
from mypy_boto3_builder.structures.packages.types_aiobotocore_package import TypesAioBotocorePackage


class AioBotocoreGenerator(BaseGenerator):
Expand All @@ -45,16 +45,16 @@ def _get_postprocessor(self, service_package: ServicePackage) -> AioBotocorePost
"""
return AioBotocorePostprocessor(service_package, self.main_service_names)

def generate_stubs(self) -> list[Package]:
def generate_stubs(self) -> TypesAioBotocorePackage | None:
"""
Generate `types-aiobotocore` package.
"""
package_data = TypesAioBotocorePackageData()
try:
version = self._get_package_version(package_data.pypi_name, self.version)
except AlreadyPublishedError:
self.logger.info(f"Skipping {package_data.pypi_name} {self.version}, already on PyPI")
return []
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")

Expand All @@ -70,17 +70,17 @@ def generate_stubs(self) -> list[Package]:
template_path=TemplatePath.types_aiobotocore,
static_files_path=self._get_static_files_path(),
)
return [package]
return package

def generate_stubs_lite(self) -> Package | None:
def generate_stubs_lite(self) -> TypesAioBotocorePackage | None:
"""
Generate `types-aiobotocore-lite` package.
"""
package_data = TypesAioBotocoreLitePackageData()
try:
version = self._get_package_version(package_data.pypi_name, self.version)
except AlreadyPublishedError:
self.logger.info(f"Skipping {package_data.pypi_name} {self.version}, already on PyPI")
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
Expand Down Expand Up @@ -128,15 +128,15 @@ def generate_docs(self) -> None:
version=self.version,
)

def generate_full_stubs(self) -> Package | None:
def generate_full_stubs(self) -> TypesAioBotocorePackage | None:
"""
Generate `types-aiobotocore-full` package.
"""
package_data = TypesAioBotocoreFullPackageData()
try:
version = self._get_package_version(package_data.pypi_name, self.version)
except AlreadyPublishedError:
self.logger.info(f"Skipping {package_data.pypi_name} {self.version}, already on PyPI")
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
Expand Down Expand Up @@ -164,7 +164,7 @@ def generate_full_stubs(self) -> Package | None:
)
return package

def generate_custom_stubs(self) -> Package:
def generate_custom_stubs(self) -> TypesAioBotocorePackage:
"""
Generate `types-aiobotocore-custom` package.
"""
Expand Down
29 changes: 13 additions & 16 deletions mypy_boto3_builder/generators/base_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ def _get_library_version(self) -> str:
"""
return self.service_package_data.get_library_version()

def _get_package_version(self, pypi_name: str, version: str) -> str:
def _get_package_build_version(self, pypi_name: str) -> str:
if self.config.disable_smart_version:
return version
return self.version
pypi_manager = PyPIManager(pypi_name)
if not pypi_manager.has_version(version):
return version
if not pypi_manager.has_version(self.version):
return self.version

if self.config.skip_published:
raise AlreadyPublishedError(f"{pypi_name} {version} is already on PyPI")
raise AlreadyPublishedError(f"{pypi_name} {self.version} is already on PyPI")

return pypi_manager.get_next_version(version)
return pypi_manager.get_next_version(self.version)

@abstractmethod
def generate_stubs(self) -> Sequence[Package]:
def generate_stubs(self) -> Package | None:
"""
Generate main stubs.
"""
Expand All @@ -182,7 +182,6 @@ def generate_custom_stubs(self) -> Package | None:
"""
Generate custom stubs.
"""
raise NotImplementedError("Method should be implemented in child class")

def _generate_full_stubs_services(self, package: Package) -> None:
service_package_writer = PackageWriter(
Expand Down Expand Up @@ -225,7 +224,7 @@ def generate_product(self, product_type: ProductType) -> None:
packages: list[Package | None] = []
match product_type:
case ProductType.stubs:
packages.extend(self.generate_stubs())
packages.append(self.generate_stubs())
case ProductType.stubs_lite:
packages.append(self.generate_stubs_lite())
case ProductType.service_stubs:
Expand Down Expand Up @@ -317,11 +316,9 @@ def generate_service_stubs(self) -> list[ServicePackage]:

pypi_name = self.service_package_data.get_service_pypi_name(service_name)
try:
version = self._get_package_version(pypi_name, self.version)
except AlreadyPublishedError:
self.logger.info(
f"{progress_str} Skipping {pypi_name} {self.version}, already on PyPI"
)
version = self._get_package_build_version(pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"{progress_str} Skipping {pypi_name}: {e}")
continue

self.logger.info(f"{progress_str} Generating {pypi_name} {version}")
Expand All @@ -346,7 +343,7 @@ def cleanup_temporary_files(self) -> None:
self.logger.debug(f"Removing {dir_path}")
shutil.rmtree(dir_path)

def _get_wrapper_package_extras(self, package: Package) -> list[PackageExtra]:
def _get_wrapper_package_extras(self, package: Package) -> tuple[PackageExtra, ...]:
result: list[PackageExtra] = []
if package.data.pypi_full_name:
result.append(
Expand Down Expand Up @@ -400,4 +397,4 @@ def _get_wrapper_package_extras(self, package: Package) -> list[PackageExtra]:
)
for service_name in package.service_names
)
return result
return tuple(result)
Loading

0 comments on commit f58bef7

Please sign in to comment.