Skip to content

Commit

Permalink
Setup loguru logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Jan 10, 2025
1 parent 342219e commit b6e2e5b
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 149 deletions.
6 changes: 5 additions & 1 deletion mypy_boto3_builder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Builder for `mypy_boto3`.
Main library entrypoint.
"""

from mypy_boto3_builder.logger import disable_logger

disable_logger()
2 changes: 2 additions & 0 deletions mypy_boto3_builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
Copyright 2024 Vlad Emelianov
"""

from mypy_boto3_builder.logger import enable_logger
from mypy_boto3_builder.main import main

if __name__ == "__main__":
enable_logger()
main()
17 changes: 9 additions & 8 deletions mypy_boto3_builder/generators/aioboto3_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ def generate_stubs(self) -> TypesAioBoto3Package | None:
package_data = TypesAioBoto3PackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_aioboto3_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -89,11 +88,10 @@ def generate_stubs_lite(self) -> TypesAioBoto3Package | None:
package_data = TypesAioBoto3LitePackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_aioboto3_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -116,7 +114,10 @@ def generate_docs(self) -> None:
package_data = TypesAioBoto3PackageData()
total_str = f"{len(self.service_names)}"

self.logger.info(f"Generating {package_data.pypi_name} module docs")
self.logger.info(
f"Generating {package_data.pypi_name} module docs",
tags=(package_data.pypi_name,),
)
package = parse_types_aioboto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -157,7 +158,7 @@ def generate_custom_stubs(self) -> TypesAioBoto3Package:
package_data = TypesAioBoto3CustomPackageData()
aiobotocore_package_data = TypesAioBotocorePackageData()

self.logger.info(f"Generating {package_data.pypi_name} {self.version}")
self._log_generate(package_data.pypi_name, self.version)
package = parse_types_aioboto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down
23 changes: 11 additions & 12 deletions mypy_boto3_builder/generators/aiobotocore_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ def generate_stubs(self) -> TypesAioBotocorePackage | None:
package_data = TypesAioBotocorePackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

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

self._log_generate(package_data.pypi_name, version)
package = parse_types_aiobotocore_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -79,11 +77,10 @@ def generate_stubs_lite(self) -> TypesAioBotocorePackage | None:
package_data = TypesAioBotocoreLitePackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, self.version)
package = parse_types_aiobotocore_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -106,7 +103,10 @@ def generate_docs(self) -> None:
package_data = TypesAioBotocorePackageData()
total_str = f"{len(self.service_names)}"

