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

(Mostly) Replace flake8 with Ruff #18801

Merged
merged 6 commits into from
Nov 1, 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
8 changes: 1 addition & 7 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[flake8]
max-line-length = 120
exclude = ./typings/**/*
ignore = E203,W503
extend-ignore = E226,E704,E701
per-file-ignores =
chia/_tests/util/build_network_protocol_files.py:F405
chia/_tests/util/test_network_protocol_files.py:F405
chia/_tests/util/test_network_protocol_json.py:F405
chia/_tests/util/protocol_messages_json.py:E501
select = F841
2 changes: 1 addition & 1 deletion benchmarks/block_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def main(db_path: Path) -> None:
timing += one_call
assert gen is not None

print(f"get_block_generator(): {timing/REPETITIONS:0.3f}s")
print(f"get_block_generator(): {timing / REPETITIONS:0.3f}s")

blockchain.shut_down()

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/block_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ async def run_add_block_benchmark(version: int) -> None:
print(f"all tests completed in {all_test_time:0.4f}s")

db_size = os.path.getsize(Path("block-store-benchmark.db"))
print(f"database size: {db_size/1000000:.3f} MB")
print(f"database size: {db_size / 1000000:.3f} MB")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/coin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ async def run_new_block_benchmark(version: int) -> None:
if verbose:
print("")
print(
f"{total_time:0.4f}s, GET COINS REMOVED AT HEIGHT {block_height-1} blocks, "
f"{total_time:0.4f}s, GET COINS REMOVED AT HEIGHT {block_height - 1} blocks, "
f"found {found_coins} coins in total"
)
all_test_time += total_time
print(f"all tests completed in {all_test_time:0.4f}s")

db_size = os.path.getsize(Path("coin-store-benchmark.db"))
print(f"database size: {db_size/1000000:.3f} MB")
print(f"database size: {db_size / 1000000:.3f} MB")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions chia/_tests/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,8 +1850,8 @@ async def test_pre_validation(
)
end = time.time()
log.info(f"Total time: {end - start} seconds")
log.info(f"Average pv: {sum(times_pv)/(len(blocks)/n_at_a_time)}")
log.info(f"Average rb: {sum(times_rb)/(len(blocks))}")
log.info(f"Average pv: {sum(times_pv) / (len(blocks) / n_at_a_time)}")
log.info(f"Average rb: {sum(times_rb) / (len(blocks))}")


class TestBodyValidation:
Expand Down
12 changes: 1 addition & 11 deletions chia/_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# flake8: noqa E402 # See imports after multiprocessing.set_start_method
# ruff: noqa: E402 # See imports after multiprocessing.set_start_method
from __future__ import annotations

import asyncio
import dataclasses
import datetime
import functools
import json
Expand All @@ -24,7 +23,6 @@
from _pytest.fixtures import SubRequest
from pytest import MonkeyPatch

import chia._tests
from chia._tests import ether
from chia._tests.core.data_layer.util import ChiaRoot
from chia._tests.core.node_height import node_height_at_least
Expand All @@ -50,13 +48,10 @@
from chia._tests.util.spend_sim import CostLogger
from chia._tests.util.time_out_assert import time_out_assert
from chia.consensus.constants import ConsensusConstants
from chia.full_node.full_node import FullNode
from chia.full_node.full_node_api import FullNodeAPI
from chia.rpc.farmer_rpc_client import FarmerRpcClient
from chia.rpc.harvester_rpc_client import HarvesterRpcClient
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.seeder.crawler import Crawler
from chia.seeder.crawler_api import CrawlerAPI
from chia.seeder.dns_server import DNSServer
from chia.server.server import ChiaServer
from chia.server.start_service import Service
Expand All @@ -71,13 +66,10 @@
)
from chia.simulator.start_simulator import SimulatorFullNodeService
from chia.simulator.wallet_tools import WalletTool
from chia.timelord.timelord import Timelord
from chia.timelord.timelord_api import TimelordAPI

