Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
139 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Product-related enums. | ||
""" | ||
|
||
from enum import Enum | ||
|
||
|
||
class ProductLibrary(Enum): | ||
""" | ||
Product library for Generator. | ||
""" | ||
|
||
boto3 = "boto3" | ||
aiobotocore = "aiobotocore" | ||
aioboto3 = "aioboto3" | ||
|
||
|
||
class ProductType(Enum): | ||
""" | ||
Product type for Generator. | ||
""" | ||
|
||
stubs = "stubs" | ||
service_stubs = "service_stubs" | ||
docs = "docs" | ||
|
||
|
||
class Product(Enum): | ||
""" | ||
Product choice for CLI. | ||
""" | ||
|
||
boto3 = "boto3" | ||
boto3_services = "boto3-services" | ||
boto3_docs = "boto3-docs" | ||
aiobotocore = "aiobotocore" | ||
aiobotocore_services = "aiobotocore-services" | ||
aiobotocore_docs = "aiobotocore-docs" | ||
aioboto3 = "aioboto3" | ||
aioboto3_docs = "aioboto3-docs" | ||
|
||
def __str__(self) -> str: | ||
""" | ||
Get string representation for debugging. | ||
""" | ||
return self.value | ||
|
||
def get_library(self) -> ProductLibrary: | ||
""" | ||
Get library name. | ||
""" | ||
for library in ProductLibrary: | ||
if self.value.startswith(library.value): | ||
return library | ||
raise ValueError(f"No library found for {self.value}") | ||
|
||
def get_type(self) -> ProductType: | ||
""" | ||
Get product type. | ||
""" | ||
if "-" not in self.value: | ||
return ProductType.stubs | ||
if self.value.endswith("-services"): | ||
return ProductType.service_stubs | ||
if self.value.endswith("-docs"): | ||
return ProductType.docs | ||
raise ValueError(f"No type found for {self.value}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Wrapper for TypedDict maps. | ||
""" | ||
|
||
from collections.abc import Iterator | ||
|
||
from mypy_boto3_builder.type_annotations.type_typed_dict import TypeTypedDict | ||
from mypy_boto3_builder.utils.type_def_sorter import TypeDefSorter | ||
|
||
|
||
class TypedDictMap(dict[str, TypeTypedDict]): | ||
""" | ||
Wrapper for TypedDict maps. | ||
""" | ||
|
||
def add(self, item: TypeTypedDict) -> None: | ||
""" | ||
Add new item. | ||
""" | ||
self[item.name] = item | ||
|
||
def iterate_pairs(self, name: str) -> Iterator[tuple[str, TypeTypedDict]]: | ||
""" | ||
Iterate over pairs mathed by real dict name. | ||
""" | ||
for key, value in list(self.items()): | ||
if value.name == name: | ||
yield key, value | ||
|
||
def rename(self, item: TypeTypedDict, new_name: str) -> None: | ||
""" | ||
Rename item and change mapping. | ||
""" | ||
for key, value in list(self.items()): | ||
if value == item: | ||
del self[key] | ||
|
||
item.name = new_name | ||
self[new_name] = item | ||
|
||
def get_sorted_names(self) -> list[str]: | ||
""" | ||
Get real TypedDict names topologically sorted. | ||
""" | ||
sorted_values = TypeDefSorter(self.values()).sort() | ||
allowed_names = {i.name for i in self.values()} | ||
return [i.name for i in sorted_values if i.name in allowed_names] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters