-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
25 changed files
with
203 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Wrapper for ImportString usage. | ||
Copyright 2024 Vlad Emelianov | ||
""" | ||
|
||
from typing import Final | ||
|
||
from mypy_boto3_builder.exceptions import StructureError | ||
from mypy_boto3_builder.import_helpers.import_parent import ImportParent | ||
from mypy_boto3_builder.import_helpers.import_string import ImportString | ||
|
||
|
||
class Import: | ||
""" | ||
Wrapper for ImportString usage. | ||
""" | ||
|
||
future: Final = ImportString(ImportParent.future.value) | ||
builtins: Final = ImportString(ImportParent.builtins.value) | ||
boto3: Final = ImportString(ImportParent.boto3.value) | ||
botocore: Final = ImportString(ImportParent.botocore.value) | ||
typing: Final = ImportString(ImportParent.typing.value) | ||
awscrt: Final = ImportString(ImportParent.awscrt.value) | ||
s3transfer: Final = ImportString(ImportParent.s3transfer.value) | ||
aiobotocore: Final = ImportString(ImportParent.aiobotocore.value) | ||
aioboto3: Final = ImportString(ImportParent.aioboto3.value) | ||
typing_extensions: Final = ImportString(ImportParent.typing_extensions.value) | ||
types: Final = ImportString(ImportParent.types.value) | ||
sys: Final = ImportString(ImportParent.sys.value) | ||
|
||
@classmethod | ||
def local(cls, module_name: str) -> ImportString: | ||
""" | ||
Create local import string. | ||
""" | ||
if not module_name: | ||
raise StructureError("Module name cannot be empty for local import") | ||
return ImportString("", module_name) | ||
|
||
@classmethod | ||
def from_str(cls, import_string: str) -> ImportString: | ||
""" | ||
Create from string. | ||
""" | ||
return cls.from_parts(*import_string.split(".")) | ||
|
||
@classmethod | ||
def from_parts(cls, parent: str, *parts: str) -> ImportString: | ||
""" | ||
Create from string. | ||
""" | ||
if not parent: | ||
raise StructureError("Parent cannot be empty") | ||
return ImportString(parent, *parts) |
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,53 @@ | ||
""" | ||
Enum with all parent imports. | ||
Copyright 2024 Vlad Emelianov | ||
""" | ||
|
||
from enum import Enum | ||
from typing import Final | ||
|
||
|
||
class ImportParent(Enum): | ||
""" | ||
Enum with all parent imports. | ||
""" | ||
|
||
future = "__future__" | ||
builtins = "builtins" | ||
boto3 = "boto3" | ||
botocore = "botocore" | ||
typing = "typing" | ||
awscrt = "awscrt" | ||
s3transfer = "s3transfer" | ||
aiobotocore = "aiobotocore" | ||
aioboto3 = "aioboto3" | ||
typing_extensions = "typing_extensions" | ||
types = "types" | ||
sys = "sys" | ||
|
||
@classmethod | ||
def is_third_party(cls, parent_name: str) -> bool: | ||
""" | ||
Whether import is from 3rd party module. | ||
""" | ||
return parent_name in _THIRD_PARTY | ||
|
||
@classmethod | ||
def is_builtins(cls, parent_name: str) -> bool: | ||
""" | ||
Whether import is from Python `builtins` module. | ||
""" | ||
return parent_name == cls.builtins.value | ||
|
||
|
||
_THIRD_PARTY: Final = frozenset( | ||
( | ||
ImportParent.boto3.value, | ||
ImportParent.botocore.value, | ||
ImportParent.aioboto3.value, | ||
ImportParent.aiobotocore.value, | ||
ImportParent.s3transfer.value, | ||
ImportParent.awscrt.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
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
Oops, something went wrong.