Skip to content

Commit

Permalink
Merge pull request #1968 from backend-developers-ltd/ruff
Browse files Browse the repository at this point in the history
replace `black` with `ruff`
  • Loading branch information
gus-opentensor authored Jun 3, 2024
2 parents 0cf372e + ae964d2 commit 28b9039
Show file tree
Hide file tree
Showing 31 changed files with 152 additions and 181 deletions.
52 changes: 26 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ orbs:
# coveralls: coveralls/[email protected]

jobs:
black:
ruff:
resource_class: small
parameters:
python-version:
Expand All @@ -18,29 +18,29 @@ jobs:
- checkout

- restore_cache:
name: Restore cached black venv
name: Restore cached ruff venv
keys:
- v2-pypi-py-black-<< parameters.python-version >>
- v2-pypi-py-ruff-<< parameters.python-version >>

- run:
name: Update & Activate black venv
name: Update & Activate ruff venv
command: |
python -m venv env/
. env/bin/activate
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
pip install black==23.7.0
pip install ruff -c requirements/dev.txt
- save_cache:
name: Save cached black venv
name: Save cached ruff venv
paths:
- "env/"
key: v2-pypi-py-black-<< parameters.python-version >>
- ".venv/"
key: v2-pypi-py-ruff-<< parameters.python-version >>

- run:
name: Black format check
name: Ruff format check
command: |
. env/bin/activate
python -m black --exclude '(env|venv|.eggs)' --check .
. .venv/bin/activate
ruff format --diff .
check_compatibility:
parameters:
Expand Down Expand Up @@ -85,8 +85,8 @@ jobs:
- run:
name: Update & Activate venv
command: |
python -m venv env/
. env/bin/activate
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install '.[dev]'
Expand All @@ -99,20 +99,20 @@ jobs:
- run:
name: Install Bittensor
command: |
. env/bin/activate
. .venv/bin/activate
pip install -e '.[dev]'
- run:
name: Instantiate Mock Wallet
command: |
. env/bin/activate
. .venv/bin/activate
./scripts/create_wallet.sh
# TODO: Update test durations on different runs
- run:
name: Unit Tests
command: |
. env/bin/activate
. .venv/bin/activate
export PYTHONUNBUFFERED=1
pytest -n2 --reruns 3 --durations=0 --verbose --junitxml=test-results/unit_tests.xml \
--cov=. --cov-append --cov-config .coveragerc \
Expand All @@ -123,7 +123,7 @@ jobs:
- run:
name: Integration Tests
command: |
. env/bin/activate
. .venv/bin/activate
export PYTHONUNBUFFERED=1
pytest -n2 --reruns 3 --reruns-delay 15 --durations=0 --verbose --junitxml=test-results/integration_tests.xml \
--cov=. --cov-append --cov-config .coveragerc \
Expand All @@ -143,7 +143,7 @@ jobs:
#- run:
#name: Upload Coverage
#command: |
#. env/bin/activate && coveralls
#. .venv/bin/activate && coveralls
#env:
#CI_NAME: circleci
#CI_BUILD_NUMBER: $CIRCLE_BUILD_NUM
Expand Down Expand Up @@ -173,8 +173,8 @@ jobs:
- run:
name: Update & Activate venv
command: |
python -m venv env/
. env/bin/activate
python -m venv .venv
. .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install '.[dev]'
pip install flake8
Expand All @@ -188,19 +188,19 @@ jobs:
- run:
name: Install Bittensor
command: |
. env/bin/activate
. .venv/bin/activate
pip install -e '.[dev]'
- run:
name: Lint with flake8
command: |
. env/bin/activate
. .venv/bin/activate
python -m flake8 bittensor/ --count
- run:
name: Type check with mypy
command: |
. env/bin/activate
. .venv/bin/activate
python -m mypy --ignore-missing-imports bittensor/
unit-tests-all-python-versions:
Expand Down Expand Up @@ -290,7 +290,7 @@ workflows:

