Skip to content
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
42 changes: 42 additions & 0 deletions .github/workflows/ruff-formatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Ruff Formatter Check
permissions:
contents: read

on:
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
ruff:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9.13"]
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Set up caching for Ruff virtual environment
id: cache-ruff
uses: actions/cache@v4
with:
path: .venv
key: v2-pypi-py-ruff-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
v2-pypi-py-ruff-${{ matrix.python-version }}-

- name: Set up Ruff virtual environment if cache is missed
if: steps.cache-ruff.outputs.cache-hit != 'true'
run: |
python -m venv .venv
.venv/bin/python -m pip install ruff==0.11.5

- name: Ruff format check
run: |
.venv/bin/ruff format --diff bittensor_cli
.venv/bin/ruff format --diff tests
8 changes: 2 additions & 6 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,11 +840,7 @@ def update_metadata_table(table_name: str, values: dict[str, str]) -> None:
"""
with DB() as (conn, cursor):
cursor.execute(
"CREATE TABLE IF NOT EXISTS metadata ("
"TableName TEXT, "
"Key TEXT, "
"Value TEXT"
")"
"CREATE TABLE IF NOT EXISTS metadata (TableName TEXT, Key TEXT, Value TEXT)"
)
conn.commit()
for key, value in values.items():
Expand Down Expand Up @@ -1311,7 +1307,7 @@ def validate_rate_tolerance(value: Optional[float]) -> Optional[float]:
raise typer.BadParameter("Rate tolerance cannot be greater than 1 (100%).")
if value > 0.5:
console.print(
f"[yellow]Warning: High rate tolerance of {value*100}% specified. "
f"[yellow]Warning: High rate tolerance of {value * 100}% specified. "
"This may result in unfavorable transaction execution.[/yellow]"
)
return value
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/commands/stake/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def _define_stake_table(

if safe_staking:
table.add_column(
f"Rate with tolerance: [blue]({rate_tolerance*100}%)[/blue]",
f"Rate with tolerance: [blue]({rate_tolerance * 100}%)[/blue]",
justify="center",
style=COLOR_PALETTE["POOLS"]["RATE"],
)
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/commands/stake/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ def _create_unstake_table(
)
if safe_staking:
table.add_column(
f"Rate with tolerance: [blue]({rate_tolerance*100}%)[/blue]",
f"Rate with tolerance: [blue]({rate_tolerance * 100}%)[/blue]",
justify="center",
style=COLOR_PALETTE["POOLS"]["RATE"],
)
Expand Down
16 changes: 10 additions & 6 deletions bittensor_cli/src/commands/sudo.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ async def set_take_extrinsic(

if current_take_u16 < take_u16:
console.print(
f"Current take is [{COLOR_PALETTE['POOLS']['RATE']}]{current_take * 100.:.2f}%[/{COLOR_PALETTE['POOLS']['RATE']}]. Increasing to [{COLOR_PALETTE['POOLS']['RATE']}]{take * 100:.2f}%."
f"Current take is [{COLOR_PALETTE.P.RATE}]{current_take * 100.0:.2f}%[/{COLOR_PALETTE.P.RATE}]. "
f"Increasing to [{COLOR_PALETTE.P.RATE}]{take * 100:.2f}%."
)
with console.status(
f":satellite: Sending decrease_take_extrinsic call on [white]{subtensor}[/white] ..."
Expand All @@ -542,7 +543,8 @@ async def set_take_extrinsic(

else:
console.print(
f"Current take is [{COLOR_PALETTE['POOLS']['RATE']}]{current_take * 100.:.2f}%[/{COLOR_PALETTE['POOLS']['RATE']}]. Decreasing to [{COLOR_PALETTE['POOLS']['RATE']}]{take * 100:.2f}%."
f"Current take is [{COLOR_PALETTE.P.RATE}]{current_take * 100.0:.2f}%[/{COLOR_PALETTE.P.RATE}]. "
f"Decreasing to [{COLOR_PALETTE.P.RATE}]{take * 100:.2f}%."
)
with console.status(
f":satellite: Sending increase_take_extrinsic call on [white]{subtensor}[/white] ..."
Expand Down Expand Up @@ -871,7 +873,7 @@ async def get_current_take(subtensor: "SubtensorInterface", wallet: Wallet):
async def display_current_take(subtensor: "SubtensorInterface", wallet: Wallet) -> None:
current_take = await get_current_take(subtensor, wallet)
console.print(
f"Current take is [{COLOR_PALETTE['POOLS']['RATE']}]{current_take * 100.:.2f}%"
f"Current take is [{COLOR_PALETTE.P.RATE}]{current_take * 100.0:.2f}%"
)


Expand All @@ -891,7 +893,9 @@ async def _do_set_take() -> bool:
)
if not len(netuids_registered) > 0:
err_console.print(
f"Hotkey [{COLOR_PALETTE['GENERAL']['HOTKEY']}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE['GENERAL']['HOTKEY']}] is not registered to any subnet. Please register using [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]`btcli subnets register`[{COLOR_PALETTE['GENERAL']['SUBHEADING']}] and try again."
f"Hotkey [{COLOR_PALETTE.G.HK}]{wallet.hotkey.ss58_address}[/{COLOR_PALETTE.G.HK}] is not registered to"
f" any subnet. Please register using [{COLOR_PALETTE.G.SUBHEAD}]`btcli subnets register`"
f"[{COLOR_PALETTE.G.SUBHEAD}] and try again."
)
return False

Expand All @@ -908,12 +912,12 @@ async def _do_set_take() -> bool:
else:
new_take = await get_current_take(subtensor, wallet)
console.print(
f"New take is [{COLOR_PALETTE['POOLS']['RATE']}]{new_take * 100.:.2f}%"
f"New take is [{COLOR_PALETTE.P.RATE}]{new_take * 100.0:.2f}%"
)
return True

console.print(
f"Setting take on [{COLOR_PALETTE['GENERAL']['LINKS']}]network: {subtensor.network}"
f"Setting take on [{COLOR_PALETTE.G.LINKS}]network: {subtensor.network}"
)

if not unlock_key(wallet, "hot").success and unlock_key(wallet, "cold").success:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ cuda = [
dev = [
"pytest",
"pytest-asyncio",
"ruff==0.11.5",
]

[project.urls]
Expand Down
36 changes: 18 additions & 18 deletions tests/e2e_tests/test_wallet_creations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ def verify_key_pattern(output: str, wallet_name: str) -> Optional[str]:
match = re.search(pattern, line)
if match:
# Assert key starts with '5'
assert match.group(1).startswith(
"5"
), f"{wallet_name} should start with '5'"
assert match.group(1).startswith("5"), (
f"{wallet_name} should start with '5'"
)
# Assert length of key is 48 characters
assert (
len(match.group(1)) == 48
), f"Key for {wallet_name} should be 48 characters long"
assert len(match.group(1)) == 48, (
f"Key for {wallet_name} should be 48 characters long"
)
found = True
return match.group(1)

Expand Down Expand Up @@ -441,9 +441,9 @@ def test_wallet_regen(wallet_setup, capfd):

new_coldkey_mod_time = os.path.getmtime(coldkey_path)

assert (
initial_coldkey_mod_time != new_coldkey_mod_time
), "Coldkey file was not regenerated as expected"
assert initial_coldkey_mod_time != new_coldkey_mod_time, (
"Coldkey file was not regenerated as expected"
)
json_result = exec_command(
command="wallet",
sub_command="regen-coldkey",
Expand Down Expand Up @@ -502,9 +502,9 @@ def test_wallet_regen(wallet_setup, capfd):

new_coldkeypub_mod_time = os.path.getmtime(coldkeypub_path)

assert (
initial_coldkeypub_mod_time != new_coldkeypub_mod_time
), "Coldkeypub file was not regenerated as expected"
assert initial_coldkeypub_mod_time != new_coldkeypub_mod_time, (
"Coldkeypub file was not regenerated as expected"
)
print("Passed wallet regen_coldkeypub command ✅")

# -----------------------------
Expand Down Expand Up @@ -537,9 +537,9 @@ def test_wallet_regen(wallet_setup, capfd):

new_hotkey_mod_time = os.path.getmtime(hotkey_path)

assert (
initial_hotkey_mod_time != new_hotkey_mod_time
), "Hotkey file was not regenerated as expected"
assert initial_hotkey_mod_time != new_hotkey_mod_time, (
"Hotkey file was not regenerated as expected"
)
print("Passed wallet regen_hotkey command ✅")


Expand Down Expand Up @@ -593,9 +593,9 @@ def test_wallet_balance_all(local_chain, wallet_setup, capfd):
output = result.stdout

for wallet_name in wallet_names:
assert (
wallet_name in output
), f"Wallet {wallet_name} not found in balance --all output"
assert wallet_name in output, (
f"Wallet {wallet_name} not found in balance --all output"
)

json_results = exec_command(
"wallet",
Expand Down
Loading