From 8c5e8799ed33e20a2b81bede112e1fd256b54888 Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Sat, 30 Nov 2024 18:08:49 +0300 Subject: [PATCH] Optimize templates --- .../generators/aioboto3_generator.py | 1 - .../boto3-stubs-full/README.md.jinja2 | 26 +------------------ .../templates/boto3-stubs/README.md.jinja2 | 26 +------------------ .../templates/common/usage.md.jinja2 | 23 ++++++++++++++++ .../templates/common/usage_full.md.jinja2 | 23 ++++++++++++++++ .../templates/common/wrapper/README.md.jinja2 | 11 ++++++++ .../types-aioboto3-custom/README.md.jinja2 | 2 +- .../templates/types-aioboto3/README.md.jinja2 | 12 +-------- .../types-aiobotocore-custom/README.md.jinja2 | 2 +- .../types-aiobotocore/README.md.jinja2 | 13 +--------- .../types-boto3-full/README.md.jinja2 | 24 ----------------- .../templates/types-boto3/README.md.jinja2 | 24 ----------------- 12 files changed, 63 insertions(+), 124 deletions(-) create mode 100644 mypy_boto3_builder/templates/common/wrapper/README.md.jinja2 diff --git a/mypy_boto3_builder/generators/aioboto3_generator.py b/mypy_boto3_builder/generators/aioboto3_generator.py index 1aa8bbb7..758af390 100644 --- a/mypy_boto3_builder/generators/aioboto3_generator.py +++ b/mypy_boto3_builder/generators/aioboto3_generator.py @@ -183,7 +183,6 @@ def generate_custom_stubs(self) -> Package: package_data=aiobotocore_package_data, version=aiobotocore_package_data.get_library_version(), ) - # raise ValueError(self.output_path / aiobotocore_package_data.NAME) aiobotocore_package_writer = PackageWriter( output_path=self.output_path / package.directory_name, generate_package=False, diff --git a/mypy_boto3_builder/templates/boto3-stubs-full/README.md.jinja2 b/mypy_boto3_builder/templates/boto3-stubs-full/README.md.jinja2 index 36e84092..c7a8d459 100644 --- a/mypy_boto3_builder/templates/boto3-stubs-full/README.md.jinja2 +++ b/mypy_boto3_builder/templates/boto3-stubs-full/README.md.jinja2 @@ -4,7 +4,7 @@ {% include "common/usage_full.md.jinja2" with context %} -### Explicit type annotations +## Explicit type annotations To speed up type checking and code completion, you can set types explicitly. @@ -26,28 +26,4 @@ bundle_task_complete_waiter: BundleTaskCompleteWaiter = ec2_client.get_waiter("b describe_volumes_paginator: DescribeVolumesPaginator = ec2_client.get_paginator("describe_volumes") ``` -### Pylint compatibility - -It is totally safe to use `TYPE_CHECKING` flag in order to avoid `{{ package.pypi_name }}` -dependency in production. -However, there is an issue in `pylint` that it complains about undefined -variables. To fix it, set all types to `object` in non-`TYPE_CHECKING` mode. - -```python -import boto3 -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from {{ package.data.SERVICE_PREFIX }}_ec2 import EC2Client, EC2ServiceResource - from {{ package.data.SERVICE_PREFIX }}_ec2.waiters import BundleTaskCompleteWaiter - from {{ package.data.SERVICE_PREFIX }}_ec2.paginators import DescribeVolumesPaginator -else: - EC2Client = object - EC2ServiceResource = object - BundleTaskCompleteWaiter = object - DescribeVolumesPaginator = object - -... -``` - {% include "common/footer.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/boto3-stubs/README.md.jinja2 b/mypy_boto3_builder/templates/boto3-stubs/README.md.jinja2 index 23b54419..ef6a3159 100644 --- a/mypy_boto3_builder/templates/boto3-stubs/README.md.jinja2 +++ b/mypy_boto3_builder/templates/boto3-stubs/README.md.jinja2 @@ -6,7 +6,7 @@ {% include "common/usage.md.jinja2" with context %} {% endwith %} -### Explicit type annotations +## Explicit type annotations To speed up type checking and code completion, you can set types explicitly. @@ -28,30 +28,6 @@ bundle_task_complete_waiter: BundleTaskCompleteWaiter = ec2_client.get_waiter("b describe_volumes_paginator: DescribeVolumesPaginator = ec2_client.get_paginator("describe_volumes") ``` -### Pylint compatibility - -It is totally safe to use `TYPE_CHECKING` flag in order to avoid `{{ package.pypi_name }}` -dependency in production. -However, there is an issue in `pylint` that it complains about undefined -variables. To fix it, set all types to `object` in non-`TYPE_CHECKING` mode. - -```python -import boto3 -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from {{ package.data.SERVICE_PREFIX }}_ec2 import EC2Client, EC2ServiceResource - from {{ package.data.SERVICE_PREFIX }}_ec2.waiters import BundleTaskCompleteWaiter - from {{ package.data.SERVICE_PREFIX }}_ec2.paginators import DescribeVolumesPaginator -else: - EC2Client = object - EC2ServiceResource = object - BundleTaskCompleteWaiter = object - DescribeVolumesPaginator = object - -... -``` - {% include "common/footer.md.jinja2" with context %} {% include "common/submodules.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/common/usage.md.jinja2 b/mypy_boto3_builder/templates/common/usage.md.jinja2 index 19b3bc04..1df30ac9 100644 --- a/mypy_boto3_builder/templates/common/usage.md.jinja2 +++ b/mypy_boto3_builder/templates/common/usage.md.jinja2 @@ -116,3 +116,26 @@ Optionally, you can install `{{ package.data.PYPI_NAME }}` to `typings` director Type checking should now work. No explicit type annotations required, write your `{{ package.library_name }}` code as usual. + +### Pylint compatibility + +It is totally safe to use `TYPE_CHECKING` flag in order to avoid `{{ package.pypi_name }}` +dependency in production. +However, there is an issue in `pylint` that it complains about undefined +variables. To fix it, set all types to `object` in non-`TYPE_CHECKING` mode. + +```python +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from {{ package.data.SERVICE_PREFIX }}_ec2 import EC2Client, EC2ServiceResource + from {{ package.data.SERVICE_PREFIX }}_ec2.waiters import BundleTaskCompleteWaiter + from {{ package.data.SERVICE_PREFIX }}_ec2.paginators import DescribeVolumesPaginator +else: + EC2Client = object + EC2ServiceResource = object + BundleTaskCompleteWaiter = object + DescribeVolumesPaginator = object + +... +``` diff --git a/mypy_boto3_builder/templates/common/usage_full.md.jinja2 b/mypy_boto3_builder/templates/common/usage_full.md.jinja2 index 9cac9d07..6c526cf5 100644 --- a/mypy_boto3_builder/templates/common/usage_full.md.jinja2 +++ b/mypy_boto3_builder/templates/common/usage_full.md.jinja2 @@ -115,3 +115,26 @@ Optionally, you can install `{{ package.data.PYPI_NAME }}` to `typings` director Type checking should now work. No explicit type annotations required, write your `{{ package.library_name }}` code as usual. + +### Pylint compatibility + +It is totally safe to use `TYPE_CHECKING` flag in order to avoid `{{ package.pypi_name }}` +dependency in production. +However, there is an issue in `pylint` that it complains about undefined +variables. To fix it, set all types to `object` in non-`TYPE_CHECKING` mode. + +```python +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from {{ package.data.SERVICE_PREFIX }}_ec2 import EC2Client, EC2ServiceResource + from {{ package.data.SERVICE_PREFIX }}_ec2.waiters import BundleTaskCompleteWaiter + from {{ package.data.SERVICE_PREFIX }}_ec2.paginators import DescribeVolumesPaginator +else: + EC2Client = object + EC2ServiceResource = object + BundleTaskCompleteWaiter = object + DescribeVolumesPaginator = object + +... +``` diff --git a/mypy_boto3_builder/templates/common/wrapper/README.md.jinja2 b/mypy_boto3_builder/templates/common/wrapper/README.md.jinja2 new file mode 100644 index 00000000..7fa3fbd0 --- /dev/null +++ b/mypy_boto3_builder/templates/common/wrapper/README.md.jinja2 @@ -0,0 +1,11 @@ +{% include "common/header.md.jinja2" with context %} + +{% include "common/how_to_install.md.jinja2" with context %} + +{% with extras_name="essential" %} +{% include "common/usage.md.jinja2" with context %} +{% endwith %} + +{% include "common/footer.md.jinja2" with context %} + +{% include "common/submodules.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/types-aioboto3-custom/README.md.jinja2 b/mypy_boto3_builder/templates/types-aioboto3-custom/README.md.jinja2 index 32a77102..6e2a22fd 100644 --- a/mypy_boto3_builder/templates/types-aioboto3-custom/README.md.jinja2 +++ b/mypy_boto3_builder/templates/types-aioboto3-custom/README.md.jinja2 @@ -1 +1 @@ -{% include "types-aioboto3/README.md.jinja2" with context %} +{% include "common/wrapper/README.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/types-aioboto3/README.md.jinja2 b/mypy_boto3_builder/templates/types-aioboto3/README.md.jinja2 index 7fa3fbd0..32a77102 100644 --- a/mypy_boto3_builder/templates/types-aioboto3/README.md.jinja2 +++ b/mypy_boto3_builder/templates/types-aioboto3/README.md.jinja2 @@ -1,11 +1 @@ -{% include "common/header.md.jinja2" with context %} - -{% include "common/how_to_install.md.jinja2" with context %} - -{% with extras_name="essential" %} -{% include "common/usage.md.jinja2" with context %} -{% endwith %} - -{% include "common/footer.md.jinja2" with context %} - -{% include "common/submodules.md.jinja2" with context %} +{% include "types-aioboto3/README.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/types-aiobotocore-custom/README.md.jinja2 b/mypy_boto3_builder/templates/types-aiobotocore-custom/README.md.jinja2 index 80a740d8..6e2a22fd 100644 --- a/mypy_boto3_builder/templates/types-aiobotocore-custom/README.md.jinja2 +++ b/mypy_boto3_builder/templates/types-aiobotocore-custom/README.md.jinja2 @@ -1 +1 @@ -{% include "types-aiobotocore/README.md.jinja2" with context %} +{% include "common/wrapper/README.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/types-aiobotocore/README.md.jinja2 b/mypy_boto3_builder/templates/types-aiobotocore/README.md.jinja2 index 73294927..6e2a22fd 100644 --- a/mypy_boto3_builder/templates/types-aiobotocore/README.md.jinja2 +++ b/mypy_boto3_builder/templates/types-aiobotocore/README.md.jinja2 @@ -1,12 +1 @@ -{% include "common/header.md.jinja2" with context %} - -{% include "common/how_to_install.md.jinja2" with context %} - -{% with extras_name="essential" %} -{% include "common/usage.md.jinja2" with context %} -{% endwith %} - -{% include "common/footer.md.jinja2" with context %} - -{% include "common/submodules.md.jinja2" with context %} - +{% include "common/wrapper/README.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/types-boto3-full/README.md.jinja2 b/mypy_boto3_builder/templates/types-boto3-full/README.md.jinja2 index 36e84092..ad1d867d 100644 --- a/mypy_boto3_builder/templates/types-boto3-full/README.md.jinja2 +++ b/mypy_boto3_builder/templates/types-boto3-full/README.md.jinja2 @@ -26,28 +26,4 @@ bundle_task_complete_waiter: BundleTaskCompleteWaiter = ec2_client.get_waiter("b describe_volumes_paginator: DescribeVolumesPaginator = ec2_client.get_paginator("describe_volumes") ``` -### Pylint compatibility - -It is totally safe to use `TYPE_CHECKING` flag in order to avoid `{{ package.pypi_name }}` -dependency in production. -However, there is an issue in `pylint` that it complains about undefined -variables. To fix it, set all types to `object` in non-`TYPE_CHECKING` mode. - -```python -import boto3 -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from {{ package.data.SERVICE_PREFIX }}_ec2 import EC2Client, EC2ServiceResource - from {{ package.data.SERVICE_PREFIX }}_ec2.waiters import BundleTaskCompleteWaiter - from {{ package.data.SERVICE_PREFIX }}_ec2.paginators import DescribeVolumesPaginator -else: - EC2Client = object - EC2ServiceResource = object - BundleTaskCompleteWaiter = object - DescribeVolumesPaginator = object - -... -``` - {% include "common/footer.md.jinja2" with context %} diff --git a/mypy_boto3_builder/templates/types-boto3/README.md.jinja2 b/mypy_boto3_builder/templates/types-boto3/README.md.jinja2 index 23b54419..57cb9058 100644 --- a/mypy_boto3_builder/templates/types-boto3/README.md.jinja2 +++ b/mypy_boto3_builder/templates/types-boto3/README.md.jinja2 @@ -28,30 +28,6 @@ bundle_task_complete_waiter: BundleTaskCompleteWaiter = ec2_client.get_waiter("b describe_volumes_paginator: DescribeVolumesPaginator = ec2_client.get_paginator("describe_volumes") ``` -### Pylint compatibility - -It is totally safe to use `TYPE_CHECKING` flag in order to avoid `{{ package.pypi_name }}` -dependency in production. -However, there is an issue in `pylint` that it complains about undefined -variables. To fix it, set all types to `object` in non-`TYPE_CHECKING` mode. - -```python -import boto3 -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from {{ package.data.SERVICE_PREFIX }}_ec2 import EC2Client, EC2ServiceResource - from {{ package.data.SERVICE_PREFIX }}_ec2.waiters import BundleTaskCompleteWaiter - from {{ package.data.SERVICE_PREFIX }}_ec2.paginators import DescribeVolumesPaginator -else: - EC2Client = object - EC2ServiceResource = object - BundleTaskCompleteWaiter = object - DescribeVolumesPaginator = object - -... -``` - {% include "common/footer.md.jinja2" with context %} {% include "common/submodules.md.jinja2" with context %}