# Set spawn after stdlib imports, but before other imports
from chia.types.aliases import (
CrawlerService,
DataLayerService,
FarmerService,
FullNodeService,
HarvesterService,
Expand All @@ -92,7 +84,6 @@
from chia.util.task_timing import main as task_instrumentation_main
from chia.util.task_timing import start_task_instrumentation, stop_task_instrumentation
from chia.wallet.wallet_node import WalletNode
from chia.wallet.wallet_node_api import WalletNodeAPI

multiprocessing.set_start_method("spawn")

Expand Down Expand Up @@ -639,7 +630,6 @@ async def five_nodes(db_version: int, self_hostname, blockchain_constants):

@pytest.fixture(scope="function")
async def wallet_nodes(blockchain_constants, consensus_mode):
constants = blockchain_constants
async with setup_simulators_and_wallets(
2,
1,
Expand Down
4 changes: 0 additions & 4 deletions chia/_tests/core/full_node/full_sync/test_full_sync.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# flake8: noqa: F811, F401
from __future__ import annotations

import asyncio
import dataclasses
import logging
import time

import pytest

from chia._tests.conftest import ConsensusMode
from chia._tests.core.node_height import node_height_between, node_height_exactly
from chia._tests.util.time_out_assert import time_out_assert
from chia.full_node.full_node import FullNode
Expand Down Expand Up @@ -116,7 +113,6 @@ async def test_long_sync_from_zero(self, five_nodes, default_400_blocks, bt, sel
async def test_sync_from_fork_point_and_weight_proof(
self, three_nodes, default_1000_blocks, default_400_blocks, self_hostname
):
start = time.time()
# Must be larger than "sync_block_behind_threshold" in the config
num_blocks_initial = len(default_1000_blocks) - 50
blocks_950 = default_1000_blocks[:num_blocks_initial]
Expand Down
2 changes: 0 additions & 2 deletions chia/_tests/core/full_node/test_performance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# flake8: noqa: F811, F401
from __future__ import annotations

import dataclasses
import logging
import random

Expand Down
1 change: 0 additions & 1 deletion chia/_tests/core/server/test_dos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: F811, F401
from __future__ import annotations

import asyncio
Expand Down
6 changes: 2 additions & 4 deletions chia/_tests/core/test_full_node_rpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: F811, F401
from __future__ import annotations

import pytest
Expand All @@ -7,7 +6,6 @@

from chia import __version__
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
from chia._tests.conftest import ConsensusMode
from chia._tests.connection_utils import connect_and_get_peer
from chia._tests.util.rpc import validate_get_routes
from chia._tests.util.time_out_assert import time_out_assert
Expand Down Expand Up @@ -713,7 +711,7 @@ async def test_coin_name_not_found_in_mempool(one_node, self_hostname):

empty_coin_name = bytes32.zeros
mempool_item = await client.get_mempool_items_by_coin_name(empty_coin_name)
assert mempool_item["success"] == True
assert mempool_item["success"]
assert "mempool_items" in mempool_item
assert len(mempool_item["mempool_items"]) == 0
finally:
Expand Down Expand Up @@ -780,7 +778,7 @@ async def test_coin_name_found_in_mempool(one_node, self_hostname):
mempool_item = await client.get_mempool_items_by_coin_name(coin_to_spend.name())

# found coin in coin spends
assert mempool_item["success"] == True
assert mempool_item["success"]
assert "mempool_items" in mempool_item
assert len(mempool_item["mempool_items"]) > 0
for item in mempool_item["mempool_items"]:
Expand Down
21 changes: 2 additions & 19 deletions chia/_tests/generator/test_compression.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
# flake8: noqa: F501
# ruff: noqa: E501
from __future__ import annotations

import io
from dataclasses import dataclass
from typing import Any

import pytest
from chia_rs import ALLOW_BACKREFS
from chia_rs import serialized_length
from clvm.serialize import sexp_from_stream
from clvm.SExp import SExp
from clvm_tools import binutils

from chia._tests.core.make_block_generator import make_spend_bundle
from chia._tests.generator.test_rom import run_generator
from chia.full_node.bundle_tools import simple_solution_generator, simple_solution_generator_backrefs
from chia.full_node.mempool_check_conditions import get_puzzle_and_solution_for_coin
from chia.simulator.block_tools import test_constants
from chia.types.blockchain_format.program import INFINITE_COST, Program
from chia.types.blockchain_format.serialized_program import SerializedProgram
from chia.types.generator_types import BlockGenerator
from chia.types.spend_bundle import SpendBundle
from chia.util.byte_types import hexstr_to_bytes
from chia.util.ints import uint32
Expand Down Expand Up @@ -51,8 +42,6 @@
FAKE_BLOCK_HEIGHT1 = uint32(100)
FAKE_BLOCK_HEIGHT2 = uint32(200)

from chia_rs import serialized_length

assert serialized_length(original_generator) == len(original_generator)
assert serialized_length(gen1) == len(gen1)
assert serialized_length(gen2) == len(gen2)
Expand Down Expand Up @@ -135,9 +124,6 @@ def test_decompress_cse_with_prefix(self) -> None:

def test_block_program_zero(self) -> None:
"Decompress a list of CSEs"
cse1 = binutils.assemble(
"(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
)
cse2 = binutils.assemble(
"""
(
Expand Down Expand Up @@ -176,9 +162,6 @@ def test_block_program_zero(self) -> None:
print(out)

def test_block_program_zero_with_curry(self) -> None:
cse1 = binutils.assemble(
"(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
)
cse2 = binutils.assemble(
"""
(
Expand Down
5 changes: 1 addition & 4 deletions chia/_tests/pools/test_pool_cmdline.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# flake8: noqa: E501

from __future__ import annotations

import click
import pytest
from click.testing import CliRunner, Result
from click.testing import CliRunner

from chia.cmds.plotnft import create_cmd, show_cmd

Expand Down
8 changes: 3 additions & 5 deletions chia/_tests/pools/test_pool_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# flake8: noqa: E501
from __future__ import annotations

from chia_rs import AugSchemeMPL, PrivateKey

from chia.pools.pool_config import PoolWalletConfig
from chia.util.config import create_default_chia_config, load_config, lock_config, save_config

Expand All @@ -18,9 +15,10 @@ def test_pool_config(tmp_path):
eg_config.rename(to_config)
config = load_config(test_root, "test_pool_config.yaml")

auth_sk: PrivateKey = AugSchemeMPL.key_gen(b"1" * 32)
d = {
"owner_public_key": "84c3fcf9d5581c1ddc702cb0f3b4a06043303b334dd993ab42b2c320ebfa98e5ce558448615b3f69638ba92cf7f43da5",
"owner_public_key": (
"84c3fcf9d5581c1ddc702cb0f3b4a06043303b334dd993ab42b2c320ebfa98e5ce558448615b3f69638ba92cf7f43da5"
),
"p2_singleton_puzzle_hash": "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824",
"payout_instructions": "c2b08e41d766da4116e388357ed957d04ad754623a915f3fd65188a8746cf3e8",
"pool_url": "localhost",
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/util/benchmark_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ def benchmark_all_operators():
constant = clvm_should_cost / clvm_cost
format = float_to_str(constant)
print(f"Constant factor: {format}")
print(f"CLVM RATIO MULTIPLIER: {1/constant}")
print(f"CLVM RATIO MULTIPLIER: {1 / constant}")
10 changes: 7 additions & 3 deletions chia/_tests/util/build_network_protocol_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F405
from __future__ import annotations

import os
Expand Down Expand Up @@ -183,7 +184,8 @@ def visitor(obj: Any, name: str) -> None:


def build_protocol_test() -> str:
result = """# this file is generated by build_network_protocol_files.py
result = """# ruff: noqa: F405
# this file is generated by build_network_protocol_files.py

from __future__ import annotations

Expand Down Expand Up @@ -232,7 +234,8 @@ def visitor(obj: Any, name: str) -> None:


def get_protocol_json() -> str:
result = """# this file is generated by build_network_protocol_files.py
result = """# ruff: noqa: E501
# this file is generated by build_network_protocol_files.py
from __future__ import annotations

from typing import Any
Expand All @@ -251,7 +254,8 @@ def visitor(obj: Any, name: str) -> None:


def build_json_test() -> str:
result = """# this file is generated by build_network_protocol_files.py
result = """# ruff: noqa: F405
# this file is generated by build_network_protocol_files.py

from __future__ import annotations

Expand Down
16 changes: 7 additions & 9 deletions chia/_tests/util/network_protocol_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# flake8: noqa

from __future__ import annotations

from chia_rs import G1Element, G2Element, RewardChainBlockUnfinished
Expand Down Expand Up @@ -46,7 +44,7 @@
error_with_data = Error(int16(Err.UNKNOWN.value), "Unknown", b"extra data")


### FARMER PROTOCOL
# FARMER PROTOCOL
new_signage_point = farmer_protocol.NewSignagePoint(
bytes32(bytes.fromhex("34b2a753b0dc864e7218f8facf23ca0e2b636351df5289b76f5845d9a78b7026")),
bytes32(bytes.fromhex("9dc8b9d685c79acdf8780d994416dfcfb118e0adc99769ecfa94e1f40aa5bbe5")),
Expand Down Expand Up @@ -142,7 +140,7 @@
)


### FULL NODE PROTOCOL.
# FULL NODE PROTOCOL.
new_peak = full_node_protocol.NewPeak(
bytes32(bytes.fromhex("8a346e8dc02e9b44c0571caa74fd99f163d4c5d7deae9f8ddb00528721493f7a")),
uint32(2653549198),
Expand Down Expand Up @@ -503,7 +501,7 @@
respond_peers = full_node_protocol.RespondPeers([timestamped_peer_info])


## WALLET PROTOCOL
# WALLET PROTOCOL
request_puzzle_solution = wallet_protocol.RequestPuzzleSolution(
bytes32(bytes.fromhex("6edddb46bd154f50566b49c95812e0f1131a0a7162630349fc8d1d696e463e47")),
uint32(3905474497),
Expand Down Expand Up @@ -755,7 +753,7 @@
)


### HARVESTER PROTOCOL
# HARVESTER PROTOCOL
pool_difficulty = harvester_protocol.PoolDifficulty(
uint64(14819251421858580996),
uint64(12852879676624401630),
Expand Down Expand Up @@ -899,7 +897,7 @@
["str"],
)

### INTRODUCER PROTOCOL
# INTRODUCER PROTOCOL
request_peers_introducer = introducer_protocol.RequestPeersIntroducer()

respond_peers_introducer = introducer_protocol.RespondPeersIntroducer(
Expand All @@ -913,7 +911,7 @@
)


### POOL PROTOCOL
# POOL PROTOCOL
authentication_payload = pool_protocol.AuthenticationPayload(
"method",
bytes32(bytes.fromhex("0251e3b3a1aacc689091b6b085be7a8d319bd9d1a015faae969cb76d8a45607c")),
Expand Down Expand Up @@ -1002,7 +1000,7 @@
"err",
)

### TIMELORD PROTOCOL
# TIMELORD PROTOCOL
sub_epoch_summary = SubEpochSummary(
bytes32(bytes.fromhex("2d0550de416467e7b57e56e962c712b79bee29cae29c73cc908da5978fc9789e")),
bytes32(bytes.fromhex("3d29f5a3fe067ce7edea76c9cebaf3a3afdebc0eb9fbd530f807f1a28ed2df6d")),
Expand Down
1 change: 1 addition & 0 deletions chia/_tests/util/protocol_messages_json.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: E501
pmaslana marked this conversation as resolved.
Show resolved Hide resolved
# this file is generated by build_network_protocol_files.py
from __future__ import annotations

Expand Down
1 change: 1 addition & 0 deletions chia/_tests/util/test_network_protocol_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F405
# this file is generated by build_network_protocol_files.py

from __future__ import annotations
Expand Down
Loading
Loading