From 683fd45e3a24a76e5ae2e7b1f192ab88892f28cf Mon Sep 17 00:00:00 2001 From: antazoey Date: Tue, 12 Nov 2024 21:16:37 -0600 Subject: [PATCH] perf: make plugin load faster (#30) --- ape_bsc/__init__.py | 30 +++++++++++++++++++++++++----- setup.cfg | 3 ++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ape_bsc/__init__.py b/ape_bsc/__init__.py index f939836..9ad4eef 100644 --- a/ape_bsc/__init__.py +++ b/ape_bsc/__init__.py @@ -1,23 +1,31 @@ from ape import plugins -from ape.api.networks import LOCAL_NETWORK_NAME, ForkedNetworkAPI, NetworkAPI, create_network_type -from ape_node import Node -from ape_test import LocalProvider - -from .ecosystem import BSC, NETWORKS, BSCConfig @plugins.register(plugins.Config) def config_class(): + from .ecosystem import BSCConfig + return BSCConfig @plugins.register(plugins.EcosystemPlugin) def ecosystems(): + from .ecosystem import BSC + yield BSC @plugins.register(plugins.NetworkPlugin) def networks(): + from ape.api.networks import ( + LOCAL_NETWORK_NAME, + ForkedNetworkAPI, + NetworkAPI, + create_network_type, + ) + + from .ecosystem import NETWORKS + for network_name, network_params in NETWORKS.items(): yield "bsc", network_name, create_network_type(*network_params) yield "bsc", f"{network_name}-fork", ForkedNetworkAPI @@ -28,7 +36,19 @@ def networks(): @plugins.register(plugins.ProviderPlugin) def providers(): + from ape.api.networks import LOCAL_NETWORK_NAME + from ape_node import Node + from ape_test import LocalProvider + + from .ecosystem import NETWORKS + for network_name in NETWORKS: yield "bsc", network_name, Node yield "bsc", LOCAL_NETWORK_NAME, LocalProvider + + +def __getattr__(name: str): + import ape_bsc.ecosystem as module + + return getattr(module, name) diff --git a/setup.cfg b/setup.cfg index fb8dd96..a71f67c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,8 +1,9 @@ [flake8] max-line-length = 100 -ignore = E704,W503,PYD002 +ignore = E704,W503,PYD002,TC003,TC006 exclude = venv* .eggs docs build +type-checking-pydantic-enabled = True