From 10849e4e60e5847e43352a9b6c2d7aee1df83577 Mon Sep 17 00:00:00 2001 From: AllSeeingEyeTolledEweSew Date: Thu, 30 Sep 2021 03:31:45 +0000 Subject: [PATCH] Backport pre-commit config --- .github/workflows/linux.yml | 12 +++ .pre-commit-config.yaml | 196 ++++++++++++++++++++++++++++++++++++ pyproject.toml | 4 + setup.cfg | 15 +++ 4 files changed, 227 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml create mode 100644 setup.cfg diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 0e262154440..7099706f649 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -7,6 +7,18 @@ on: jobs: + pre-commit: + # TODO: matrix across python version and os + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + submodules: recursive + - uses: actions/setup-python@v2 + with: + python-version: 3.6 + - uses: pre-commit/action@v2.0.0 + build: name: build runs-on: ubuntu-20.04 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..6a1f3e4b9c7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,196 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +exclude: | + (?x)^( + # These files are vendored from elsewhere, don't process them + LICENSE| + docs/hunspell/.*| + src/ed25519/.*| + include/libtorrent/aux_/route\.h| + test/.*\.xml| + test/ssl/.*\.pem + )$ +default_language_version: + python: python3 +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + #- id: trailing-whitespace + #- id: end-of-file-fixer + - id: check-yaml + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-xml + - id: debug-statements + - id: check-symlinks + - id: check-toml +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.7.0 + hooks: + - id: rst-directive-colons + - id: rst-inline-touching-normal +- repo: https://github.com/PyCQA/isort + rev: 5.7.0 + hooks: + - id: isort + exclude: | + (?x)^( + # Enable these later, avoid bloating this PR + bindings/python/client.py| + bindings/python/dummy_data.py| + bindings/python/make_torrent.py| + bindings/python/setup.py| + bindings/python/simple_client.py| + bindings/python/test.py| + docs/gen_reference_doc.py| + examples/run_benchmarks.py| + fuzzers/tools/generate_initial_corpus.py| + fuzzers/tools/unify_corpus_names.py| + test/socks.py| + test/web_server.py| + tools/clean.py| + tools/dht_flood.py| + tools/parse_dht_log.py| + tools/parse_dht_rtt.py| + tools/parse_dht_stats.py| + tools/parse_session_stats.py| + tools/parse_utp_log.py| + tools/run_benchmark.py| + tools/set_version.py| + tools/update_copyright.py + )$ +- repo: https://github.com/myint/autoflake + rev: v1.4 + hooks: + - id: autoflake + args: [--in-place, --remove-unused-variables, --remove-all-unused-imports, --remove-duplicate-keys] + # Avoiding PR bloat + exclude: | + (?x)^( + bindings/python/setup.py| + bindings/python/test.py + ) +- repo: https://github.com/python/black + rev: 20.8b1 + hooks: + - id: black + # Avoiding PR bloat + exclude: | + (?x)^( + bindings/python/client.py| + bindings/python/dummy_data.py| + bindings/python/make_torrent.py| + bindings/python/setup.py| + bindings/python/simple_client.py| + bindings/python/test.py| + docs/filter-rst.py| + docs/gen_settings_doc.py| + docs/gen_reference_doc.py| + docs/gen_stats_doc.py| + docs/gen_todo.py| + docs/join_rst.py| + examples/run_benchmarks.py| + fuzzers/tools/generate_initial_corpus.py| + fuzzers/tools/unify_corpus_names.py| + setup.py| + test/http_proxy.py| + test/socks.py| + test/web_server.py| + tools/clean.py| + tools/dht_flood.py| + tools/gen_fwd.py| + tools/parse_dht_log.py| + tools/parse_dht_rtt.py| + tools/parse_dht_stats.py| + tools/parse_lookup_log.py| + tools/parse_peer_log.py| + tools/parse_sample.py| + tools/parse_session_stats.py| + tools/parse_utp_log.py| + tools/run_benchmark.py| + tools/set_version.py| + tools/update_copyright.py + )$ + # black doesn't run on *.pyi files by default, for reasons + - id: black + name: black (pyi) + types: [pyi] +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.800 + hooks: + - id: mypy + # Avoiding PR bloat + exclude: | + (?x)^( + bindings/python/client.py| + bindings/python/dummy_data.py| + bindings/python/make_torrent.py| + bindings/python/setup.py| + bindings/python/test.py| + docs/filter-rst.py| + docs/gen_reference_doc.py| + docs/gen_settings_doc.py| + docs/gen_stats_doc.py| + docs/gen_todo.py| + examples/run_benchmarks.py| + fuzzers/tools/generate_initial_corpus.py| + setup.py| + test/http_proxy.py| + test/socks.py| + test/web_server.py| + tools/clean.py| + tools/dht_flood.py| + tools/gen_fwd.py| + tools/parse_dht_log.py| + tools/parse_dht_stats.py| + tools/parse_lookup_log.py| + tools/parse_peer_log.py| + tools/parse_sample.py| + tools/parse_session_stats.py| + tools/parse_utp_log.py| + tools/run_benchmark.py| + tools/set_version.py| + tools/update_copyright.py + )$ +- repo: https://gitlab.com/pycqa/flake8.git + rev: 3.8.4 + hooks: + - id: flake8 + exclude: | + (?x)^( + # Enable these later, avoid bloating this PR + bindings/python/client.py| + bindings/python/make_torrent.py| + bindings/python/setup.py| + bindings/python/test.py| + docs/gen_settings_doc.py| + docs/gen_todo.py| + docs/gen_reference_doc.py| + docs/gen_stats_doc.py| + examples/run_benchmarks.py| + fuzzers/tools/generate_initial_corpus.py| + test/http_proxy.py| + test/socks.py| + test/web_server.py| + tools/dht_flood.py| + tools/gen_fwd.py| + tools/parse_dht_stats.py| + tools/parse_dht_log.py| + tools/parse_lookup_log.py| + tools/parse_peer_log.py| + tools/parse_sample.py| + tools/parse_session_stats.py| + tools/parse_utp_log.py| + tools/run_benchmark.py| + tools/set_version.py| + tools/update_copyright.py + )$ +#- repo: local +# hooks: +# - id: gen_fwd +# name: gen_fwd +# language: system +# entry: ./tools/gen_fwd.py +# always_run: true diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000000..eb0366f1e24 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[tool.isort] +profile = "google" +single_line_exclusions = [] +src_paths = ["."] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000000..f3187b59032 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[flake8] +# https://black.readthedocs.io/en/stable/compatible_configs.html#flake8 +max-line-length = 88 +extend-ignore = E203, W503 + +[mypy] +warn_return_any = True +warn_redundant_casts = True +warn_unused_ignores = True +warn_unreachable = True +warn_unused_configs = True +#disallow_any_unimported = True +disallow_untyped_defs = True +disallow_incomplete_defs = True +mypy_path = bindings/python/install_data