self.logger.info(f"Generating {package_data.pypi_name} module docs")
self.logger.info(
f"Generating {package_data.pypi_name} module docs",
tags=(package_data.pypi_name,),
)
package = parse_types_aiobotocore_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -135,11 +135,10 @@ def generate_full_stubs(self) -> TypesAioBotocorePackage | None:
package_data = TypesAioBotocoreFullPackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_aiobotocore_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -170,7 +169,7 @@ def generate_custom_stubs(self) -> TypesAioBotocorePackage:
"""
package_data = TypesAioBotocoreCustomPackageData()

self.logger.info(f"Generating {package_data.pypi_name} {self.version}")
self._log_generate(package_data.pypi_name, self.version)
package = parse_types_aiobotocore_package(
service_names=self.service_names,
package_data=package_data,
Expand Down
31 changes: 25 additions & 6 deletions mypy_boto3_builder/generators/base_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def _get_package_build_version(self, pypi_name: str) -> str:
return self.version

if self.config.skip_published:
self.logger.info(
f"Skipping {pypi_name}: {self.version} is already on PyPI",
tags=(pypi_name,),
)
raise AlreadyPublishedError(f"{pypi_name} {self.version} is already on PyPI")

return pypi_manager.get_next_version(self.version)
Expand Down Expand Up @@ -196,6 +200,7 @@ def _generate_full_stubs_services(self, package: Package) -> None:

self.logger.info(
f"{progress_str} Generating {service_name.boto3_name} service directory",
tags=(service_name.boto3_name,),
)
service_package = self._parse_service_package(
service_name=service_name,
Expand Down Expand Up @@ -251,7 +256,9 @@ def _parse_service_package(
version: str,
package_data: BasePackageData,
) -> ServicePackage:
self.logger.debug(f"Parsing {service_name.boto3_name}")
self.logger.debug(
f"Parsing {service_name.boto3_name} botocore service", tags=(service_name.boto3_name,)
)
parser = ServicePackageParser(service_name, package_data, version)
service_package = parser.parse()

Expand All @@ -277,7 +284,10 @@ def _process_service(
)
service_package.mark_safe_typed_dicts()

self.logger.debug(f"Writing {service_name.boto3_name}")
self.logger.debug(
f"Writing {service_name.boto3_name} service package",
tags=(service_name.boto3_name,),
)
self.package_writer.write_service_package(
service_package,
templates_path=templates_path,
Expand All @@ -297,7 +307,10 @@ def _process_service_docs(
package_data=package_data,
)

self.logger.debug(f"Writing {service_name.boto3_name}")
self.logger.debug(
f"Writing {service_name.boto3_name} service docs",
tags=(service_name.boto3_name,),
)
self.package_writer.write_service_docs(
service_package,
templates_path=templates_path,
Expand All @@ -317,11 +330,10 @@ def generate_service_stubs(self) -> list[ServicePackage]:
pypi_name = self.service_package_data.get_service_pypi_name(service_name)
try:
version = self._get_package_build_version(pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"{progress_str} Skipping {pypi_name}: {e}")
except AlreadyPublishedError:
continue

self.logger.info(f"{progress_str} Generating {pypi_name} {version}")
self.logger.info(f"{progress_str} Generating {pypi_name} {version}", tags=(pypi_name,))
package = self._process_service(
service_name=service_name,
version=version,
Expand Down Expand Up @@ -398,3 +410,10 @@ def _get_wrapper_package_extras(self, package: Package) -> tuple[PackageExtra, .
for service_name in package.service_names
)
return tuple(result)

def _log_generate(self, pypi_name: str, version: str | None = None) -> None:
version_str = version or self.version
self.logger.info(
f"Generating {pypi_name} {version_str}",
tags=(pypi_name,),
)
22 changes: 11 additions & 11 deletions mypy_boto3_builder/generators/boto3_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ def generate_stubs(self) -> TypesBoto3Package | None:
package_data = Boto3StubsPackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_boto3_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -78,11 +77,10 @@ def generate_stubs_lite(self) -> Package | None:
package_data = Boto3StubsLitePackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_boto3_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -108,7 +106,10 @@ def generate_docs(self) -> None:
package_data = Boto3StubsPackageData()
total_str = f"{len(self.service_names)}"

self.logger.info(f"Generating {package_data.name} module docs")
self.logger.info(
f"Generating {package_data.pypi_name} package docs",
tags=(package_data.pypi_name,),
)
package = parse_types_boto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -138,11 +139,10 @@ def generate_full_stubs(self) -> Package | None:
package_data = Boto3StubsFullPackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_boto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -174,7 +174,7 @@ def generate_custom_stubs(self) -> Package:
"""
package_data = Boto3StubsCustomPackageData()

self.logger.info(f"Generating {package_data.pypi_name} {self.version}")
self._log_generate(package_data.pypi_name, self.version)
package = parse_types_boto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down
5 changes: 2 additions & 3 deletions mypy_boto3_builder/generators/mypy_boto3_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ def generate_stubs(self) -> MypyBoto3Package | None:
package_data = MypyBoto3PackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_mypy_boto3_package(service_names=self.main_service_names, version=version)
self.package_writer.write_package(
package,
Expand Down
22 changes: 11 additions & 11 deletions mypy_boto3_builder/generators/types_boto3_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ def generate_stubs(self) -> TypesBoto3Package | None:
package_data = TypesBoto3PackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_boto3_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -78,11 +77,10 @@ def generate_stubs_lite(self) -> TypesBoto3Package | None:
package_data = TypesBoto3LitePackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_boto3_package(
service_names=self.main_service_names,
package_data=package_data,
Expand All @@ -108,7 +106,10 @@ def generate_docs(self) -> None:
package_data = TypesBoto3PackageData()
total_str = f"{len(self.service_names)}"

self.logger.info(f"Generating {package_data.name} module docs")
self.logger.info(
f"Generating {package_data.pypi_name} package docs",
tags=(package_data.pypi_name,),
)
package = parse_types_boto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -138,11 +139,10 @@ def generate_full_stubs(self) -> TypesBoto3Package | None:
package_data = TypesBoto3FullPackageData()
try:
version = self._get_package_build_version(package_data.pypi_name)
except AlreadyPublishedError as e:
self.logger.info(f"Skipping {package_data.pypi_name}: {e}")
except AlreadyPublishedError:
return None

self.logger.info(f"Generating {package_data.pypi_name} {version}")
self._log_generate(package_data.pypi_name, version)
package = parse_types_boto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down Expand Up @@ -174,7 +174,7 @@ def generate_custom_stubs(self) -> TypesBoto3Package:
"""
package_data = TypesBoto3CustomPackageData()

self.logger.info(f"Generating {package_data.pypi_name} {self.version}")
self._log_generate(package_data.pypi_name, self.version)
package = parse_types_boto3_package(
service_names=self.service_names,
package_data=package_data,
Expand Down
Loading

0 comments on commit b6e2e5b

Please sign in to comment.