Skip to content

Commit

Permalink
[CHIA-1553] Replace pylint with ruff (#18759)
Browse files Browse the repository at this point in the history
* Replace pylint with ruff

* poetry

* remove pylint

* Address comments by @altendky

* Undo formatting

* actually undo formatting
  • Loading branch information
Quexington authored Oct 25, 2024
1 parent 0354e6e commit 6084112
Show file tree
Hide file tree
Showing 49 changed files with 184 additions and 763 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
* @Chia-Network/required-reviewers
/.github/**/* @Chia-Network/actions-reviewers
/PRETTY_GOOD_PRACTICES.md @altendky @Chia-Network/required-reviewers
/pylintrc @altendky @Chia-Network/required-reviewers
/tests/ether.py @altendky @Chia-Network/required-reviewers
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
- name: "Dependency Review"
uses: actions/dependency-review-action@v4
with:
allow-dependencies-licenses: pkg:pypi/pylint, pkg:pypi/pyinstaller
allow-dependencies-licenses: pkg:pypi/pyinstaller
deny-licenses: AGPL-1.0-only, AGPL-1.0-or-later, AGPL-1.0-or-later, AGPL-3.0-or-later, GPL-1.0-only, GPL-1.0-or-later, GPL-2.0-only, GPL-2.0-or-later, GPL-3.0-only, GPL-3.0-or-later
2 changes: 0 additions & 2 deletions .github/workflows/upload-pypi-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ jobs:
command: black --check --diff .
- name: flake8
command: flake8 benchmarks build_scripts chia tools *.py
- name: pylint
command: pylint benchmarks build_scripts chia tools *.py
- name: generated protocol tests
command: |
python3 -m chia._tests.util.build_network_protocol_files
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ repos:
entry: ./activated.py flake8
language: system
types: [python]
- repo: local
hooks:
- id: ruff
name: Ruff
entry: ./activated.py ruff check --fix
language: system
types: [python]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The [black library](https://black.readthedocs.io/en/stable/) is used as an autom
The [flake8 library](https://readthedocs.org/projects/flake8/) helps ensure consistent style.
The [Mypy library](https://mypy.readthedocs.io/en/stable/) is very useful for ensuring objects are of the correct type, so try to always add the type of the return value, and the type of local variables.
The [isort library](https://isort.readthedocs.io) is used to sort, group and validate imports in all python files.
The [pylint library](https://pylint.pycqa.org/en/stable/) is used to further lint all python files.
The [Ruff library](https://docs.astral.sh) is used to further lint all of the python files

If you want verbose logging for tests, edit the `tests/pytest.ini` file.

Expand Down
1 change: 0 additions & 1 deletion benchmarks/block_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ def entry_point(db_path: Path) -> None:


if __name__ == "__main__":
# pylint: disable = no-value-for-parameter
entry_point()
2 changes: 1 addition & 1 deletion benchmarks/streamable.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,4 @@ def get_bench_results() -> BenchmarkResults:


if __name__ == "__main__":
run() # pylint: disable = no-value-for-parameter
run()
2 changes: 1 addition & 1 deletion chia/_tests/build-init-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ def command(verbose, root_str):
raise click.ClickException("At least one __init__.py created or not a regular file")


command() # pylint: disable=no-value-for-parameter
command()
2 changes: 1 addition & 1 deletion chia/_tests/cmds/cmd_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def run_cli_command(capsys: object, chia_root: Path, command_list: list[str]) ->
argv_temp = sys.argv
try:
sys.argv = ["chia", "--root-path", str(chia_root)] + command_list
chia_cli() # pylint: disable=no-value-for-parameter
chia_cli()
except SystemExit as e:
if e.code != 0:
exited_cleanly = False
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/cmds/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async def get_block(self, header_hash: bytes32) -> Optional[FullBlock]:
return full_block


RPC_CLIENT_TO_USE = ShowFullNodeRpcClient() # pylint: disable=no-value-for-parameter
RPC_CLIENT_TO_USE = ShowFullNodeRpcClient()


def test_chia_show(capsys: object, get_test_cli_clients: tuple[TestRpcClients, Path]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions chia/_tests/cmds/wallet/test_coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_coins_get_info(capsys: object, get_test_cli_clients: tuple[TestRpcClien

# set RPC Client

inst_rpc_client = TestWalletRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = TestWalletRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = ["wallet", "coins", "list", FINGERPRINT_ARG, "-i1", "-u"]
# these are various things that should be in the output
Expand Down Expand Up @@ -68,7 +68,7 @@ async def combine_coins(
self.add_to_log("combine_coins", (args, tx_config, timelock_info))
return CombineCoinsResponse([STD_UTX], [STD_TX])

inst_rpc_client = CoinsCombineRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = CoinsCombineRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
assert sum(coin.amount for coin in STD_TX.removals) < 500_000_000_000
command_args = [
Expand Down Expand Up @@ -173,7 +173,7 @@ async def get_coin_records_by_names(
else:
return []

inst_rpc_client = CoinsSplitRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = CoinsSplitRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
target_coin_id = test_coin.name()
command_args = [
Expand Down
8 changes: 4 additions & 4 deletions chia/_tests/cmds/wallet/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def create_new_dao_wallet(
}
)

inst_rpc_client = DAOCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DAOCreateRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = [
"dao",
Expand Down Expand Up @@ -175,7 +175,7 @@ async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
valid_times=parse_timelock_info(tuple()),
)

inst_rpc_client = DAOCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DAOCreateRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client

get_id_args = ["dao", "get_id", FINGERPRINT_ARG, "-i 2"]
Expand Down Expand Up @@ -345,7 +345,7 @@ async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
)

# List all proposals
inst_rpc_client = DAOCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DAOCreateRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
list_args = ["dao", "list_proposals", FINGERPRINT_ARG, "-i 2"]
# these are various things that should be in the output
Expand Down Expand Up @@ -549,7 +549,7 @@ async def get_transaction(self, transaction_id: bytes32) -> TransactionRecord:
valid_times=parse_timelock_info(tuple()),
)

inst_rpc_client = DAOCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DAOCreateRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
lockup_args = ["dao", "lockup_coins", FINGERPRINT_ARG, "-i 2", "-a", "1000", "-m 0.1", "--reuse"]
lockup_asserts = ["Transaction submitted to nodes"]
Expand Down
18 changes: 9 additions & 9 deletions chia/_tests/cmds/wallet/test_did.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def create_new_did_wallet(
)
return {"wallet_id": 3, "my_did": "did:chia:testdid123456"}

inst_rpc_client = DidCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidCreateRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = [
"wallet",
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_did_sign_message(capsys: object, get_test_cli_clients: tuple[TestRpcCli
test_rpc_clients, root_dir = get_test_cli_clients

# set RPC Client
inst_rpc_client = TestWalletRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = TestWalletRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
did_id = encode_puzzle_hash(get_bytes32(1), "did:chia:")
message = b"hello did world!!"
Expand Down Expand Up @@ -106,7 +106,7 @@ async def did_set_wallet_name(self, wallet_id: int, name: str) -> dict[str, Unio
self.add_to_log("did_set_wallet_name", (wallet_id, name))
return {}

inst_rpc_client = DidSetNameRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidSetNameRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
w_id = 3
did_name = "testdid"
Expand All @@ -129,7 +129,7 @@ async def get_did_id(self, wallet_id: int) -> dict[str, str]:
self.add_to_log("get_did_id", (wallet_id,))
return {"my_did": encode_puzzle_hash(get_bytes32(1), "did:chia:"), "coin_id": get_bytes32(2).hex()}

inst_rpc_client = DidGetDidRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidGetDidRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
w_id = 3
expected_did = encode_puzzle_hash(get_bytes32(1), "did:chia:")
Expand Down Expand Up @@ -165,7 +165,7 @@ async def get_did_info(self, coin_id: str, latest: bool) -> dict[str, object]:
}
return response

inst_rpc_client = DidGetDetailsRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidGetDetailsRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
did_coin_id_hex = get_bytes32(1).hex()
command_args = ["wallet", "did", "get_details", FINGERPRINT_ARG, "--coin_id", did_coin_id_hex]
Expand Down Expand Up @@ -207,7 +207,7 @@ async def update_did_metadata(
self.add_to_log("update_did_metadata", (wallet_id, metadata, tx_config, push, timelock_info))
return DIDUpdateMetadataResponse([STD_UTX], [STD_TX], WalletSpendBundle([], G2Element()), uint32(wallet_id))

inst_rpc_client = DidUpdateMetadataRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidUpdateMetadataRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
w_id = 3
json_mdata = '{"test": true}'
Expand Down Expand Up @@ -252,7 +252,7 @@ async def find_lost_did(
self.add_to_log("find_lost_did", (coin_id, recovery_list_hash, metadata, num_verification))
return {"success": True, "latest_coin_id": get_bytes32(2).hex()}

inst_rpc_client = DidFindLostRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidFindLostRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
c_id = get_bytes32(1)
json_mdata = '{"test": true}'
Expand Down Expand Up @@ -291,7 +291,7 @@ async def did_message_spend(
self.add_to_log("did_message_spend", (wallet_id, tx_config, extra_conditions, push, timelock_info))
return DIDMessageSpendResponse([STD_UTX], [STD_TX], WalletSpendBundle([], G2Element()))

inst_rpc_client = DidMessageSpendRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidMessageSpendRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
w_id = 3
c_announcements = [get_bytes32(1), get_bytes32(2)]
Expand Down Expand Up @@ -357,7 +357,7 @@ async def did_transfer_did(
STD_TX.name,
)

inst_rpc_client = DidTransferRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = DidTransferRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
w_id = 3
t_address = encode_puzzle_hash(get_bytes32(1), "xch")
Expand Down
16 changes: 8 additions & 8 deletions chia/_tests/cmds/wallet/test_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def create_new_nft_wallet(self, did_id: str, name: Optional[str] = None) -
self.add_to_log("create_new_nft_wallet", (did_id, name))
return {"wallet_id": 4}

inst_rpc_client = NFTCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NFTCreateRpcClient()
did_id = encode_puzzle_hash(get_bytes32(2), "did:chia:")
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = ["wallet", "nft", "create", FINGERPRINT_ARG, "-ntest", "--did-id", did_id]
Expand All @@ -54,7 +54,7 @@ def test_nft_sign_message(capsys: object, get_test_cli_clients: tuple[TestRpcCli

# set RPC Client

inst_rpc_client = TestWalletRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = TestWalletRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
did_id = encode_puzzle_hash(get_bytes32(1), "nft")
message = b"hello nft world!!"
Expand Down Expand Up @@ -132,7 +132,7 @@ async def mint_nft(
bytes32.zeros.hex(),
)

inst_rpc_client = NFTCreateRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NFTCreateRpcClient()
target_addr = encode_puzzle_hash(get_bytes32(2), "xch")
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = [
Expand Down Expand Up @@ -209,7 +209,7 @@ async def add_uri_to_nft(
self.add_to_log("add_uri_to_nft", (wallet_id, nft_coin_id, key, uri, fee, tx_config, push, timelock_info))
return NFTAddURIResponse([STD_UTX], [STD_TX], uint32(wallet_id), WalletSpendBundle([], G2Element()))

inst_rpc_client = NFTAddUriRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NFTAddUriRpcClient()
nft_coin_id = get_bytes32(2).hex()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = [
Expand Down Expand Up @@ -275,7 +275,7 @@ async def transfer_nft(
WalletSpendBundle([], G2Element()),
)

inst_rpc_client = NFTTransferRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NFTTransferRpcClient()
nft_coin_id = get_bytes32(2).hex()
target_address = encode_puzzle_hash(get_bytes32(2), "xch")
test_rpc_clients.wallet_rpc_client = inst_rpc_client
Expand Down Expand Up @@ -352,7 +352,7 @@ async def list_nfts(self, wallet_id: int, num: int = 50, start_index: int = 0) -
)
return {"nft_list": nft_list}

inst_rpc_client = NFTListRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NFTListRpcClient()
launcher_ids = [bytes32([i] * 32).hex() for i in range(50, 60)]
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = [
Expand Down Expand Up @@ -401,7 +401,7 @@ async def set_nft_did(
WalletSpendBundle([], G2Element()),
)

inst_rpc_client = NFTSetDidRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NFTSetDidRpcClient()
nft_coin_id = get_bytes32(2).hex()
did_id = encode_puzzle_hash(get_bytes32(3), "did:chia:")
test_rpc_clients.wallet_rpc_client = inst_rpc_client
Expand Down Expand Up @@ -447,7 +447,7 @@ def test_nft_get_info(capsys: object, get_test_cli_clients: tuple[TestRpcClients

# set RPC Client

inst_rpc_client = TestWalletRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = TestWalletRpcClient()
nft_coin_id = get_bytes32(2).hex()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = [
Expand Down
6 changes: 3 additions & 3 deletions chia/_tests/cmds/wallet/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, name: str) -> None:

return cast(TransactionRecord, FakeTransactionRecord(get_bytes32(2).hex()))

inst_rpc_client = NotificationsSendRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NotificationsSendRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
target_ph = get_bytes32(1)
target_addr = encode_puzzle_hash(target_ph, "xch")
Expand Down Expand Up @@ -82,7 +82,7 @@ async def get_notifications(self, request: GetNotifications) -> GetNotifications
[Notification(get_bytes32(1), bytes("hello", "utf8"), uint64(1000000000), uint32(50))]
)

inst_rpc_client = NotificationsGetRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NotificationsGetRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
target_ph = get_bytes32(1)
command_args = [
Expand Down Expand Up @@ -114,7 +114,7 @@ async def delete_notifications(self, ids: Optional[list[bytes32]] = None) -> boo
self.add_to_log("delete_notifications", (ids,))
return True

inst_rpc_client = NotificationsDeleteRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = NotificationsDeleteRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = ["wallet", "notifications", "delete", FINGERPRINT_ARG, "--all"]
# these are various things that should be in the output
Expand Down
14 changes: 7 additions & 7 deletions chia/_tests/cmds/wallet/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def vc_mint(
),
)

inst_rpc_client = VcsMintRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsMintRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
did_bytes = get_bytes32(1)
did_id = encode_puzzle_hash(did_bytes, "did:chia:")
Expand Down Expand Up @@ -108,7 +108,7 @@ def __getattr__(self, item: str) -> Any:
records = [cast(VCRecord, FakeVC())]
return records, proofs

inst_rpc_client = VcsGetRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsGetRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
command_args = ["wallet", "vcs", "get", FINGERPRINT_ARG, "-s10", "-c10"]
# these are various things that should be in the output
Expand Down Expand Up @@ -144,7 +144,7 @@ async def vc_spend(
)
return VCSpendResponse([STD_UTX], [STD_TX])

inst_rpc_client = VcsUpdateProofsRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsUpdateProofsRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
vc_bytes = get_bytes32(1)
target_ph = get_bytes32(2)
Expand Down Expand Up @@ -196,7 +196,7 @@ async def vc_add_proofs(self, proofs: dict[str, Any]) -> None:
self.add_to_log("vc_add_proofs", (proofs,))
return None

inst_rpc_client = VcsAddProofRevealRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsAddProofRevealRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
new_proof = "test_proof"
command_args = ["wallet", "vcs", "add_proof_reveal", FINGERPRINT_ARG, f"-p{new_proof}"]
Expand All @@ -220,7 +220,7 @@ async def vc_get_proofs_for_root(self, root: bytes32) -> dict[str, Any]:
self.add_to_log("vc_get_proofs_for_root", (root,))
return {"test_proof": "1", "test_proof2": "1"}

inst_rpc_client = VcsGetProofsForRootRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsGetProofsForRootRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
proof_hash = get_bytes32(1)
command_args = ["wallet", "vcs", "get_proofs_for_root", FINGERPRINT_ARG, f"-r{proof_hash.hex()}"]
Expand Down Expand Up @@ -261,7 +261,7 @@ async def vc_revoke(
self.add_to_log("vc_revoke", (vc_parent_id, tx_config, fee, push, timelock_info))
return VCRevokeResponse([STD_UTX], [STD_TX])

inst_rpc_client = VcsRevokeRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsRevokeRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
parent_id = get_bytes32(1)
vc_id = get_bytes32(2)
Expand Down Expand Up @@ -330,7 +330,7 @@ async def crcat_approve_pending(
)
return [STD_TX]

inst_rpc_client = VcsApproveRCATSRpcClient() # pylint: disable=no-value-for-parameter
inst_rpc_client = VcsApproveRCATSRpcClient()
test_rpc_clients.wallet_rpc_client = inst_rpc_client
wallet_id = uint32(2)
command_args = [
Expand Down
Loading

0 comments on commit 6084112

Please sign in to comment.