remove lazy import
This commit is contained in:
parent
d692c301aa
commit
20e7b7004b
|
@ -1,76 +1,24 @@
|
|||
__version__ = "0.1.6a"
|
||||
|
||||
import traceback
|
||||
import typing
|
||||
from .errors import SignatureFailureError
|
||||
from .message import Attachment, Message, ActorMixin
|
||||
from .misc import Digest, HttpDate, JsonBase, Signature
|
||||
from .objects import HostMeta, HostMetaJson, Nodeinfo, Webfinger, WellKnownNodeinfo
|
||||
from .enums import (
|
||||
Enum,
|
||||
IntEnum,
|
||||
StrEnum,
|
||||
AlgorithmType,
|
||||
KeyType,
|
||||
NodeinfoProtocol,
|
||||
NodeinfoServiceInbound,
|
||||
NodeinfoServiceOutbound,
|
||||
NodeinfoVersion,
|
||||
ObjectType
|
||||
)
|
||||
|
||||
from importlib import import_module
|
||||
from pathlib import Path
|
||||
try:
|
||||
from .signer import Signer
|
||||
|
||||
|
||||
MODULES = {
|
||||
# message
|
||||
"Attachment": "message",
|
||||
"Message": "message",
|
||||
"ActorMixin": "message_types",
|
||||
|
||||
# misc
|
||||
"Digest": "misc",
|
||||
"HttpDate": "misc",
|
||||
"JsonBase": "misc",
|
||||
"Signature": "misc",
|
||||
|
||||
# objects
|
||||
"HostMeta": "objects",
|
||||
"HostMetaJson": "objects",
|
||||
"Nodeinfo": "objects",
|
||||
"Webfinger": "objects",
|
||||
"WellKnownNodeinfo": "objects",
|
||||
|
||||
# signer
|
||||
"Signer": "signer",
|
||||
|
||||
# enums
|
||||
"Enum": "enums",
|
||||
"IntEnum": "enums",
|
||||
"StrEnum": "enums",
|
||||
"AlgorithmType": "enums",
|
||||
"KeyType": "enums",
|
||||
"NodeinfoProtocol": "enums",
|
||||
"NodeinfoServiceInbound": "enums",
|
||||
"NodeinfoServiceOutbound": "enums",
|
||||
"NodeinfoVersion": "enums",
|
||||
"ObjectType": "enums",
|
||||
|
||||
# exceptions
|
||||
"SignatureFailureError": "errors"
|
||||
}
|
||||
|
||||
|
||||
# lazy import
|
||||
def __getattr__(key: str) -> typing.Any:
|
||||
try:
|
||||
return globals()[key]
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
module = import_module(f"aputils.{MODULES[key]}")
|
||||
return getattr(module, key)
|
||||
|
||||
except ModuleNotFoundError:
|
||||
traceback.print_exc()
|
||||
raise ImportError(f"Cannot import '{key}' from 'aputils.{MODULES[key]}'") from None
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
raise e
|
||||
|
||||
return import_module(f"aputils.{key}")
|
||||
|
||||
|
||||
def get_hook_dirs() -> list[str]: # pylint: disable=missing-function-docstring
|
||||
return [str(Path(__file__).resolve().parent)]
|
||||
except ImportError:
|
||||
Signer = None
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
hiddenimports: list[str] = [
|
||||
"aputils.enums",
|
||||
"aputils.errors",
|
||||
"aputils.misc",
|
||||
"aputils.objects",
|
||||
"aputils.signer"
|
||||
]
|
Loading…
Reference in a new issue