Skip to content

Commit d0197d8

Browse files
authored
Merge pull request #2863 from opentensor/fix/thewhaleking/add-all-easy-imports
Adds `__all__` to easy_imports.py to get rid of all the #noqa stuff
2 parents fd22870 + 69b55ec commit d0197d8

File tree

2 files changed

+161
-44
lines changed

2 files changed

+161
-44
lines changed

bittensor/utils/easy_imports.py

Lines changed: 143 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import importlib
88
import sys
99

10-
from bittensor_wallet import Keypair # noqa: F401
11-
from bittensor_wallet.errors import KeyFileError # noqa: F401
12-
from bittensor_wallet.keyfile import ( # noqa: F401
10+
from bittensor_wallet import Keypair
11+
from bittensor_wallet.errors import KeyFileError
12+
from bittensor_wallet.keyfile import (
1313
serialized_keypair_to_keyfile_data,
1414
deserialize_keypair_from_keyfile_data,
1515
validate_password,
@@ -25,12 +25,12 @@
2525
decrypt_keyfile_data,
2626
Keyfile,
2727
)
28-
from bittensor_wallet.wallet import display_mnemonic_msg, Wallet # noqa: F401
28+
from bittensor_wallet.wallet import display_mnemonic_msg, Wallet
2929

30-
from bittensor.core import settings, timelock # noqa: F401
30+
from bittensor.core import settings, timelock
3131
from bittensor.core.async_subtensor import AsyncSubtensor
3232
from bittensor.core.axon import Axon
33-
from bittensor.core.chain_data import ( # noqa: F401
33+
from bittensor.core.chain_data import (
3434
AxonInfo,
3535
ChainIdentity,
3636
DelegateInfo,
@@ -55,14 +55,9 @@
5555
SubnetState,
5656
WeightCommitInfo,
5757
)
58-
from bittensor.core.config import ( # noqa: F401
59-
InvalidConfigFile,
60-
DefaultConfig,
61-
Config,
62-
T,
63-
)
64-
from bittensor.core.dendrite import Dendrite # noqa: F401
65-
from bittensor.core.errors import ( # noqa: F401
58+
from bittensor.core.config import Config
59+
from bittensor.core.dendrite import Dendrite
60+
from bittensor.core.errors import (
6661
BlacklistedException,
6762
ChainConnectionError,
6863
ChainError,
@@ -102,15 +97,13 @@
10297
)
10398
from bittensor.core.metagraph import Metagraph
10499
from bittensor.core.settings import BLOCKTIME
105-
from bittensor.core.stream import StreamingSynapse # noqa: F401
100+
from bittensor.core.stream import StreamingSynapse
106101
from bittensor.core.subtensor import Subtensor
107-
from bittensor.core.subtensor_api import SubtensorApi # noqa: F401
108-
from bittensor.core.synapse import TerminalInfo, Synapse # noqa: F401
109-
from bittensor.core.tensor import Tensor # noqa: F401
110-
from bittensor.core.threadpool import ( # noqa: F401
111-
PriorityThreadPoolExecutor as PriorityThreadPoolExecutor,
112-
)
113-
from bittensor.utils import ( # noqa: F401
102+
from bittensor.core.subtensor_api import SubtensorApi
103+
from bittensor.core.synapse import TerminalInfo, Synapse
104+
from bittensor.core.tensor import Tensor
105+
from bittensor.core.threadpool import PriorityThreadPoolExecutor
106+
from bittensor.utils import (
114107
ss58_to_vec_u8,
115108
version_checking,
116109
strtobool,
@@ -120,14 +113,12 @@
120113
u64_normalized_float,
121114
get_hash,
122115
)
123-
from bittensor.utils.balance import Balance as Balance # noqa: F401
116+
from bittensor.utils.balance import Balance
124117
from bittensor.utils.balance import tao, rao
125118
from bittensor.utils.btlogging import logging
126-
from bittensor.utils.mock.subtensor_mock import MockSubtensor as MockSubtensor # noqa: F401
127-
from bittensor.utils.subnets import SubnetsAPI # noqa: F401
119+
from bittensor.utils.mock.subtensor_mock import MockSubtensor
120+
from bittensor.utils.subnets import SubnetsAPI
128121

129-
tao = tao
130-
rao = rao
131122

132123
# Backwards compatibility with previous bittensor versions.
133124
async_subtensor = AsyncSubtensor
@@ -140,23 +131,6 @@
140131
subtensor = Subtensor
141132
synapse = Synapse
142133

143-
__blocktime__ = BLOCKTIME
144-
__network_explorer_map__ = settings.NETWORK_EXPLORER_MAP
145-
__pipaddress__ = settings.PIPADDRESS
146-
__ss58_format__ = settings.SS58_FORMAT
147-
__type_registry__ = settings.TYPE_REGISTRY
148-
__ss58_address_length__ = settings.SS58_ADDRESS_LENGTH
149-
150-
__networks__ = settings.NETWORKS
151-
152-
__finney_entrypoint__ = settings.FINNEY_ENTRYPOINT
153-
__finney_test_entrypoint__ = settings.FINNEY_TEST_ENTRYPOINT
154-
__archive_entrypoint__ = settings.ARCHIVE_ENTRYPOINT
155-
__local_entrypoint__ = settings.LOCAL_ENTRYPOINT
156-
157-
__tao_symbol__ = settings.TAO_SYMBOL
158-
__rao_symbol__ = settings.RAO_SYMBOL
159-
160134
# Makes the `bittensor.utils.mock` subpackage available as `bittensor.mock` for backwards compatibility.
161135
mock_subpackage = importlib.import_module("bittensor.utils.mock")
162136
sys.modules["bittensor.mock"] = mock_subpackage
@@ -201,3 +175,128 @@ def info(on: bool = True):
201175
on (bool): If True, enables info logging. If False, disables info logging and sets default (WARNING) level.
202176
"""
203177
logging.set_info(on)
178+
179+
180+
__all__ = [
181+
"Keypair",
182+
"KeyFileError",
183+
"serialized_keypair_to_keyfile_data",
184+
"deserialize_keypair_from_keyfile_data",
185+
"validate_password",
186+
"ask_password_to_encrypt",
187+
"keyfile_data_is_encrypted_nacl",
188+
"keyfile_data_is_encrypted_ansible",
189+
"keyfile_data_is_encrypted_legacy",
190+
"keyfile_data_is_encrypted",
191+
"keyfile_data_encryption_method",
192+
"legacy_encrypt_keyfile_data",
193+
"encrypt_keyfile_data",
194+
"get_coldkey_password_from_environment",
195+
"decrypt_keyfile_data",
196+
"Keyfile",
197+
"display_mnemonic_msg",
198+
"Wallet",
199+
"settings",
200+
"timelock",
201+
"AsyncSubtensor",
202+
"Axon",
203+
"AxonInfo",
204+
"ChainIdentity",
205+
"DelegateInfo",
206+
"DelegateInfoLite",
207+
"DynamicInfo",
208+
"IPInfo",
209+
"MetagraphInfo",
210+
"MetagraphInfoEmissions",
211+
"MetagraphInfoParams",
212+
"MetagraphInfoPool",
213+
"NeuronInfo",
214+
"NeuronInfoLite",
215+
"PrometheusInfo",
216+
"ProposalCallData",
217+
"ProposalVoteData",
218+
"ScheduledColdkeySwapInfo",
219+
"SelectiveMetagraphIndex",
220+
"StakeInfo",
221+
"SubnetHyperparameters",
222+
"SubnetIdentity",
223+
"SubnetInfo",
224+
"SubnetState",
225+
"WeightCommitInfo",
226+
"Config",
227+
"Dendrite",
228+
"BlacklistedException",
229+
"ChainConnectionError",
230+
"ChainError",
231+
"ChainQueryError",
232+
"ChainTransactionError",
233+
"DelegateTakeTooHigh",
234+
"DelegateTakeTooLow",
235+
"DelegateTxRateLimitExceeded",
236+
"DuplicateChild",
237+
"HotKeyAccountNotExists",
238+
"IdentityError",
239+
"InternalServerError",
240+
"InvalidChild",
241+
"InvalidRequestNameError",
242+
"MetadataError",
243+
"NominationError",
244+
"NonAssociatedColdKey",
245+
"NotDelegateError",
246+
"NotEnoughStakeToSetChildkeys",
247+
"NotRegisteredError",
248+
"NotVerifiedException",
249+
"PostProcessException",
250+
"PriorityException",
251+
"ProportionOverflow",
252+
"RegistrationError",
253+
"RegistrationNotPermittedOnRootSubnet",
254+
"RunException",
255+
"StakeError",
256+
"SubNetworkDoesNotExist",
257+
"SynapseDendriteNoneException",
258+
"SynapseParsingError",
259+
"TooManyChildren",
260+
"TransferError",
261+
"TxRateLimitExceeded",
262+
"UnknownSynapseError",
263+
"UnstakeError",
264+
"Metagraph",
265+
"BLOCKTIME",
266+
"StreamingSynapse",
267+
"Subtensor",
268+
"SubtensorApi",
269+
"TerminalInfo",
270+
"Synapse",
271+
"Tensor",
272+
"PriorityThreadPoolExecutor",
273+
"ss58_to_vec_u8",
274+
"version_checking",
275+
"strtobool",
276+
"get_explorer_url_for_network",
277+
"ss58_address_to_bytes",
278+
"u16_normalized_float",
279+
"u64_normalized_float",
280+
"get_hash",
281+
"Balance",
282+
"tao",
283+
"rao",
284+
"logging",
285+
"MockSubtensor",
286+
"SubnetsAPI",
287+
"async_subtensor",
288+
"axon",
289+
"config",
290+
"dendrite",
291+
"keyfile",
292+
"metagraph",
293+
"wallet",
294+
"subtensor",
295+
"synapse",
296+
"trace",
297+
"debug",
298+
"warning",
299+
"info",
300+
"mock_subpackage",
301+
"extrinsics_subpackage",
302+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from bittensor.utils import easy_imports
2+
import bittensor
3+
4+
import pytest
5+
6+
7+
@pytest.mark.parametrize(
8+
"attr",
9+
[
10+
a
11+
for a in dir(easy_imports)
12+
if (
13+
not a.startswith("__") and a not in ["sys", "importlib"]
14+
) # we don't care about systemwide pkgs
15+
],
16+
)
17+
def test_easy_imports(attr):
18+
assert getattr(bittensor, attr), attr

0 commit comments

Comments
 (0)