pre-commit: Add a new hook to run isort (#8827)

* pre-commit: Add a new hook to run `isort`

* contributing: Add hint about `isort`

* add isort to dev deps, ignore existing .py files, use black profile

* long list to lines not comma delimited

* isort: Update and sort ignore list to match latest `main`

* add bash command line to generate isort extend skip list (#3)

* add bash command line to generate extend skip list

* tidy

* isort: More files to ignore after rebase

* tests: Fix `test_wallet_user_store.py` after rebase

* Some fixes after rebase

Co-authored-by: Kyle Altendorf <sda@fstab.net>
This commit is contained in:
dustinface 2022-02-15 16:28:53 +01:00 committed by GitHub
parent 65c0829f66
commit 98971de9d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 289 additions and 43 deletions

View File

@ -1,20 +1,243 @@
[settings]
profile=
; vertical hanging indent mode also used in black configuration
multi_line_output = 3
; necessary because black expect the trailing comma
include_trailing_comma = true
; black compatibility
force_grid_wrap = 0
; black compatibility
use_parentheses = True
; black compatibility
ensure_newline_before_comments = True
; we chose 120 as line length
line_length = 120
profile=black
skip_gitignore=true
# venv/bin/isort --check . |& sed -n "s;ERROR: ${PWD}/\(.*\) Imports are.*; \1;p" | sort | uniq
extend_skip=
benchmarks/block_store.py
benchmarks/coin_store.py
benchmarks/utils.py
chia/clvm/spend_sim.py
chia/cmds/chia.py
chia/cmds/db.py
chia/cmds/db_upgrade_func.py
chia/cmds/farm_funcs.py
chia/cmds/farm.py
chia/cmds/init_funcs.py
chia/cmds/init.py
chia/cmds/keys_funcs.py
chia/cmds/keys.py
chia/cmds/netspace.py
chia/cmds/passphrase_funcs.py
chia/cmds/passphrase.py
chia/cmds/plotnft_funcs.py
chia/cmds/plotnft.py
chia/cmds/plotters.py
chia/cmds/seeder.py
chia/cmds/show.py
chia/cmds/start_funcs.py
chia/cmds/start.py
chia/cmds/wallet_funcs.py
chia/cmds/wallet.py
chia/daemon/keychain_proxy.py
chia/daemon/keychain_server.py
chia/daemon/server.py
chia/farmer/farmer_api.py
chia/farmer/farmer.py
chia/full_node/block_height_map.py
chia/full_node/block_store.py
chia/full_node/bundle_tools.py
chia/full_node/coin_store.py
chia/full_node/full_node_api.py
chia/full_node/full_node.py
chia/full_node/generator.py
chia/full_node/hint_store.py
chia/full_node/lock_queue.py
chia/full_node/mempool_check_conditions.py
chia/full_node/mempool_manager.py
chia/full_node/weight_proof.py
chia/harvester/harvester_api.py
chia/harvester/harvester.py
chia/introducer/introducer.py
chia/plotters/bladebit.py
chia/plotters/chiapos.py
chia/plotters/install_plotter.py
chia/plotters/madmax.py
chia/plotters/plotters.py
chia/plotting/check_plots.py
chia/plotting/create_plots.py
chia/plotting/manager.py
chia/plotting/util.py
chia/pools/pool_puzzles.py
chia/pools/pool_wallet_info.py
chia/pools/pool_wallet.py
chia/protocols/harvester_protocol.py
chia/protocols/pool_protocol.py
chia/protocols/protocol_state_machine.py
chia/rpc/farmer_rpc_client.py
chia/rpc/full_node_rpc_client.py
chia/rpc/rpc_client.py
chia/rpc/wallet_rpc_api.py
chia/rpc/wallet_rpc_client.py
chia/seeder/crawler.py
chia/seeder/crawl_store.py
chia/seeder/dns_server.py
chia/seeder/util/service_groups.py
chia/seeder/util/service.py
chia/server/address_manager_sqlite_store.py
chia/server/address_manager_store.py
chia/server/introducer_peers.py
chia/server/node_discovery.py
chia/server/peer_store_resolver.py
chia/server/reconnect_task.py
chia/server/start_service.py
chia/server/start_wallet.py
chia/simulator/simulator_constants.py
chia/simulator/start_simulator.py
chia/ssl/create_ssl.py
chia/timelord/timelord_launcher.py
chia/types/blockchain_format/program.py
chia/types/blockchain_format/proof_of_space.py
chia/types/blockchain_format/vdf.py
chia/types/coin_solution.py
chia/types/coin_spend.py
chia/types/full_block.py
chia/types/generator_types.py
chia/types/name_puzzle_condition.py
chia/types/spend_bundle.py
chia/util/bech32m.py
chia/util/byte_types.py
chia/util/chain_utils.py
chia/util/check_fork_next_block.py
chia/util/chia_logging.py
chia/util/condition_tools.py
chia/util/dump_keyring.py
chia/util/file_keyring.py
chia/util/files.py
chia/util/generator_tools.py
chia/util/keychain.py
chia/util/keyring_wrapper.py
chia/util/log_exceptions.py
chia/util/network.py
chia/util/profiler.py
chia/util/service_groups.py
chia/util/ssl_check.py
chia/util/streamable.py
chia/util/ws_message.py
chia/wallet/cat_wallet/cat_info.py
chia/wallet/cat_wallet/cat_utils.py
chia/wallet/cat_wallet/cat_wallet.py
chia/wallet/derive_keys.py
chia/wallet/did_wallet/did_info.py
chia/wallet/did_wallet/did_wallet_puzzles.py
chia/wallet/did_wallet/did_wallet.py
chia/wallet/lineage_proof.py
chia/wallet/payment.py
chia/wallet/puzzles/genesis_checkers.py
chia/wallet/puzzles/load_clvm.py
chia/wallet/puzzles/prefarm/make_prefarm_ph.py
chia/wallet/puzzles/prefarm/spend_prefarm.py
chia/wallet/puzzles/puzzle_utils.py
chia/wallet/puzzles/singleton_top_layer.py
chia/wallet/puzzles/tails.py
chia/wallet/rl_wallet/rl_wallet.py
chia/wallet/sign_coin_spends.py
chia/wallet/trade_manager.py
chia/wallet/trade_record.py
chia/wallet/trading/offer.py
chia/wallet/trading/trade_store.py
chia/wallet/transaction_record.py
chia/wallet/util/compute_hints.py
chia/wallet/util/compute_memos.py
chia/wallet/util/debug_spend_bundle.py
chia/wallet/util/puzzle_compression.py
chia/wallet/util/wallet_sync_utils.py
chia/wallet/wallet_blockchain.py
chia/wallet/wallet_coin_store.py
chia/wallet/wallet_interested_store.py
chia/wallet/wallet_node_api.py
chia/wallet/wallet_node.py
chia/wallet/wallet_pool_store.py
chia/wallet/wallet.py
chia/wallet/wallet_state_manager.py
chia/wallet/wallet_weight_proof_handler.py
installhelper.py
tests/blockchain/test_blockchain.py
tests/blockchain/test_blockchain_transactions.py
tests/block_tools.py
tests/build-init-files.py
tests/build-workflows.py
tests/clvm/benchmark_costs.py
tests/clvm/coin_store.py
tests/clvm/test_chialisp_deserialization.py
tests/clvm/test_program.py
tests/clvm/test_puzzle_compression.py
tests/clvm/test_serialized_program.py
tests/clvm/test_singletons.py
tests/clvm/test_spend_sim.py
tests/conftest.py
tests/core/cmds/test_keys.py
tests/core/custom_types/test_coin.py
tests/core/custom_types/test_spend_bundle.py
tests/core/daemon/test_daemon.py
tests/core/full_node/full_sync/test_full_sync.py
tests/core/full_node/ram_db.py
tests/core/full_node/test_block_height_map.py
tests/core/full_node/test_block_store.py
tests/core/full_node/test_coin_store.py
tests/core/full_node/test_conditions.py
tests/core/full_node/test_full_node.py
tests/core/full_node/test_full_node_store.py
tests/core/full_node/test_hint_store.py
tests/core/full_node/test_mempool_performance.py
tests/core/full_node/test_mempool.py
tests/core/full_node/test_performance.py
tests/core/server/test_dos.py
tests/core/server/test_rate_limits.py
tests/core/ssl/test_ssl.py
tests/core/test_daemon_rpc.py
tests/core/test_db_conversion.py
tests/core/test_farmer_harvester_rpc.py
tests/core/test_filter.py
tests/core/test_full_node_rpc.py
tests/core/util/test_cached_bls.py
tests/core/util/test_config.py
tests/core/util/test_file_keyring_synchronization.py
tests/core/util/test_files.py
tests/core/util/test_keychain.py
tests/core/util/test_keyring_wrapper.py
tests/core/util/test_streamable.py
tests/generator/test_compression.py
tests/generator/test_generator_types.py
tests/generator/test_list_to_batches.py
tests/generator/test_rom.py
tests/generator/test_scan.py
tests/plotting/test_plot_manager.py
tests/plotting/util.py
tests/pools/test_pool_cmdline.py
tests/pools/test_pool_config.py
tests/pools/test_pool_puzzles_lifecycle.py
tests/pools/test_pool_rpc.py
tests/pools/test_wallet_pool_store.py
tests/setup_nodes.py
tests/simulation/test_simulation.py
tests/util/benchmark_cost.py
tests/util/blockchain.py
tests/util/build_network_protocol_files.py
tests/util/db_connection.py
tests/util/keyring.py
tests/util/key_tool.py
tests/util/misc.py
tests/util/network_protocol_data.py
tests/util/network.py
tests/util/test_lock_queue.py
tests/util/test_network_protocol_files.py
tests/util/test_struct_stream.py
tests/wallet/cat_wallet/test_cat_lifecycle.py
tests/wallet/cat_wallet/test_cat_wallet.py
tests/wallet/cat_wallet/test_offer_lifecycle.py
tests/wallet/did_wallet/test_did.py
tests/wallet/did_wallet/test_did_rpc.py
tests/wallet/rpc/test_wallet_rpc.py
tests/wallet/simple_sync/test_simple_sync_protocol.py
tests/wallet/test_singleton_lifecycle_fast.py
tests/wallet/test_singleton_lifecycle.py
tests/wallet/test_singleton.py
tests/wallet/test_wallet_blockchain.py
tests/wallet/test_wallet_interested_store.py
tests/wallet/test_wallet_key_val_store.py
tests/wallet/test_wallet.py
tests/wallet_tools.py
tests/weight_proof/test_weight_proof.py
tools/analyze-chain.py
tools/run_block.py

View File

@ -14,6 +14,27 @@ repos:
language: python
pass_filenames: false
additional_dependencies: [click~=7.1]
# The following, commented hook is the usual way to add isort. However, it doesn't work in some environments.
# See https://github.com/PyCQA/isort/issues/1874#issuecomment-1002212936
# -----------------------------------------------------
# - repo: https://github.com/pycqa/isort
# rev: 5.9.3
# hooks:
# - id: isort
# -----------------------------------------------------
# The hook below is the workaround for the issue above.
- 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.10.1]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:

View File

@ -58,6 +58,7 @@ py.test tests -v --durations 0
The [black library](https://black.readthedocs.io/en/stable/) is used as an automatic style formatter to make things easier.
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.
If you want verbose logging for tests, edit the `tests/pytest.ini` file.

View File

@ -1,13 +1,13 @@
import click
import aiosqlite
import asyncio
import time
import random
import os
from typing import Optional, List
from pathlib import Path
import random
import time
from dataclasses import dataclass
from pathlib import Path
from typing import List, Optional
import aiosqlite
import click
from chia.consensus.blockchain import Blockchain
from chia.consensus.default_constants import DEFAULT_CONSTANTS

View File

@ -29,6 +29,7 @@ from chia.full_node.block_store import BlockStore
from chia.full_node.coin_store import CoinStore
from chia.full_node.hint_store import HintStore
from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
from chia.types.block_protocol import BlockInfo
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.program import SerializedProgram
from chia.types.blockchain_format.sized_bytes import bytes32
@ -47,7 +48,6 @@ from chia.util.errors import ConsensusError, Err
from chia.util.generator_tools import get_block_header, tx_removals_and_additions
from chia.util.ints import uint16, uint32, uint64, uint128
from chia.util.streamable import recurse_jsonify
from chia.types.block_protocol import BlockInfo
log = logging.getLogger(__name__)

View File

@ -1,4 +1,4 @@
from typing import Dict, Tuple, Any, Optional, List
from typing import Any, Dict, List, Optional, Tuple
from chia.protocols.wallet_protocol import CoinState
from chia.types.blockchain_format.sized_bytes import bytes32

View File

@ -46,6 +46,7 @@ dev_dependencies = [
"pytest-asyncio",
"pytest-monitor; sys_platform == 'linux'",
"pytest-xdist",
"isort",
"flake8",
"mypy",
# TODO: black 22.1.0 requires click>=8, remove this pin after updating to click 8

View File

@ -1,10 +1,11 @@
#!/usr/bin/env python3
import asyncio
from tools.test_full_sync import run_sync_test
import os
from pathlib import Path
from tools.test_full_sync import run_sync_test
def test_full_sync_test():
file_path = os.path.realpath(__file__)

View File

@ -1,10 +1,10 @@
from pathlib import Path
import aiosqlite
import pytest
from chia.util.db_wrapper import DBWrapper
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_user_store import WalletUserStore

View File

@ -1,24 +1,23 @@
#!/usr/bin/env python3
import asyncio
import aiosqlite
import zstd
import click
import logging
import cProfile
import logging
import tempfile
import time
from contextlib import contextmanager
from pathlib import Path
from typing import Iterator
from pathlib import Path
import time
import tempfile
from contextlib import contextmanager
from chia.types.full_block import FullBlock
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.util.config import load_config
from chia.full_node.full_node import FullNode
import aiosqlite
import click
import zstd
from chia.cmds.init_funcs import chia_init
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.full_node.full_node import FullNode
from chia.types.full_block import FullBlock
from chia.util.config import load_config
class ExitOnError(logging.Handler):
@ -128,8 +127,8 @@ def run(file: Path, db_version: int, profile: bool) -> None:
@main.command("analyze", short_help="generate call stacks for all profiles dumped to current directory")
def analyze() -> None:
from shlex import quote
from glob import glob
from shlex import quote
from subprocess import check_call
for input_file in glob("slow-batch-*.profile"):