pr-requirements:
jobs:
- black:
- ruff:
python-version: "3.9.13"
- build-and-test:
matrix:
Expand Down
3 changes: 1 addition & 2 deletions bittensor/axon.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Create and initialize Axon, which services the forward and backward requests from other neurons.
"""
"""Create and initialize Axon, which services the forward and backward requests from other neurons."""

# The MIT License (MIT)
# Copyright © 2021 Yuma Rao
Expand Down
8 changes: 4 additions & 4 deletions bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,10 @@ def list_of_tuple_from_vec_u8(
cls, vec_u8: List[int]
) -> Dict[str, List["StakeInfo"]]:
"""Returns a list of StakeInfo objects from a ``vec_u8``."""
decoded: Optional[
list[tuple[str, list[object]]]
] = from_scale_encoding_using_type_string(
input_=vec_u8, type_string="Vec<(AccountId, Vec<StakeInfo>)>"
decoded: Optional[list[tuple[str, list[object]]]] = (
from_scale_encoding_using_type_string(
input_=vec_u8, type_string="Vec<(AccountId, Vec<StakeInfo>)>"
)
)

if decoded is None:
Expand Down
32 changes: 16 additions & 16 deletions bittensor/commands/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def show_delegates_lite(
the table in the console.
"""

registered_delegate_info: Optional[
Dict[str, DelegatesDetails]
] = get_delegates_details(url=bittensor.__delegates_details_url__)
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
get_delegates_details(url=bittensor.__delegates_details_url__)
)
if registered_delegate_info is None:
bittensor.__console__.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
Expand Down Expand Up @@ -206,9 +206,9 @@ def show_delegates(
for prev_delegate in prev_delegates:
prev_delegates_dict[prev_delegate.hotkey_ss58] = prev_delegate

registered_delegate_info: Optional[
Dict[str, DelegatesDetails]
] = get_delegates_details(url=bittensor.__delegates_details_url__)
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
get_delegates_details(url=bittensor.__delegates_details_url__)
)
if registered_delegate_info is None:
bittensor.__console__.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
Expand Down Expand Up @@ -238,10 +238,10 @@ def show_delegates(
"[overline white]NOMINATORS", justify="center", style="green", no_wrap=True
)
table.add_column(
"[overline white]DELEGATE STAKE(\u03C4)", justify="right", no_wrap=True
"[overline white]DELEGATE STAKE(\u03c4)", justify="right", no_wrap=True
)
table.add_column(
"[overline white]TOTAL STAKE(\u03C4)",
"[overline white]TOTAL STAKE(\u03c4)",
justify="right",
style="green",
no_wrap=True,
Expand All @@ -250,7 +250,7 @@ def show_delegates(
table.add_column("[overline white]VPERMIT", justify="right", no_wrap=False)
table.add_column("[overline white]TAKE", style="white", no_wrap=True)
table.add_column(
"[overline white]NOMINATOR/(24h)/k\u03C4", style="green", justify="center"
"[overline white]NOMINATOR/(24h)/k\u03c4", style="green", justify="center"
)
table.add_column("[overline white]DELEGATE/(24h)", style="green", justify="center")
table.add_column("[overline white]Desc", style="rgb(50,163,219)")
Expand Down Expand Up @@ -980,18 +980,18 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
style="bold green",
)
table.add_column(
"[overline green]\u03C4/24h",
"[overline green]\u03c4/24h",
footer_style="overline green",
style="bold green",
)
table.add_column(
"[overline white]NOMS", justify="center", style="green", no_wrap=True
)
table.add_column(
"[overline white]OWNER STAKE(\u03C4)", justify="right", no_wrap=True
"[overline white]OWNER STAKE(\u03c4)", justify="right", no_wrap=True
)
table.add_column(
"[overline white]TOTAL STAKE(\u03C4)",
"[overline white]TOTAL STAKE(\u03c4)",
justify="right",
style="green",
no_wrap=True,
Expand All @@ -1000,7 +1000,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
"[overline white]SUBNETS", justify="right", style="white", no_wrap=True
)
table.add_column("[overline white]VPERMIT", justify="right", no_wrap=True)
table.add_column("[overline white]24h/k\u03C4", style="green", justify="center")
table.add_column("[overline white]24h/k\u03c4", style="green", justify="center")
table.add_column("[overline white]Desc", style="rgb(50,163,219)")
total_delegated = 0

Expand All @@ -1023,9 +1023,9 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
delegates.sort(key=lambda delegate: delegate[0].total_stake, reverse=True)
total_delegated += sum(my_delegates.values())

registered_delegate_info: Optional[
DelegatesDetails
] = get_delegates_details(url=bittensor.__delegates_details_url__)
registered_delegate_info: Optional[DelegatesDetails] = (
get_delegates_details(url=bittensor.__delegates_details_url__)
)
if registered_delegate_info is None:
bittensor.__console__.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
Expand Down
12 changes: 6 additions & 6 deletions bittensor/commands/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
)
bittensor.logging.debug(f"Netuids to check: {netuids}")

