diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 6b2eaa0333..0000000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -max-line-length = 120 -exclude = .git,__pycache__, __init__.py, docs/source/conf.py,old,build,dist,venv,.venv,.tox -select = E9,F63,F7,F82,F401 diff --git a/.github/workflows/flake8-and-mypy.yml b/.github/workflows/mypy.yml similarity index 93% rename from .github/workflows/flake8-and-mypy.yml rename to .github/workflows/mypy.yml index d1470cd6ef..ee436db4ca 100644 --- a/.github/workflows/flake8-and-mypy.yml +++ b/.github/workflows/mypy.yml @@ -1,4 +1,4 @@ -name: Flake8 and Mypy - linters check +name: Mypy check permissions: contents: read @@ -55,8 +55,5 @@ jobs: - name: Sync dev deps run: uv sync --extra dev --dev - - name: Flake8 - run: uv run flake8 bittensor/ --count - - name: Mypy run: uv run mypy --ignore-missing-imports bittensor/ diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index fdf1141a7b..4990b1e391 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -1,4 +1,4 @@ -name: Ruff - formatter check +name: Ruff - formatter/linter check permissions: contents: read @@ -8,26 +8,22 @@ on: jobs: ruff: - if: github.event.pull_request.draft == false runs-on: ubuntu-latest - + timeout-minutes: 10 steps: - name: Checkout repository uses: actions/checkout@v6 - - name: Set up Python - uses: actions/setup-python@v6 + - name: Ruff format check + uses: astral-sh/ruff-action@v4.0.0 with: - python-version: "3.11" - - - name: Install Ruff in virtual environment - run: | - python -m venv venv - source venv/bin/activate - python -m pip install --upgrade pip - python -m pip install ruff==0.11.5 + version: "0.11.5" + args: "format --diff" + src: "bittensor tests" - - name: Ruff format check - run: | - source venv/bin/activate - python -m ruff format --diff bittensor + - name: Ruff linter check + uses: astral-sh/ruff-action@v4.0.0 + with: + version: "0.11.5" + args: "check" + src: "bittensor" diff --git a/Makefile b/Makefile index f71c2c2a2b..b776718f25 100644 --- a/Makefile +++ b/Makefile @@ -35,4 +35,4 @@ check: ruff @mypy --ignore-missing-imports bittensor/ --python-version=3.12 @mypy --ignore-missing-imports bittensor/ --python-version=3.13 @mypy --ignore-missing-imports bittensor/ --python-version=3.14 - @flake8 bittensor/ --count + @python -m ruff check bittensor/ diff --git a/bittensor/__init__.py b/bittensor/__init__.py index e290570af2..a9d99b0c76 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -1,3 +1,7 @@ -from .core.settings import __version__, DEFAULTS, DEFAULT_NETWORK -from .utils.btlogging import logging -from .utils.easy_imports import * +from .core.settings import ( + __version__ as __version__, + DEFAULTS as DEFAULTS, + DEFAULT_NETWORK as DEFAULT_NETWORK, +) +from .utils.btlogging import logging # noqa: F401 +from .utils.easy_imports import * # noqa: F403 diff --git a/bittensor/core/extrinsics/asyncex/registration.py b/bittensor/core/extrinsics/asyncex/registration.py index adcd78c992..2e9531380f 100644 --- a/bittensor/core/extrinsics/asyncex/registration.py +++ b/bittensor/core/extrinsics/asyncex/registration.py @@ -341,7 +341,7 @@ async def register_extrinsic( if not torch.cuda.is_available(): return ExtrinsicResponse(False, "CUDA not available.").with_log() - logging.debug(f"Creating a POW with CUDA.") + logging.debug("Creating a POW with CUDA.") pow_result = await create_pow_async( subtensor=subtensor, wallet=wallet, @@ -355,7 +355,7 @@ async def register_extrinsic( log_verbose=log_verbose, ) else: - logging.debug(f"Creating a POW.") + logging.debug("Creating a POW.") pow_result = await create_pow_async( subtensor=subtensor, wallet=wallet, diff --git a/bittensor/core/extrinsics/registration.py b/bittensor/core/extrinsics/registration.py index 50962fb9c1..fd8952bbf8 100644 --- a/bittensor/core/extrinsics/registration.py +++ b/bittensor/core/extrinsics/registration.py @@ -333,7 +333,7 @@ def register_extrinsic( if not torch.cuda.is_available(): return ExtrinsicResponse(False, "CUDA not available.").with_log() - logging.debug(f"Creating a POW with CUDA.") + logging.debug("Creating a POW with CUDA.") pow_result = create_pow( subtensor=subtensor, wallet=wallet, @@ -347,7 +347,7 @@ def register_extrinsic( log_verbose=log_verbose, ) else: - logging.debug(f"Creating a POW.") + logging.debug("Creating a POW.") pow_result = create_pow( subtensor=subtensor, wallet=wallet, diff --git a/bittensor/core/extrinsics/utils.py b/bittensor/core/extrinsics/utils.py index a491d82da8..7af0985eab 100644 --- a/bittensor/core/extrinsics/utils.py +++ b/bittensor/core/extrinsics/utils.py @@ -217,11 +217,11 @@ def apply_pure_proxy_data( # If triggered events are not available or event PureCreated does not exist in the response, return the response # with warning message ot raise the error if raise_error is True. message = ( - f"The ExtrinsicResponse doesn't contain pure_proxy data (`pure_account`, `spawner`, `proxy_type`, etc.) " - f"because the extrinsic receipt doesn't have triggered events. This typically happens when " - f"`wait_for_inclusion=False` or when `block_hash` is not available. To get this data, either pass " - f"`wait_for_inclusion=True` when calling this function, or retrieve the data manually from the blockchain " - f"using the extrinsic hash." + "The ExtrinsicResponse doesn't contain pure_proxy data (`pure_account`, `spawner`, `proxy_type`, etc.) " + "because the extrinsic receipt doesn't have triggered events. This typically happens when " + "`wait_for_inclusion=False` or when `block_hash` is not available. To get this data, either pass " + "`wait_for_inclusion=True` when calling this function, or retrieve the data manually from the blockchain " + "using the extrinsic hash." ) if response.extrinsic is not None and hasattr(response.extrinsic, "extrinsic_hash"): extrinsic_hash = response.extrinsic.extrinsic_hash diff --git a/bittensor/core/metagraph.py b/bittensor/core/metagraph.py index 44f4a033c1..5496dfca9c 100644 --- a/bittensor/core/metagraph.py +++ b/bittensor/core/metagraph.py @@ -320,7 +320,7 @@ def S(self) -> Tensor: return self.stake @property - def I(self) -> Tensor: + def I(self) -> Tensor: # noqa: E743 """ Incentive values of neurons represent the rewards they receive for their contributions to the network. The Bittensor network employs an incentive mechanism that rewards neurons based on their diff --git a/bittensor/extras/dev_framework/__init__.py b/bittensor/extras/dev_framework/__init__.py index 6aed8910fc..2fbd8693b4 100644 --- a/bittensor/extras/dev_framework/__init__.py +++ b/bittensor/extras/dev_framework/__init__.py @@ -1,8 +1,8 @@ -from .calls import * # noqa: F401 +from .calls import * # noqa: F403 from .subnet import ( - NETUID, - TestSubnet, - ACTIVATE_SUBNET, - REGISTER_SUBNET, - REGISTER_NEURON, + NETUID as NETUID, + TestSubnet as TestSubnet, + ACTIVATE_SUBNET as ACTIVATE_SUBNET, + REGISTER_SUBNET as REGISTER_SUBNET, + REGISTER_NEURON as REGISTER_NEURON, ) diff --git a/bittensor/extras/dev_framework/calls/__init__.py b/bittensor/extras/dev_framework/calls/__init__.py index 0455d723f9..f88c0a6808 100644 --- a/bittensor/extras/dev_framework/calls/__init__.py +++ b/bittensor/extras/dev_framework/calls/__init__.py @@ -11,9 +11,9 @@ import os from bittensor import Subtensor -from bittensor.extras.dev_framework.calls.sudo_calls import * # noqa: F401 -from bittensor.extras.dev_framework.calls.non_sudo_calls import * # noqa: F401 -from bittensor.extras.dev_framework.calls.pallets import * # noqa: F401 +from bittensor.extras.dev_framework.calls.sudo_calls import * # noqa: F403 +from bittensor.extras.dev_framework.calls.non_sudo_calls import * # noqa: F403 +from bittensor.extras.dev_framework.calls.pallets import * # noqa: F403 HEADER = '''""" This file is auto-generated. Do not edit manually. diff --git a/bittensor/extras/dev_framework/subnet.py b/bittensor/extras/dev_framework/subnet.py index b14c530500..13b15366cc 100644 --- a/bittensor/extras/dev_framework/subnet.py +++ b/bittensor/extras/dev_framework/subnet.py @@ -10,7 +10,7 @@ from bittensor.core.types import ExtrinsicResponse from bittensor.extras import SubtensorApi from bittensor.utils.btlogging import logging -from .calls import * # noqa: F401# +from .calls import * # noqa: F403 from .utils import ( is_instance_namedtuple, split_command, diff --git a/bittensor/utils/__init__.py b/bittensor/utils/__init__.py index 44889d4c40..52003f0017 100644 --- a/bittensor/utils/__init__.py +++ b/bittensor/utils/__init__.py @@ -28,7 +28,6 @@ if TYPE_CHECKING: from bittensor_wallet import Wallet from bittensor.core.types import ExtrinsicResponse - from bittensor.utils.balance import Balance # keep save from import analyzer as obvious aliases hex_to_ss58 = ss58_encode diff --git a/bittensor/utils/btlogging/defines.py b/bittensor/utils/btlogging/defines.py index f71a99e702..526e5444b3 100644 --- a/bittensor/utils/btlogging/defines.py +++ b/bittensor/utils/btlogging/defines.py @@ -2,7 +2,7 @@ BASE_LOG_FORMAT = "%(asctime)s | %(levelname)s | %(message)s" TRACE_LOG_FORMAT = ( - f"%(asctime)s | %(levelname)s | %(name)s:%(filename)s:%(lineno)s | %(message)s" + "%(asctime)s | %(levelname)s | %(name)s:%(filename)s:%(lineno)s | %(message)s" ) DATE_FORMAT = "%Y-%m-%d %H:%M:%S" BITTENSOR_LOGGER_NAME = "bittensor" diff --git a/bittensor/utils/mock/__init__.py b/bittensor/utils/mock/__init__.py index 04893c78a3..fc4d22dacf 100644 --- a/bittensor/utils/mock/__init__.py +++ b/bittensor/utils/mock/__init__.py @@ -1 +1 @@ -from .subtensor_mock import MockSubtensor +from .subtensor_mock import MockSubtensor as MockSubtensor diff --git a/bittensor/utils/mock/subtensor_mock.py b/bittensor/utils/mock/subtensor_mock.py index 95c6d4af54..832d24a2c0 100644 --- a/bittensor/utils/mock/subtensor_mock.py +++ b/bittensor/utils/mock/subtensor_mock.py @@ -871,9 +871,6 @@ def _neuron_subnet_exists( dividends = self._get_most_recent_storage( subtensor_state["Dividends"][netuid][uid], block ) - pruning_score = self._get_most_recent_storage( - subtensor_state["PruningScores"][netuid][uid], block - ) last_update = self._get_most_recent_storage( subtensor_state["LastUpdate"][netuid][uid], block ) diff --git a/bittensor/utils/version.py b/bittensor/utils/version.py index e78fd109e8..53aa8b8550 100644 --- a/bittensor/utils/version.py +++ b/bittensor/utils/version.py @@ -117,6 +117,6 @@ def check_latest_version_in_pypi(): except InvalidVersion: # stay silent if InvalidVersion pass - except (requests.RequestException, KeyError) as e: + except (requests.RequestException, KeyError): # stay silent if not internet connection or pypi.org issue pass diff --git a/pyproject.toml b/pyproject.toml index b43cab375c..21579e3984 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ version = "10.2.0" description = "Bittensor SDK" readme = "README.md" authors = [ - {name = "bittensor.com"} + { name = "bittensor.com" } ] license = { file = "LICENSE" } requires-python = ">=3.10,<3.15" @@ -48,7 +48,6 @@ dev = [ "pytest-cov==4.0.0", "ddt==1.6.0", "hypothesis==6.81.1", - "flake8==7.0.0", "mypy==1.8.0", "types-retry==0.9.9.4", "typing_extensions>= 4.0.0; python_version<'3.11'", @@ -94,5 +93,11 @@ classifiers = [ ] [tool.setuptools] -package-dir = {"bittensor" = "bittensor"} +package-dir = { "bittensor" = "bittensor" } script-files = ["bittensor/utils/certifi.sh"] + +[tool.ruff] +exclude = [".git", "__pycache__", "__init__.py", "docs/source/conf.py", "old", "build", "dist", "venv", ".venv", ".tox"] + +[tool.ruff.lint] +select = ["E9", "F63", "F7", "F82", "F401"] diff --git a/tests/consistency/test_proxy_types.py b/tests/consistency/test_proxy_types.py index ab9462f8bc..5bb3e8be6b 100644 --- a/tests/consistency/test_proxy_types.py +++ b/tests/consistency/test_proxy_types.py @@ -1,5 +1,4 @@ from bittensor.core.chain_data.proxy import ProxyType -from bittensor.core.extrinsics.pallets import SubtensorModule, Proxy, Balances def get_proxy_type_fields(meta): diff --git a/tests/e2e_tests/test_crowdloan.py b/tests/e2e_tests/test_crowdloan.py index 52b99bfc9c..b771d36609 100644 --- a/tests/e2e_tests/test_crowdloan.py +++ b/tests/e2e_tests/test_crowdloan.py @@ -1,6 +1,5 @@ from bittensor import Balance from bittensor.core.extrinsics.pallets import SubtensorModule -from bittensor_wallet import Wallet import pytest import asyncio diff --git a/tests/e2e_tests/test_delegate.py b/tests/e2e_tests/test_delegate.py index d0a4a6fb95..07a4d67402 100644 --- a/tests/e2e_tests/test_delegate.py +++ b/tests/e2e_tests/test_delegate.py @@ -2,7 +2,6 @@ from bittensor.core.chain_data.chain_identity import ChainIdentity from bittensor.core.chain_data.delegate_info import DelegatedInfo, DelegateInfo -from bittensor.core.chain_data.proposal_vote_data import ProposalVoteData from bittensor.core.errors import ( DelegateTakeTooHigh, DelegateTxRateLimitExceeded, @@ -11,13 +10,9 @@ ) from bittensor.utils.balance import Balance from tests.e2e_tests.utils import ( - async_propose, async_set_identity, - async_vote, get_dynamic_balance, - propose, set_identity, - vote, TestSubnet, AdminUtils, ACTIVATE_SUBNET, @@ -26,7 +21,6 @@ SUDO_SET_NOMINATOR_MIN_REQUIRED_STAKE, SUDO_SET_TX_DELEGATE_TAKE_RATE_LIMIT, ) -from tests.helpers.helpers import CloseInValue DEFAULT_DELEGATE_TAKE = 0.179995422293431 diff --git a/tests/e2e_tests/test_incentive.py b/tests/e2e_tests/test_incentive.py index 64d5b97268..e02455e166 100644 --- a/tests/e2e_tests/test_incentive.py +++ b/tests/e2e_tests/test_incentive.py @@ -3,7 +3,6 @@ import pytest from bittensor.utils.balance import Balance -from bittensor.utils.btlogging import logging from tests.e2e_tests.utils import ( TestSubnet, AdminUtils, diff --git a/tests/e2e_tests/test_metagraph.py b/tests/e2e_tests/test_metagraph.py index 102899bae5..6606ec62c5 100644 --- a/tests/e2e_tests/test_metagraph.py +++ b/tests/e2e_tests/test_metagraph.py @@ -14,7 +14,6 @@ from bittensor.utils.balance import Balance from bittensor.utils.btlogging import logging from bittensor.utils.registration.pow import LazyLoadedTorch -from bittensor.utils.weight_utils import convert_and_normalize_weights_and_uids from tests.e2e_tests.utils import ( AdminUtils, NETUID, diff --git a/tests/e2e_tests/test_subnets.py b/tests/e2e_tests/test_subnets.py index 7079073d82..5368988946 100644 --- a/tests/e2e_tests/test_subnets.py +++ b/tests/e2e_tests/test_subnets.py @@ -1,5 +1,4 @@ import pytest -from bittensor.utils.btlogging import logging def test_subnets(subtensor, alice_wallet): diff --git a/tests/e2e_tests/test_transfer.py b/tests/e2e_tests/test_transfer.py index b6859238e2..136fb98bba 100644 --- a/tests/e2e_tests/test_transfer.py +++ b/tests/e2e_tests/test_transfer.py @@ -4,10 +4,9 @@ import pytest from bittensor.utils.balance import Balance -from bittensor import logging if typing.TYPE_CHECKING: - from bittensor.extras import SubtensorApi + pass def test_transfer(subtensor, alice_wallet): diff --git a/tests/e2e_tests/utils/e2e_test_utils.py b/tests/e2e_tests/utils/e2e_test_utils.py index dd31553524..2e7239bffe 100644 --- a/tests/e2e_tests/utils/e2e_test_utils.py +++ b/tests/e2e_tests/utils/e2e_test_utils.py @@ -6,7 +6,6 @@ from typing import Optional from bittensor_wallet import Keypair, Wallet -from bittensor.extras import SubtensorApi from bittensor.utils.btlogging import logging template_path = os.getcwd() + "/neurons/" diff --git a/tests/unit_tests/extrinsics/asyncex/test_coldkey_swap.py b/tests/unit_tests/extrinsics/asyncex/test_coldkey_swap.py index 0f969281bd..6611134d52 100644 --- a/tests/unit_tests/extrinsics/asyncex/test_coldkey_swap.py +++ b/tests/unit_tests/extrinsics/asyncex/test_coldkey_swap.py @@ -1,10 +1,7 @@ import pytest from bittensor_wallet import Wallet -from scalecodec.types import GenericCall from bittensor.core.extrinsics.asyncex import coldkey_swap -from bittensor.core.extrinsics.pallets import SubtensorModule -from bittensor.core.settings import DEFAULT_MEV_PROTECTION from bittensor.core.types import ExtrinsicResponse from bittensor.core.chain_data.coldkey_swap import ColdkeySwapAnnouncementInfo diff --git a/tests/unit_tests/extrinsics/asyncex/test_weights.py b/tests/unit_tests/extrinsics/asyncex/test_weights.py index 649dc79b15..c365bf4ed5 100644 --- a/tests/unit_tests/extrinsics/asyncex/test_weights.py +++ b/tests/unit_tests/extrinsics/asyncex/test_weights.py @@ -1,7 +1,6 @@ import pytest from bittensor.core.extrinsics.asyncex import weights as weights_module -from bittensor.core.settings import version_as_int from bittensor.core.types import ExtrinsicResponse diff --git a/tests/unit_tests/extrinsics/test_mev_shield.py b/tests/unit_tests/extrinsics/test_mev_shield.py index 2c0fba851b..549c3d55b9 100644 --- a/tests/unit_tests/extrinsics/test_mev_shield.py +++ b/tests/unit_tests/extrinsics/test_mev_shield.py @@ -1,4 +1,3 @@ -from bittensor_wallet import Wallet from scalecodec.types import GenericCall from async_substrate_interface import ExtrinsicReceipt from async_substrate_interface.errors import SubstrateRequestException diff --git a/tests/unit_tests/extrinsics/test_transfer.py b/tests/unit_tests/extrinsics/test_transfer.py index e6f560c388..4ddd3031bd 100644 --- a/tests/unit_tests/extrinsics/test_transfer.py +++ b/tests/unit_tests/extrinsics/test_transfer.py @@ -1,4 +1,3 @@ -import pytest from bittensor.core.extrinsics import transfer from bittensor.core.settings import DEFAULT_MEV_PROTECTION from bittensor.utils.balance import Balance diff --git a/tests/unit_tests/test_stream.py b/tests/unit_tests/test_stream.py index be333d59b3..b40a51b373 100644 --- a/tests/unit_tests/test_stream.py +++ b/tests/unit_tests/test_stream.py @@ -5,9 +5,7 @@ """ import pytest -from abc import ABC -from typing import Optional -from unittest.mock import AsyncMock, Mock, MagicMock, patch +from unittest.mock import AsyncMock, Mock from aiohttp import ClientResponse from starlette.types import Send, Receive, Scope