Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Flake8 #1701

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,51 @@ jobs:
#CI_JOB_ID: $CIRCLE_NODE_INDEX
#COVERALLS_PARALLEL: true

lint-and-type-check:
resource_class: medium
parallelism: 2
parameters:
python-version:
type: string
docker:
- image: cimg/python:<< parameters.python-version >>

steps:
- checkout

- restore_cache:
name: Restore cached venv
keys:
- v2-pypi-py<< parameters.python-version >>-{{ checksum "requirements/prod.txt" }}+{{ checksum "requirements/dev.txt" }}
- v2-pypi-py<< parameters.python-version >>

- run:
name: Update & Activate venv
command: |
python -m venv env/
. env/bin/activate
python -m pip install --upgrade pip
python -m pip install '.[dev]'
pip install flake8

- save_cache:
name: Save cached venv
paths:
- "env/"
key: v2-pypi-py<< parameters.python-version >>-{{ checksum "requirements/prod.txt" }}+{{ checksum "requirements/dev.txt" }}

- run:
name: Install Bittensor
command: |
. env/bin/activate
pip install -e '.[dev]'

- run:
name: Lint with flake8
command: |
. env/bin/activate
python -m flake8 bittensor/ --count

unit-tests-all-python-versions:
docker:
- image: cimg/python:3.10
Expand Down Expand Up @@ -251,6 +296,12 @@ workflows:
- unit-tests-all-python-versions:
requires:
- build-and-test
- lint-and-type-check:
matrix:
parameters:
python-version: ["3.8.12", "3.9.13", "3.10.6"]
requires:
- build-and-test
#- coveralls:
#requires:
#- build-and-test
Expand Down
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[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
6 changes: 2 additions & 4 deletions bittensor/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import copy
import json
import time
import base64
import asyncio
import inspect
import uvicorn
Expand All @@ -39,11 +38,10 @@
from fastapi.responses import JSONResponse
from substrateinterface import Keypair
from fastapi import FastAPI, APIRouter, Request, Response, Depends
from starlette.types import Scope, Message
from starlette.responses import Response
from starlette.requests import Request
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from typing import Dict, Optional, Tuple, Union, List, Callable, Any
from typing import Optional, Tuple, Callable, Any

from bittensor.errors import (
InvalidRequestNameError,
Expand Down Expand Up @@ -647,7 +645,7 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None):
parser.add_argument(
"--" + prefix_str + "axon.max_workers",
type=int,
help="""The maximum number connection handler threads working simultaneously on this endpoint.
help="""The maximum number connection handler threads working simultaneously on this endpoint.
The grpc server distributes new worker threads to service requests up to this number.""",
default=default_axon_max_workers,
)
Expand Down
2 changes: 1 addition & 1 deletion bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def to_parameter_dict(self) -> "torch.nn.ParameterDict":
@classmethod
def from_parameter_dict(
cls, parameter_dict: "torch.nn.ParameterDict"
) -> "axon_info":
) -> "AxonInfo":
r"""Returns an axon_info object from a torch parameter_dict."""
return cls(**dict(parameter_dict))

Expand Down
1 change: 0 additions & 1 deletion bittensor/commands/identity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
from rich import print
from rich.table import Table
from rich.prompt import Prompt
from sys import getsizeof
Expand Down
3 changes: 0 additions & 3 deletions bittensor/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,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 json
import argparse
import bittensor
from tqdm import tqdm
from rich.table import Table
from rich.prompt import Prompt
from .utils import (
check_netuid_set,
get_delegates_details,
DelegatesDetails,
get_hotkey_wallets_for_wallet,
get_coldkey_wallets_for_path,
get_all_wallets_for_path,
filter_netuids_by_registered_hotkeys,
)
Expand Down
1 change: 0 additions & 1 deletion bittensor/commands/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import argparse
import bittensor
from rich.prompt import Prompt
from rich.table import Table
from .utils import check_netuid_set

Expand Down
2 changes: 0 additions & 2 deletions bittensor/commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
# DEALINGS IN THE SOFTWARE.

import os
import sys
import argparse
import bittensor
from typing import List
from rich.prompt import Prompt
from rich.table import Table

Expand Down
1 change: 0 additions & 1 deletion bittensor/commands/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# 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 time
import argparse
import bittensor
from . import defaults
Expand Down
3 changes: 1 addition & 2 deletions bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
# 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 sys
import re
import torch
import typing
import argparse
import numpy as np
import bittensor
from typing import List, Optional, Dict
from rich.prompt import Prompt, Confirm
from rich.prompt import Prompt
from rich.table import Table
from .utils import get_delegates_details, DelegatesDetails

Expand Down
5 changes: 2 additions & 3 deletions bittensor/commands/senate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
# 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 sys

import argparse
import bittensor
from rich.prompt import Prompt, Confirm
from rich.table import Table
from rich.console import Console
from typing import List, Union, Optional, Dict, Tuple
from typing import Optional, Dict
from .utils import get_delegates_details, DelegatesDetails
from . import defaults

Expand Down
4 changes: 1 addition & 3 deletions bittensor/commands/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,13 @@ def add_args(cls, parser: argparse.ArgumentParser):


### Stake list.
import json
import argparse
import bittensor
from tqdm import tqdm
from rich.table import Table
from rich.prompt import Prompt
from typing import Dict, Union, List, Tuple
from concurrent.futures import ThreadPoolExecutor
from .utils import check_netuid_set, get_delegates_details, DelegatesDetails
from .utils import get_delegates_details, DelegatesDetails
from . import defaults

console = bittensor.__console__
Expand Down
2 changes: 1 addition & 1 deletion bittensor/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import torch
import bittensor
from typing import List, Dict, Any, Optional
from rich.prompt import Confirm, Prompt, PromptBase
from rich.prompt import Confirm, PromptBase
import requests
from dataclasses import dataclass
from . import defaults
Expand Down
4 changes: 2 additions & 2 deletions bittensor/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ async def forward(

async def query_all_axons(
is_stream: bool,
) -> Union[AsyncGenerator[Any], bittenst.Synapse, bittensor.StreamingSynapse]:
) -> Union[AsyncGenerator[Any], bittensor.Synapse, bittensor.StreamingSynapse]:
"""
Handles the processing of requests to all targeted axons, accommodating both streaming and non-streaming responses.

Expand All @@ -423,7 +423,7 @@ async def query_all_axons(
async def single_axon_response(
target_axon,
) -> Union[
AsyncGenerator[Any], bittenst.Synapse, bittensor.StreamingSynapse
AsyncGenerator[Any], bittensor.Synapse, bittensor.StreamingSynapse
]:
"""
Manages the request and response process for a single axon, supporting both streaming and non-streaming modes.
Expand Down
3 changes: 1 addition & 2 deletions bittensor/extrinsics/delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import bittensor
from ..errors import *
from rich.prompt import Confirm
from typing import List, Dict, Union, Optional
from typing import Union, Optional
from bittensor.utils.balance import Balance
from .staking import __do_add_stake_single

from loguru import logger

Expand Down
4 changes: 1 addition & 3 deletions bittensor/extrinsics/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# 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 json
import time
import bittensor
import bittensor.utils.networking as net
from dataclasses import asdict

from rich.prompt import Confirm


Expand Down
3 changes: 1 addition & 2 deletions bittensor/extrinsics/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import bittensor

import json
from rich.prompt import Confirm
import bittensor.utils.networking as net


Expand Down Expand Up @@ -75,7 +74,7 @@ def prometheus_extrinsic(
else:
external_ip = ip

call_params: "PrometheusServeCallParams" = {
call_params: "bittensor.PrometheusServeCallParams" = {
"version": bittensor.__version_as_int__,
"ip": net.ip_to_int(external_ip),
"port": port,
Expand Down
2 changes: 1 addition & 1 deletion bittensor/extrinsics/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import time
import torch
from rich.prompt import Confirm
from typing import Union, List
from typing import Union
import bittensor.utils.weight_utils as weight_utils

from loguru import logger
Expand Down
1 change: 0 additions & 1 deletion bittensor/extrinsics/senate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import time
from rich.prompt import Confirm
from ..errors import *


def register_senate_extrinsic(
Expand Down
3 changes: 1 addition & 2 deletions bittensor/extrinsics/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# DEALINGS IN THE SOFTWARE.
import json
import bittensor
from dataclasses import asdict
import bittensor.utils.networking as net
from rich.prompt import Confirm
from ..errors import MetadataError
Expand Down Expand Up @@ -65,7 +64,7 @@ def serve_extrinsic(
"""
# Decrypt hotkey
wallet.hotkey
params: "AxonServeCallParams" = {
params: "bittensor.AxonServeCallParams" = {
"version": bittensor.__version_as_int__,
"ip": net.ip_to_int(ip),
"port": port,
Expand Down
2 changes: 1 addition & 1 deletion bittensor/extrinsics/staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import bittensor
from rich.prompt import Confirm
from time import sleep
from typing import List, Dict, Union, Optional
from typing import List, Union, Optional
from bittensor.utils.balance import Balance


Expand Down
2 changes: 1 addition & 1 deletion bittensor/extrinsics/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import bittensor

from rich.prompt import Confirm
from typing import List, Dict, Union
from typing import Union
from ..utils.balance import Balance
from ..utils import is_valid_bittensor_address_or_public_key

Expand Down
2 changes: 1 addition & 1 deletion bittensor/extrinsics/unstaking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import bittensor
from rich.prompt import Confirm
from time import sleep
from typing import List, Dict, Union, Optional
from typing import List, Union, Optional
from bittensor.utils.balance import Balance


Expand Down
2 changes: 1 addition & 1 deletion bittensor/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from starlette.responses import StreamingResponse as _StreamingResponse
from starlette.responses import Response
from starlette.types import Send, Receive, Scope
from typing import Callable, Awaitable, List
from typing import Callable, Awaitable
from pydantic import BaseModel
from abc import ABC, abstractmethod

Expand Down
3 changes: 1 addition & 2 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
NeuronInfoLite,
AxonInfo,
ProposalVoteData,
ProposalCallData,
IPInfo,
custom_rpc_type_registry,
)
Expand All @@ -65,7 +64,7 @@
swap_hotkey_extrinsic,
)
from .extrinsics.transfer import transfer_extrinsic
from .extrinsics.set_weights import set_weights_extrinsic, ttl_set_weights_extrinsic
from .extrinsics.set_weights import ttl_set_weights_extrinsic
from .extrinsics.prometheus import prometheus_extrinsic
from .extrinsics.delegation import (
delegate_extrinsic,
Expand Down
13 changes: 4 additions & 9 deletions bittensor/synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
# 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 ast
import sys
import torch
import json

import base64
import typing
import hashlib
import json
import sys

import pydantic
from pydantic.schema import schema
import bittensor
Expand Down Expand Up @@ -625,9 +623,6 @@ def to_headers(self) -> dict:
}
)

# Getting the type hints for the properties of the instance
property_type_hints = typing.get_type_hints(self)

# Getting the fields of the instance
instance_fields = self.dict()

Expand Down
Loading