From 4ad25520cc7ad0801df123bc63ec5569871649ea Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 7 May 2025 22:38:37 +0200 Subject: [PATCH 1/5] Adds `__all__` to easy_imports.py to get rid of all the #noqa stuff --- bittensor/utils/easy_imports.py | 170 +++++++++++++++++++++++++++----- 1 file changed, 148 insertions(+), 22 deletions(-) diff --git a/bittensor/utils/easy_imports.py b/bittensor/utils/easy_imports.py index 8fa826d4d9..8a421fd43d 100644 --- a/bittensor/utils/easy_imports.py +++ b/bittensor/utils/easy_imports.py @@ -7,9 +7,9 @@ import importlib import sys -from bittensor_wallet import Keypair # noqa: F401 -from bittensor_wallet.errors import KeyFileError # noqa: F401 -from bittensor_wallet.keyfile import ( # noqa: F401 +from bittensor_wallet import Keypair +from bittensor_wallet.errors import KeyFileError +from bittensor_wallet.keyfile import ( serialized_keypair_to_keyfile_data, deserialize_keypair_from_keyfile_data, validate_password, @@ -25,12 +25,12 @@ decrypt_keyfile_data, Keyfile, ) -from bittensor_wallet.wallet import display_mnemonic_msg, Wallet # noqa: F401 +from bittensor_wallet.wallet import display_mnemonic_msg, Wallet -from bittensor.core import settings, timelock # noqa: F401 +from bittensor.core import settings, timelock from bittensor.core.async_subtensor import AsyncSubtensor from bittensor.core.axon import Axon -from bittensor.core.chain_data import ( # noqa: F401 +from bittensor.core.chain_data import ( AxonInfo, ChainIdentity, DelegateInfo, @@ -55,14 +55,14 @@ SubnetState, WeightCommitInfo, ) -from bittensor.core.config import ( # noqa: F401 +from bittensor.core.config import ( InvalidConfigFile, DefaultConfig, Config, T, ) -from bittensor.core.dendrite import Dendrite # noqa: F401 -from bittensor.core.errors import ( # noqa: F401 +from bittensor.core.dendrite import Dendrite +from bittensor.core.errors import ( BlacklistedException, ChainConnectionError, ChainError, @@ -102,15 +102,13 @@ ) from bittensor.core.metagraph import Metagraph from bittensor.core.settings import BLOCKTIME -from bittensor.core.stream import StreamingSynapse # noqa: F401 +from bittensor.core.stream import StreamingSynapse from bittensor.core.subtensor import Subtensor -from bittensor.core.subtensor_api import SubtensorApi # noqa: F401 -from bittensor.core.synapse import TerminalInfo, Synapse # noqa: F401 -from bittensor.core.tensor import Tensor # noqa: F401 -from bittensor.core.threadpool import ( # noqa: F401 - PriorityThreadPoolExecutor as PriorityThreadPoolExecutor, -) -from bittensor.utils import ( # noqa: F401 +from bittensor.core.subtensor_api import SubtensorApi +from bittensor.core.synapse import TerminalInfo, Synapse +from bittensor.core.tensor import Tensor +from bittensor.core.threadpool import PriorityThreadPoolExecutor +from bittensor.utils import ( ss58_to_vec_u8, version_checking, strtobool, @@ -120,14 +118,12 @@ u64_normalized_float, get_hash, ) -from bittensor.utils.balance import Balance as Balance # noqa: F401 +from bittensor.utils.balance import Balance from bittensor.utils.balance import tao, rao from bittensor.utils.btlogging import logging -from bittensor.utils.mock.subtensor_mock import MockSubtensor as MockSubtensor # noqa: F401 -from bittensor.utils.subnets import SubnetsAPI # noqa: F401 +from bittensor.utils.mock.subtensor_mock import MockSubtensor +from bittensor.utils.subnets import SubnetsAPI -tao = tao -rao = rao # Backwards compatibility with previous bittensor versions. async_subtensor = AsyncSubtensor @@ -201,3 +197,133 @@ def info(on: bool = True): on (bool): If True, enables info logging. If False, disables info logging and sets default (WARNING) level. """ logging.set_info(on) + + +__all__ = [ + "Keypair", + "KeyFileError", + "serialized_keypair_to_keyfile_data", + "deserialize_keypair_from_keyfile_data", + "validate_password", + "ask_password_to_encrypt", + "keyfile_data_is_encrypted_nacl", + "keyfile_data_is_encrypted_ansible", + "keyfile_data_is_encrypted_legacy", + "keyfile_data_is_encrypted", + "keyfile_data_encryption_method", + "legacy_encrypt_keyfile_data", + "encrypt_keyfile_data", + "get_coldkey_password_from_environment", + "decrypt_keyfile_data", + "Keyfile", + "display_mnemonic_msg", + "Wallet", + "settings", + "timelock", + "AsyncSubtensor", + "Axon", + "AxonInfo", + "ChainIdentity", + "DelegateInfo", + "DelegateInfoLite", + "DynamicInfo", + "IPInfo", + "MetagraphInfo", + "MetagraphInfoEmissions", + "MetagraphInfoParams", + "MetagraphInfoPool", + "NeuronInfo", + "NeuronInfoLite", + "PrometheusInfo", + "ProposalCallData", + "ProposalVoteData", + "ScheduledColdkeySwapInfo", + "SelectiveMetagraphIndex", + "StakeInfo", + "SubnetHyperparameters", + "SubnetIdentity", + "SubnetInfo", + "SubnetState", + "WeightCommitInfo", + "InvalidConfigFile", + "DefaultConfig", + "Config", + "T", + "Dendrite", + "BlacklistedException", + "ChainConnectionError", + "ChainError", + "ChainQueryError", + "ChainTransactionError", + "DelegateTakeTooHigh", + "DelegateTakeTooLow", + "DelegateTxRateLimitExceeded", + "DuplicateChild", + "HotKeyAccountNotExists", + "IdentityError", + "InternalServerError", + "InvalidChild", + "InvalidRequestNameError", + "MetadataError", + "NominationError", + "NonAssociatedColdKey", + "NotDelegateError", + "NotEnoughStakeToSetChildkeys", + "NotRegisteredError", + "NotVerifiedException", + "PostProcessException", + "PriorityException", + "ProportionOverflow", + "RegistrationError", + "RegistrationNotPermittedOnRootSubnet", + "RunException", + "StakeError", + "SubNetworkDoesNotExist", + "SynapseDendriteNoneException", + "SynapseParsingError", + "TooManyChildren", + "TransferError", + "TxRateLimitExceeded", + "UnknownSynapseError", + "UnstakeError", + "Metagraph", + "BLOCKTIME", + "StreamingSynapse", + "Subtensor", + "SubtensorApi", + "TerminalInfo", + "Synapse", + "Tensor", + "PriorityThreadPoolExecutor", + "ss58_to_vec_u8", + "version_checking", + "strtobool", + "get_explorer_url_for_network", + "ss58_address_to_bytes", + "u16_normalized_float", + "u64_normalized_float", + "get_hash", + "Balance", + "tao", + "rao", + "logging", + "MockSubtensor", + "SubnetsAPI", + "__blocktime__", + "__network_explorer_map__", + "__pipaddress__", + "__ss58_format__", + "__type_registry__", + "__ss58_address_length__", + "__networks__", + "__finney_entrypoint__", + "__finney_test_entrypoint__", + "__archive_entrypoint__", + "__local_entrypoint__", + "__tao_symbol__", + "__rao_symbol__", + "trace", + "debug", + "warning", + "info", +] From b83945d07339a038e7eed785d2189b27776ef6fa Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 7 May 2025 22:54:33 +0200 Subject: [PATCH 2/5] Missed some --- bittensor/utils/easy_imports.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bittensor/utils/easy_imports.py b/bittensor/utils/easy_imports.py index 8a421fd43d..93389e50ab 100644 --- a/bittensor/utils/easy_imports.py +++ b/bittensor/utils/easy_imports.py @@ -309,6 +309,15 @@ def info(on: bool = True): "logging", "MockSubtensor", "SubnetsAPI", + "async_subtensor", + "axon", + "config", + "dendrite", + "keyfile", + "metagraph", + "wallet", + "subtensor", + "synapse", "__blocktime__", "__network_explorer_map__", "__pipaddress__", From 0bb6682557fd3033da7ac10b4081160b9e1961d8 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 7 May 2025 23:30:26 +0200 Subject: [PATCH 3/5] Added test --- bittensor/utils/easy_imports.py | 2 ++ tests/unit_tests/test_easy_imports.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/unit_tests/test_easy_imports.py diff --git a/bittensor/utils/easy_imports.py b/bittensor/utils/easy_imports.py index 93389e50ab..7774e3f4d8 100644 --- a/bittensor/utils/easy_imports.py +++ b/bittensor/utils/easy_imports.py @@ -335,4 +335,6 @@ def info(on: bool = True): "debug", "warning", "info", + "mock_subpackage", + "extrinsics_subpackage", ] diff --git a/tests/unit_tests/test_easy_imports.py b/tests/unit_tests/test_easy_imports.py new file mode 100644 index 0000000000..bfe3ca6f23 --- /dev/null +++ b/tests/unit_tests/test_easy_imports.py @@ -0,0 +1,16 @@ +from bittensor.utils import easy_imports +import bittensor + +import pytest + + +@pytest.mark.parametrize( + "attr", + [ + a + for a in dir(easy_imports) + if (not a.startswith("__") and a not in ["sys", "importlib"]) # we don't care about systemwide pkgs + ], +) +def test_easy_imports(attr): + assert getattr(bittensor, attr), attr From db58ca2941858dd0b289ef1b758a94e4e547c49c Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 7 May 2025 23:48:31 +0200 Subject: [PATCH 4/5] Removed items. --- bittensor/utils/easy_imports.py | 23 +---------------------- tests/unit_tests/test_easy_imports.py | 4 +++- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/bittensor/utils/easy_imports.py b/bittensor/utils/easy_imports.py index 7774e3f4d8..512ca764ac 100644 --- a/bittensor/utils/easy_imports.py +++ b/bittensor/utils/easy_imports.py @@ -55,12 +55,7 @@ SubnetState, WeightCommitInfo, ) -from bittensor.core.config import ( - InvalidConfigFile, - DefaultConfig, - Config, - T, -) +from bittensor.core.config import Config from bittensor.core.dendrite import Dendrite from bittensor.core.errors import ( BlacklistedException, @@ -245,10 +240,7 @@ def info(on: bool = True): "SubnetInfo", "SubnetState", "WeightCommitInfo", - "InvalidConfigFile", - "DefaultConfig", "Config", - "T", "Dendrite", "BlacklistedException", "ChainConnectionError", @@ -318,19 +310,6 @@ def info(on: bool = True): "wallet", "subtensor", "synapse", - "__blocktime__", - "__network_explorer_map__", - "__pipaddress__", - "__ss58_format__", - "__type_registry__", - "__ss58_address_length__", - "__networks__", - "__finney_entrypoint__", - "__finney_test_entrypoint__", - "__archive_entrypoint__", - "__local_entrypoint__", - "__tao_symbol__", - "__rao_symbol__", "trace", "debug", "warning", diff --git a/tests/unit_tests/test_easy_imports.py b/tests/unit_tests/test_easy_imports.py index bfe3ca6f23..8ebd020faf 100644 --- a/tests/unit_tests/test_easy_imports.py +++ b/tests/unit_tests/test_easy_imports.py @@ -9,7 +9,9 @@ [ a for a in dir(easy_imports) - if (not a.startswith("__") and a not in ["sys", "importlib"]) # we don't care about systemwide pkgs + if ( + not a.startswith("__") and a not in ["sys", "importlib"] + ) # we don't care about systemwide pkgs ], ) def test_easy_imports(attr): From 69b55ec72e3e1380fc02a28c6a791afcd3986f0f Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 7 May 2025 23:51:35 +0200 Subject: [PATCH 5/5] Removed more items. --- bittensor/utils/easy_imports.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/bittensor/utils/easy_imports.py b/bittensor/utils/easy_imports.py index 512ca764ac..a2645b0668 100644 --- a/bittensor/utils/easy_imports.py +++ b/bittensor/utils/easy_imports.py @@ -131,23 +131,6 @@ subtensor = Subtensor synapse = Synapse -__blocktime__ = BLOCKTIME -__network_explorer_map__ = settings.NETWORK_EXPLORER_MAP -__pipaddress__ = settings.PIPADDRESS -__ss58_format__ = settings.SS58_FORMAT -__type_registry__ = settings.TYPE_REGISTRY -__ss58_address_length__ = settings.SS58_ADDRESS_LENGTH - -__networks__ = settings.NETWORKS - -__finney_entrypoint__ = settings.FINNEY_ENTRYPOINT -__finney_test_entrypoint__ = settings.FINNEY_TEST_ENTRYPOINT -__archive_entrypoint__ = settings.ARCHIVE_ENTRYPOINT -__local_entrypoint__ = settings.LOCAL_ENTRYPOINT - -__tao_symbol__ = settings.TAO_SYMBOL -__rao_symbol__ = settings.RAO_SYMBOL - # Makes the `bittensor.utils.mock` subpackage available as `bittensor.mock` for backwards compatibility. mock_subpackage = importlib.import_module("bittensor.utils.mock") sys.modules["bittensor.mock"] = mock_subpackage