Skip to content

Commit

Permalink
Add ruff and update
Browse files Browse the repository at this point in the history
  • Loading branch information
emlowe committed Dec 19, 2024
1 parent 6c61d17 commit da4f652
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 179 deletions.
36 changes: 16 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
repos:
- repo: local
hooks:
- id: isort
name: isort
entry: isort
require_serial: true
language: python
language_version: python3
types_or: [cython, pyi, python]
args: ['--filter-files']
minimum_pre_commit_version: '2.9.2'
additional_dependencies: [isort==5.13.2]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -21,18 +9,26 @@ repos:
- id: check-merge-conflict
- id: check-ast
- id: debug-statements
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
- repo: local
hooks:
- id: flake8
- id: ruff_format
name: ruff format
entry: ruff format
language: system
require_serial: true
types_or: [python, pyi]

- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: system
pass_filenames: false
- repo: local
hooks:
- id: ruff
name: Ruff
entry: ruff check --fix
language: system
types: [python]
2 changes: 2 additions & 0 deletions chianft/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from pkg_resources import DistributionNotFound, get_distribution

try:
Expand Down
14 changes: 4 additions & 10 deletions chianft/cmds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ def create_spend_bundles_cmd(
"""

async def do_command() -> None:
maybe_clients = await get_node_and_wallet_clients(
node_rpc_port, wallet_rpc_port, fingerprint
)
maybe_clients = await get_node_and_wallet_clients(node_rpc_port, wallet_rpc_port, fingerprint)
if maybe_clients is None:
print("Failed to connect to wallet and node")
return
Expand All @@ -145,7 +143,7 @@ async def do_command() -> None:
)
with open(bundle_output, "wb") as f:
pickle.dump(spend_bundles, f)
print("Successfully created {} spend bundles".format(len(spend_bundles)))
print(f"Successfully created {len(spend_bundles)} spend bundles")
finally:
node_client.close()
wallet_client.close()
Expand Down Expand Up @@ -205,9 +203,7 @@ def submit_spend_bundles_cmd(
"""

async def do_command() -> None:
maybe_clients = await get_node_and_wallet_clients(
node_rpc_port, wallet_rpc_port, fingerprint
)
maybe_clients = await get_node_and_wallet_clients(node_rpc_port, wallet_rpc_port, fingerprint)
if maybe_clients is None:
print("Failed to connect to wallet and node")
return
Expand All @@ -224,9 +220,7 @@ async def do_command() -> None:
spends.append(SpendBundle.from_bytes(spend_bytes))

minter = Minter(wallet_client, node_client)
await minter.submit_spend_bundles(
spends, fee, create_sell_offer=create_sell_offer
)
await minter.submit_spend_bundles(spends, fee, create_sell_offer=create_sell_offer)

finally:
node_client.close()
Expand Down
20 changes: 7 additions & 13 deletions chianft/util/clients.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from pprint import pprint
from typing import Optional, Tuple
from typing import Optional

import aiohttp

Expand All @@ -25,9 +27,7 @@ async def get_node_client(
return full_node_client
except Exception as e:
if isinstance(e, aiohttp.ClientConnectorError):
pprint(
f"Connection error. Check if full node is running at {full_node_rpc_port}"
)
pprint(f"Connection error. Check if full node is running at {full_node_rpc_port}")
else:
pprint(f"Exception from 'full node' {e}")
return None
Expand All @@ -41,9 +41,7 @@ async def get_wallet_client(
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
self_hostname = config["self_hostname"]
wallet_rpc_port = config["wallet"]["rpc_port"]
wallet_client = await WalletRpcClient.create(
self_hostname, uint16(wallet_rpc_port), DEFAULT_ROOT_PATH, config
)
wallet_client = await WalletRpcClient.create(self_hostname, uint16(wallet_rpc_port), DEFAULT_ROOT_PATH, config)
return wallet_client
except Exception as e:
if isinstance(e, aiohttp.ClientConnectorError):
Expand All @@ -57,7 +55,7 @@ async def get_node_and_wallet_clients(
full_node_rpc_port: Optional[int],
wallet_rpc_port: Optional[int],
fingerprint: Optional[int],
) -> Optional[Tuple[Optional[FullNodeRpcClient], Optional[WalletRpcClient]]]:
) -> Optional[tuple[Optional[FullNodeRpcClient], Optional[WalletRpcClient]]]:
try:
full_node_client = await get_node_client(full_node_rpc_port)
wallet_client = await get_wallet_client(wallet_rpc_port)
Expand All @@ -76,8 +74,4 @@ async def get_node_and_wallet_clients(
def get_additional_data() -> bytes:
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
selected_network = config["farmer"]["selected_network"]
return bytes.fromhex(
config["farmer"]["network_overrides"]["constants"][selected_network][
"GENESIS_CHALLENGE"
]
)
return bytes.fromhex(config["farmer"]["network_overrides"]["constants"][selected_network]["GENESIS_CHALLENGE"])
Loading

0 comments on commit da4f652

Please sign in to comment.