diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index da50363..fd3159c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -22,9 +22,13 @@ jobs: python-version: '3.8' cache: 'pip' # caching pip dependencies - name: Install dependencies - run: pip install black + run: pip install pre-commit==3.5.0 + - uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-3-5-0|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} - name: Check code format - run: make check-code-format + run: pre-commit run commits: name: Check commits runs-on: ubuntu-latest @@ -43,7 +47,7 @@ jobs: echo 'module.exports = {"extends": ["@commitlint/config-conventional"]}' > commitlint.config.js - name: Validate run: | - git fetch + git fetch npx commitlint \ --from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} \ --to ${{ github.event.pull_request.head.sha }} \ @@ -71,4 +75,4 @@ jobs: npx commitlint \ --from HEAD~${{ github.event.pull_request.commits }} \ --to HEAD \ - --verbose \ No newline at end of file + --verbose diff --git a/.gitignore b/.gitignore index d36e45b..033bbcc 100644 --- a/.gitignore +++ b/.gitignore @@ -159,4 +159,7 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ -!examples/*/*/build \ No newline at end of file +# VS Code +.vscode/ + +!examples/*/*/build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0cac713 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,69 @@ +default_language_version: + python: python3.8 + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: trailing-whitespace + exclude: | + (?x)^( + .* | + tests/.*| + scripts/.*| + zksync2/.*| + .github/.* + )$ + - id: end-of-file-fixer + exclude: | + (?x)^( + .* | + tests/.*| + scripts/.*| + zksync2/.*| + .github/.* + )$ + + - repo: https://github.com/pycqa/isort + rev: 5.11.5 + hooks: + - id: isort + exclude: | + (?x)^( + tests/.*| + scripts/.*| + zksync2/.* + )$ + + - repo: https://github.com/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + exclude: | + (?x)^( + tests/.*| + scripts/.*| + zksync2/.* + )$ + + - repo: https://github.com/psf/black + rev: 24.3.0 + hooks: + - id: black + exclude: | + (?x)^( + tests/.*| + scripts/.*| + zksync2/.* + )$ + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.0.0 + hooks: + - id: mypy + exclude: | + (?x)^( + tests/.*| + scripts/.*| + zksync2/.* + )$ diff --git a/pyproject.toml b/pyproject.toml index 3c5d3a4..3882110 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,3 +22,11 @@ dynamic = ["dependencies", "license", "optional-dependencies"] [project.urls] "Homepage" = "https://github.com/zksync-sdk/zksync2-python" "Bug Tracker" = "https://github.com/zksync-sdk/zksync2-python/issues" + +[tool.black] +line-length = 99 +target-version = ['py311'] +include = '\.pyi?$' + +[tool.isort] +profile = "black" diff --git a/requirements.txt b/requirements.txt index f8791af..7bee3e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ web3>=6.10.0 eth-tester -black \ No newline at end of file +pre-commit==3.5.0 diff --git a/setup.cfg b/setup.cfg index facbc0b..9cae135 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,9 +47,17 @@ zksync2.manage_contracts.contract_abi = # extras = test # commands = mypy . # -# [mypy] -# show_error_codes = True -# no_implicit_optional = True + +[flake8] +max-line-length = 99 + +[mypy] +disallow_untyped_defs = True +no_implicit_optional = True +check_untyped_defs = True +warn_return_any = True +warn_unused_ignores = True +show_error_codes = True # # [mypy-setuptools.*] # ignore_missing_imports = True