Skip to content

Commit

Permalink
Replace flake8 with ruff for linting (#259)
Browse files Browse the repository at this point in the history
* Replace flake8 with ruff for linting
* Replace flake8 with ruff in Makefile
* Replace flake8 in tox
* Update pre-commit to use ruff instead of flake8. Update uv.lock and pyproject.toml
* Fix linting error and pre-commit stuff
* Update pre-commit documentation and dependencies
  • Loading branch information
remyroy authored Jan 26, 2025
1 parent e5750a4 commit 01cd633
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Run type checker
run: python -m mypy --config-file mypy.ini -p ethstaker_deposit
- name: Run linter
run: flake8 --config=flake8.ini ./ethstaker_deposit ./tests
run: ruff check ./ethstaker_deposit ./tests
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
22 changes: 10 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
repos:
- repo: https://github.com/pycqa/flake8
rev: '7.1.1'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.2
hooks:
- id: flake8
files: ^(ethstaker_deposit|tests)/
args: [--config, flake8.ini]
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.11.2'
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies:
- click==8.1.7
- eth-typing==5.0.0
- eth-utils==5.0.0
- pycryptodome==3.20.0
- click==8.1.8
- eth-typing==5.1.0
- eth-utils==5.1.0
- pycryptodome==3.21.0
- py-ecc==7.0.1
- ssz==0.5.0
- ssz==0.5.1
files: ^ethstaker_deposit/
args: [--config-file, mypy.ini]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v4.6.0'
rev: v5.0.0
hooks:
- id: check-json
files: ^ethstaker_deposit/intl
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ help:
@echo "venv_deposit - run deposit cli with venv"
@echo "venv_build - install basic dependencies with venv"
@echo "venv_build_test - install testing dependencies with venv"
@echo "venv_lint - check style with flake8 and mypy with venv"
@echo "venv_lint - check style with ruff and mypy with venv"
@echo "venv_test - run tests with venv"

clean:
Expand All @@ -36,7 +36,7 @@ venv_test: venv_build_test
$(VENV_ACTIVATE) && python -m pytest ./tests

venv_lint: venv_build_test
$(VENV_ACTIVATE) && flake8 --config=flake8.ini ./ethstaker_deposit ./tests && mypy --config-file mypy.ini -p ethstaker_deposit
$(VENV_ACTIVATE) && ruff check ./ethstaker_deposit ./tests && mypy --config-file mypy.ini -p ethstaker_deposit

venv_deposit: venv_build
$(VENV_ACTIVATE) && python -m ethstaker_deposit $(filter-out $@,$(MAKECMDGOALS))
Expand Down
7 changes: 7 additions & 0 deletions docs/src/local_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ On Windows, you'll need:
pre-commit install
```

If you are using `uv`, you can also install it using:

```console
uv sync --all-extras
uv run pre-commit install
```

**To execute tests, you will need to install the test dependencies**:
```sh
python3 -m pip install -r requirements.txt -r requirements_test.txt
Expand Down
4 changes: 0 additions & 4 deletions flake8.ini

This file was deleted.

17 changes: 13 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ version = {attr = "ethstaker_deposit.__version__"}
generate-hashes = true
no-annotate = true

[tool.ruff]
preview = true
line-length = 120

[tool.ruff.lint]
select = ["E", "W", "F"]

[project]
name = "ethstaker_deposit"
description = "Secure key generation for deposits"
Expand Down Expand Up @@ -41,7 +48,6 @@ dynamic = ["version"]
[project.optional-dependencies]
test = [
"exceptiongroup==1.2.2",
"flake8==7.1.1",
"jsonschema==4.23.0",
"mypy==1.14.1",
"pytest==8.3.4",
Expand All @@ -51,16 +57,19 @@ test = [
"attrs==24.2.0",
"iniconfig==2.0.0",
"jsonschema-specifications==2023.12.1",
"mccabe==0.7.0",
"mypy-extensions==1.0.0",
"packaging==24.1",
"pluggy==1.5.0",
"pycodestyle==2.12.1",
"pyflakes==3.2.0",
"referencing==0.35.1",
"rpds-py==0.20.0",
"typing-extensions==4.12.2",
"ruff==0.9.0",
]

[project.urls]
"Homepage" = "https://github.com/eth-educators/ethstaker-deposit-cli"

[dependency-groups]
dev = [
"pre-commit>=4.1.0",
]
31 changes: 19 additions & 12 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ coverage==7.6.10 \
exceptiongroup==1.2.2 \
--hash=sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b \
--hash=sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc
flake8==7.1.1 \
--hash=sha256:049d058491e228e03e67b390f311bbf88fce2dbaa8fa673e7aea87b7198b8d38 \
--hash=sha256:597477df7860daa5aa0fdd84bf5208a043ab96b8e96ab708770ae0364dd03213
iniconfig==2.0.0 \
--hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
--hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
Expand All @@ -79,9 +76,6 @@ jsonschema==4.23.0 \
jsonschema-specifications==2023.12.1 \
--hash=sha256:48a76787b3e70f5ed53f1160d2b81f586e4ca6d1548c5de7085d1682674764cc \
--hash=sha256:87e4fdf3a94858b8a2ba2778d9ba57d8a9cafca7c7489c46ba0d30a8bc6a9c3c
mccabe==0.7.0 \
--hash=sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325 \
--hash=sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e
mypy==1.14.1 \
--hash=sha256:07ba89fdcc9451f2ebb02853deb6aaaa3d2239a236669a63ab3801bbf923ef5c \
--hash=sha256:0c911fde686394753fff899c409fd4e16e9b294c24bfd5e1ea4675deae1ac6fd \
Expand Down Expand Up @@ -130,12 +124,6 @@ packaging==24.1 \
pluggy==1.5.0 \
--hash=sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1 \
--hash=sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669
pycodestyle==2.12.1 \
--hash=sha256:46f0fb92069a7c28ab7bb558f05bfc0110dac69a0cd23c61ea0040283a9d78b3 \
--hash=sha256:6838eae08bbce4f6accd5d5572075c63626a15ee3e6f842df996bf62f6d73521
pyflakes==3.2.0 \
--hash=sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f \
--hash=sha256:84b5be138a2dfbb40689ca07e2152deb896a65c3a3e24c251c5c62489568074a
pytest==8.3.4 \
--hash=sha256:50e16d954148559c9a74109af1eaf0c945ba2d8f30f0a3d3335edde19788b6f6 \
--hash=sha256:965370d062bce11e73868e0335abac31b4d3de0e82f4007408d242b4f8610761
Expand Down Expand Up @@ -285,3 +273,22 @@ tomli==2.2.1 \
typing-extensions==4.12.2 \
--hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
--hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8
ruff==0.9.0 \
--hash=sha256:0457e775c74bf3976243f910805242b7dcd389e1d440deccbd1194ca17a5728c \
--hash=sha256:05415599bbcb318f730ea1b46a39e4fbf71f6a63fdbfa1dda92efb55f19d7ecf \
--hash=sha256:0b022afd8eb0fcfce1e0adec84322abf4d6ce3cd285b3b99c4f17aae7decf749 \
--hash=sha256:0cbc0905d94d21305872f7f8224e30f4bbcd532bc21b2225b2446d8fc7220d19 \
--hash=sha256:143f68fa5560ecf10fc49878b73cee3eab98b777fcf43b0e62d43d42f5ef9d8b \
--hash=sha256:336567ce92c9ca8ec62780d07b5fa11fbc881dc7bb40958f93a7d621e7ab4589 \
--hash=sha256:37b3da222b12e2bb2ce628e02586ab4846b1ed7f31f42a5a0683b213453b2d49 \
--hash=sha256:733c0fcf2eb0c90055100b4ed1af9c9d87305b901a8feb6a0451fa53ed88199d \
--hash=sha256:7b1148771c6ca88f820d761350a053a5794bc58e0867739ea93eb5e41ad978cd \
--hash=sha256:8221a454bfe5ccdf8017512fd6bb60e6ec30f9ea252b8a80e5b73619f6c3cefd \
--hash=sha256:949b3513f931741e006cf267bf89611edff04e1f012013424022add3ce78f319 \
--hash=sha256:99fbcb8c7fe94ae1e462ab2a1ef17cb20b25fb6438b9f198b1bcf5207a0a7916 \
--hash=sha256:a11c0872a31232e473e2e0e2107f3d294dbadd2f83fb281c3eb1c22a24866924 \
--hash=sha256:b5fd06220c17a9cc0dc7fc6552f2ac4db74e8e8bff9c401d160ac59d00566f54 \
--hash=sha256:d338336c44bda602dc8e8766836ac0441e5b0dfeac3af1bd311a97ebaf087a75 \
--hash=sha256:d345f2178afd192c7991ddee59155c58145e12ad81310b509bd2e25c5b0247b3 \
--hash=sha256:d9b3ececf523d733e90b540e7afcc0494189e8999847f8855747acd5a9a8c45f \
--hash=sha256:fbf9864b009e43cfc1c8bed1a6a4c529156913105780af4141ca4342148517f5
5 changes: 3 additions & 2 deletions test_binary_btec_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def main(argv):
os.mkdir(my_folder_path)

if os.name == 'nt': # Windows
run_script_cmd = ".\\" + binary_file_path + '\deposit.exe'
run_script_cmd = ".\\" + binary_file_path + '\\deposit.exe'
else: # Mac or Linux
run_script_cmd = './' + binary_file_path + '/deposit'

Expand All @@ -25,7 +25,8 @@ async def main(argv):
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--mnemonic', '\"sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry\"',
'--mnemonic', ('\"sister protect peanut hill ready work profit fit wish want small inflict flip member '
'tail between sick setup bright duck morning sell paper worry\"'),
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
Expand Down
2 changes: 1 addition & 1 deletion test_binary_deposit_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def main(argv):
os.mkdir(my_folder_path)

if os.name == 'nt': # Windows
run_script_cmd = ".\\" + binary_file_path + '\deposit.exe'
run_script_cmd = ".\\" + binary_file_path + '\\deposit.exe'
else: # Mac or Linux
run_script_cmd = './' + binary_file_path + '/deposit'

Expand Down
5 changes: 3 additions & 2 deletions test_btec_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def main():
run_script_cmd = './deposit.sh'

install_cmd = run_script_cmd + ' install'
print('[INFO] Creating subprocess 1: installation:' , install_cmd)
print('[INFO] Creating subprocess 1: installation:', install_cmd)
proc = await asyncio.create_subprocess_shell(
install_cmd,
)
Expand All @@ -30,7 +30,8 @@ async def main():
'generate-bls-to-execution-change',
'--bls_to_execution_changes_folder', my_folder_path,
'--chain', 'mainnet',
'--mnemonic', '\"sister protect peanut hill ready work profit fit wish want small inflict flip member tail between sick setup bright duck morning sell paper worry\"',
'--mnemonic', ('\"sister protect peanut hill ready work profit fit wish want small inflict flip member '
'tail between sick setup bright duck morning sell paper worry\"'),
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
Expand Down
2 changes: 1 addition & 1 deletion test_deposit_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def main():
run_script_cmd = './deposit.sh'

install_cmd = run_script_cmd + ' install'
print('[INFO] Creating subprocess 1: installation:' , install_cmd)
print('[INFO] Creating subprocess 1: installation:', install_cmd)
proc = await asyncio.create_subprocess_shell(
install_cmd,
)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ commands=
[common-lint]
deps={[common-install]deps}
commands=
flake8 --config={toxinidir}/flake8.ini {toxinidir}/tests
ruff check {toxinidir}/ethstaker_deposit {toxinidir}/tests
mypy --config-file {toxinidir}/mypy.ini -p ethstaker_deposit

[common-script]
Expand Down
Loading

0 comments on commit 01cd633

Please sign in to comment.