Skip to content

Commit

Permalink
Optimize templates
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Nov 30, 2024
1 parent c19083b commit 8c5e879
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 124 deletions.
1 change: 0 additions & 1 deletion mypy_boto3_builder/generators/aioboto3_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 1 addition & 25 deletions mypy_boto3_builder/templates/boto3-stubs-full/README.md.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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 %}
26 changes: 1 addition & 25 deletions mypy_boto3_builder/templates/boto3-stubs/README.md.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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 %}
23 changes: 23 additions & 0 deletions mypy_boto3_builder/templates/common/usage.md.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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

...
```
23 changes: 23 additions & 0 deletions mypy_boto3_builder/templates/common/usage_full.md.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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

...
```
11 changes: 11 additions & 0 deletions mypy_boto3_builder/templates/common/wrapper/README.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% include "types-aioboto3/README.md.jinja2" with context %}
{% include "common/wrapper/README.md.jinja2" with context %}
12 changes: 1 addition & 11 deletions mypy_boto3_builder/templates/types-aioboto3/README.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 %}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{% include "types-aiobotocore/README.md.jinja2" with context %}
{% include "common/wrapper/README.md.jinja2" with context %}
13 changes: 1 addition & 12 deletions mypy_boto3_builder/templates/types-aiobotocore/README.md.jinja2
Original file line number Diff line number Diff line change
@@ -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 %}
24 changes: 0 additions & 24 deletions mypy_boto3_builder/templates/types-boto3-full/README.md.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
24 changes: 0 additions & 24 deletions mypy_boto3_builder/templates/types-boto3/README.md.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit 8c5e879

Please sign in to comment.