Skip to content

Commit

Permalink
Optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-opentensor committed Aug 13, 2024
1 parent 38bbf7b commit 4e44f13
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 50 deletions.
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions bittensor/core/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 5 additions & 4 deletions bittensor/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions bittensor/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
41 changes: 20 additions & 21 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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] = {}

Expand Down
8 changes: 5 additions & 3 deletions bittensor/core/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 8 additions & 9 deletions bittensor/core/threadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@

__author__ = "Brian Quinlan ([email protected])"

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
Expand Down
1 change: 0 additions & 1 deletion bittensor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion bittensor/utils/btlogging/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

from colorama import init, Fore, Back, Style


init(autoreset=True)

TRACE_LEVEL_NUM: int = 5
Expand Down
1 change: 0 additions & 1 deletion bittensor/utils/btlogging/loggingmachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from statemachine import State, StateMachine

from bittensor.core.config import Config

from .defines import (
BITTENSOR_LOGGER_NAME,
DATE_FORMAT,
Expand Down
2 changes: 1 addition & 1 deletion bittensor/utils/deprecated/extrinsics/set_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion bittensor/utils/deprecated/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions bittensor/utils/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e44f13

Please sign in to comment.