From 4e44f132339209deb9c6d060ed043ded662cee4c Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 13 Aug 2024 13:09:45 -0700 Subject: [PATCH] Optimize imports --- bittensor/__init__.py | 2 +- bittensor/core/chain_data.py | 4 +- bittensor/core/config.py | 9 ++-- bittensor/core/settings.py | 5 +-- bittensor/core/subtensor.py | 41 +++++++++---------- bittensor/core/tensor.py | 8 ++-- bittensor/core/threadpool.py | 17 ++++---- bittensor/utils/__init__.py | 1 - bittensor/utils/btlogging/format.py | 1 - bittensor/utils/btlogging/loggingmachine.py | 1 - .../deprecated/extrinsics/set_weights.py | 2 +- .../utils/deprecated/extrinsics/transfer.py | 2 +- bittensor/utils/version.py | 3 +- 13 files changed, 46 insertions(+), 50 deletions(-) diff --git a/bittensor/__init__.py b/bittensor/__init__.py index b131d13f0..cf2cb8ce7 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -19,8 +19,8 @@ import warnings from .core.settings import __version__, version_split, DEFAULTS -from .utils.deprecated import * from .utils.btlogging import logging +from .utils.deprecated import * def __getattr__(name): diff --git a/bittensor/core/chain_data.py b/bittensor/core/chain_data.py index 6d4e6103c..b01dcc665 100644 --- a/bittensor/core/chain_data.py +++ b/bittensor/core/chain_data.py @@ -30,11 +30,11 @@ from scalecodec.types import GenericCall from scalecodec.utils.ss58 import ss58_encode -from .settings import SS58_FORMAT from bittensor.utils import networking as net, RAOPERTAO, u16_normalized_float from bittensor.utils.balance import Balance -from bittensor.utils.registration import torch, use_torch from bittensor.utils.btlogging import logging +from bittensor.utils.registration import torch, use_torch +from .settings import SS58_FORMAT custom_rpc_type_registry = { "types": { diff --git a/bittensor/core/config.py b/bittensor/core/config.py index 61afb5f05..9bfa25f67 100644 --- a/bittensor/core/config.py +++ b/bittensor/core/config.py @@ -20,14 +20,15 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. +import argparse +import copy import os import sys -import yaml -import copy from copy import deepcopy -from munch import DefaultMunch from typing import List, Optional, Dict, Any, TypeVar, Type -import argparse + +import yaml +from munch import DefaultMunch class InvalidConfigFile(Exception): diff --git a/bittensor/core/settings.py b/bittensor/core/settings.py index 254868b7f..cc6ab0769 100644 --- a/bittensor/core/settings.py +++ b/bittensor/core/settings.py @@ -20,11 +20,10 @@ import os import re from pathlib import Path -from rich.console import Console -from rich.traceback import install from munch import munchify - +from rich.console import Console +from rich.traceback import install # Rich console. __console__ = Console() diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index f50d449d7..73dfaa334 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -37,6 +37,26 @@ from scalecodec.types import ScaleType from substrateinterface.base import QueryMapResult, SubstrateInterface +from bittensor.core import settings +from bittensor.core.axon import Axon +from bittensor.core.chain_data import ( + NeuronInfo, + PrometheusInfo, + SubnetHyperparameters, + NeuronInfoLite, + custom_rpc_type_registry, +) +from bittensor.core.config import Config +from bittensor.core.metagraph import Metagraph +from bittensor.core.types import AxonServeCallParams, PrometheusServeCallParams +from bittensor.utils import torch, format_error_message +from bittensor.utils import u16_normalized_float, networking +from bittensor.utils.balance import Balance +from bittensor.utils.btlogging import logging +from bittensor.utils.deprecated.extrinsics.commit_weights import ( + commit_weights_extrinsic, + reveal_weights_extrinsic, +) from bittensor.utils.deprecated.extrinsics.prometheus import ( prometheus_extrinsic, ) @@ -49,31 +69,10 @@ from bittensor.utils.deprecated.extrinsics.set_weights import ( set_weights_extrinsic, ) -from bittensor.utils.deprecated.extrinsics.commit_weights import ( - commit_weights_extrinsic, - reveal_weights_extrinsic, -) from bittensor.utils.deprecated.extrinsics.transfer import ( transfer_extrinsic, ) from bittensor.utils.weight_utils import generate_weight_hash -from bittensor.core import settings -from bittensor.core.axon import Axon -from bittensor.core.chain_data import ( - NeuronInfo, - PrometheusInfo, - SubnetHyperparameters, - NeuronInfoLite, - custom_rpc_type_registry, -) -from bittensor.core.config import Config -from bittensor.core.metagraph import Metagraph -from bittensor.core.types import AxonServeCallParams, PrometheusServeCallParams -from bittensor.utils import u16_normalized_float, networking -from bittensor.utils import torch, format_error_message -from bittensor.utils.balance import Balance -from bittensor.utils.btlogging import logging - KEY_NONCE: Dict[str, int] = {} diff --git a/bittensor/core/tensor.py b/bittensor/core/tensor.py index e50947e71..c3bb29edb 100644 --- a/bittensor/core/tensor.py +++ b/bittensor/core/tensor.py @@ -15,14 +15,16 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -import numpy as np import base64 +from typing import Optional, Union, List + import msgpack import msgpack_numpy -from typing import Optional, Union, List -from bittensor.utils.registration import torch, use_torch +import numpy as np from pydantic import ConfigDict, BaseModel, Field, field_validator +from bittensor.utils.registration import torch, use_torch + class DTypes(dict): def __init__(self, *args, **kwargs): diff --git a/bittensor/core/threadpool.py b/bittensor/core/threadpool.py index 4a8b1d302..17e553509 100644 --- a/bittensor/core/threadpool.py +++ b/bittensor/core/threadpool.py @@ -5,23 +5,22 @@ __author__ = "Brian Quinlan (brian@sweetapp.com)" +import argparse +import itertools +import logging import os -import sys -import time import queue import random -import weakref -import logging -import argparse -import itertools +import sys import threading - -from typing import Callable +import time +import weakref from concurrent.futures import _base +from typing import Callable from bittensor.core.config import Config -from bittensor.utils.btlogging.defines import BITTENSOR_LOGGER_NAME from bittensor.core.settings import BLOCKTIME +from bittensor.utils.btlogging.defines import BITTENSOR_LOGGER_NAME # Workers are created as daemon threads. This is done to allow the interpreter # to exit when there are still idle threads in a ThreadPoolExecutor's thread diff --git a/bittensor/utils/__init__.py b/bittensor/utils/__init__.py index 3089aff70..2423b6b39 100644 --- a/bittensor/utils/__init__.py +++ b/bittensor/utils/__init__.py @@ -27,7 +27,6 @@ from .registration import torch, use_torch from .version import version_checking, check_version, VersionCheckError - RAOPERTAO = 1e9 U16_MAX = 65535 U64_MAX = 18446744073709551615 diff --git a/bittensor/utils/btlogging/format.py b/bittensor/utils/btlogging/format.py index 131085f17..cbde7e9eb 100644 --- a/bittensor/utils/btlogging/format.py +++ b/bittensor/utils/btlogging/format.py @@ -27,7 +27,6 @@ from colorama import init, Fore, Back, Style - init(autoreset=True) TRACE_LEVEL_NUM: int = 5 diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index adbb4e929..b9e0408ce 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -34,7 +34,6 @@ from statemachine import State, StateMachine from bittensor.core.config import Config - from .defines import ( BITTENSOR_LOGGER_NAME, DATE_FORMAT, diff --git a/bittensor/utils/deprecated/extrinsics/set_weights.py b/bittensor/utils/deprecated/extrinsics/set_weights.py index 15681dbb1..f62a23d44 100644 --- a/bittensor/utils/deprecated/extrinsics/set_weights.py +++ b/bittensor/utils/deprecated/extrinsics/set_weights.py @@ -23,8 +23,8 @@ from numpy.typing import NDArray from rich.prompt import Confirm -from bittensor.utils import weight_utils from bittensor.core.settings import bt_console +from bittensor.utils import weight_utils from bittensor.utils.btlogging import logging from bittensor.utils.registration import torch, use_torch diff --git a/bittensor/utils/deprecated/extrinsics/transfer.py b/bittensor/utils/deprecated/extrinsics/transfer.py index 7f7decccf..3f6c964d9 100644 --- a/bittensor/utils/deprecated/extrinsics/transfer.py +++ b/bittensor/utils/deprecated/extrinsics/transfer.py @@ -17,13 +17,13 @@ from typing import Union, TYPE_CHECKING +from bittensor_wallet import Wallet from rich.prompt import Confirm from bittensor.core.settings import bt_console, NETWORK_EXPLORER_MAP from bittensor.utils import get_explorer_url_for_network from bittensor.utils import is_valid_bittensor_address_or_public_key from bittensor.utils.balance import Balance -from bittensor_wallet import Wallet # For annotation purposes if TYPE_CHECKING: diff --git a/bittensor/utils/version.py b/bittensor/utils/version.py index f0ff70763..8ffd969cf 100644 --- a/bittensor/utils/version.py +++ b/bittensor/utils/version.py @@ -22,8 +22,7 @@ import requests from packaging.version import Version -from bittensor.core.settings import __version__ -from bittensor.core.settings import PIPADDRESS +from bittensor.core.settings import __version__, PIPADDRESS from bittensor.utils.btlogging import logging VERSION_CHECK_THRESHOLD = 86400