registered_delegate_info: Optional[
Dict[str, DelegatesDetails]
] = get_delegates_details(url=bittensor.__delegates_details_url__)
registered_delegate_info: Optional[Dict[str, DelegatesDetails]] = (
get_delegates_details(url=bittensor.__delegates_details_url__)
)
if registered_delegate_info is None:
bittensor.__console__.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
Expand Down Expand Up @@ -181,9 +181,9 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
"[overline white]Emission", footer_style="overline white", style="green"
)
for wallet in tqdm(wallets):
delegates: List[
Tuple[bittensor.DelegateInfo, bittensor.Balance]
] = subtensor.get_delegated(coldkey_ss58=wallet.coldkeypub.ss58_address)
delegates: List[Tuple[bittensor.DelegateInfo, bittensor.Balance]] = (
subtensor.get_delegated(coldkey_ss58=wallet.coldkeypub.ss58_address)
)
if not wallet.coldkeypub_file.exists_on_device():
continue
cold_balance = subtensor.get_balance(wallet.coldkeypub.ss58_address)
Expand Down
8 changes: 4 additions & 4 deletions bittensor/commands/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
style="yellow",
)
table.add_column(
"[overline white]STAKE(\u03C4)",
"\u03C4{:.5f}".format(total_stake),
"[overline white]STAKE(\u03c4)",
"\u03c4{:.5f}".format(total_stake),
footer_style="overline white",
justify="right",
style="green",
Expand Down Expand Up @@ -207,8 +207,8 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
no_wrap=True,
)
table.add_column(
"[overline white]EMISSION(\u03C1)",
"\u03C1{}".format(int(total_emission)),
"[overline white]EMISSION(\u03c1)",
"\u03c1{}".format(int(total_emission)),
footer_style="overline white",
justify="right",
style="green",
Expand Down
20 changes: 10 additions & 10 deletions bittensor/commands/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
for neuron in neuron_list:
if neuron.hotkey in checked_hotkeys:
continue
total_coldkey_stake_from_metagraph[
neuron.coldkey
] += neuron.stake_dict[neuron.coldkey]
total_coldkey_stake_from_metagraph[neuron.coldkey] += (
neuron.stake_dict[neuron.coldkey]
)
checked_hotkeys.add(neuron.hotkey)

alerts_table = Table(show_header=True, header_style="bold magenta")
Expand Down Expand Up @@ -483,8 +483,8 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
)
if last_subnet:
table.add_column(
"[overline white]STAKE(\u03C4)",
"\u03C4{:.5f}".format(total_stake),
"[overline white]STAKE(\u03c4)",
"\u03c4{:.5f}".format(total_stake),
footer_style="overline white",
justify="right",
style="green",
Expand All @@ -493,7 +493,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
else:
# No footer for non-last subnet.
table.add_column(
"[overline white]STAKE(\u03C4)",
"[overline white]STAKE(\u03c4)",
justify="right",
style="green",
no_wrap=True,
Expand Down Expand Up @@ -539,8 +539,8 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
no_wrap=True,
)
table.add_column(
"[overline white]EMISSION(\u03C1)",
"\u03C1{:_}".format(total_emission),
"[overline white]EMISSION(\u03c1)",
"\u03c1{:_}".format(total_emission),
footer_style="overline white",
justify="right",
style="green",
Expand Down Expand Up @@ -603,7 +603,7 @@ def overview_sort_function(row):

console.clear()

caption = "[italic][dim][white]Wallet balance: [green]\u03C4" + str(
caption = "[italic][dim][white]Wallet balance: [green]\u03c4" + str(
total_balance.tao
)
grid.add_row(Align(caption, vertical="middle", align="center"))
Expand All @@ -613,7 +613,7 @@ def overview_sort_function(row):

@staticmethod
def _get_neurons_for_netuid(
args_tuple: Tuple["bittensor.Config", int, List[str]]
args_tuple: Tuple["bittensor.Config", int, List[str]],
) -> Tuple[int, List["bittensor.NeuronInfoLite"], Optional[str]]:
subtensor_config, netuid, hot_wallets = args_tuple

Expand Down
2 changes: 1 addition & 1 deletion bittensor/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _run(cli: "bittensor.cli", subtensor: "bittensor.subtensor"):
no_wrap=True,
)
table.add_column(
"[overline white]STAKE(\u03C4)",
"[overline white]STAKE(\u03c4)",
footer_style="overline white",
justify="right",
style="green",
Expand Down
Loading

0 comments on commit 28b9039

Please sign in to comment.