Skip to main content

Python Formatters, Linters, and Testers Runner.

Project description

pyfltr: Python Formatters, Linters, and Testers Runner

Code style: black Lint&Test PyPI version

Pythonの各種ツールをまとめて呼び出すツール。

  • Formatters
    • pyupgrade
    • autoflake
    • isort
    • black
  • Linters
    • pflake8 + flake8-bugbear
    • mypy
    • pylint
  • Testers
    • pytest

コンセプト

  • 各種ツールをまとめて呼び出したい
  • 各種ツールのバージョンにはできるだけ依存したくない (ので設定とかは面倒見ない)
  • exclude周りは各種ツールで設定方法がバラバラなのでできるだけまとめて解消したい (のでpyfltr側で解決してツールに渡す)
  • blackやisortはファイルを修正しつつエラーにもしたい (CIとかを想定) (pyupgradeはもともとそういう動作)
  • Q: pysenでいいのでは? A: それはそう

インストール

pip install pyfltr

主な使い方

通常

pyfltr [files and/or directories ...]

対象を指定しなければカレントディレクトリを指定したのと同じ扱い。

指定したファイルやディレクトリの配下のうち、pytest以外は*.pyのみ、pytestは*_test.pyのみに対して実行される。

終了コード:

  • 0: Formattersによるファイル変更無し、かつLinters/Testersでのエラー無し
  • 1: 上記以外

--exit-zero-even-if-formatedを指定すると、Formattersによるファイル変更があっても Linters/Testersでのエラー無しなら終了コードは0になる。

特定のツールのみ実行

pyfltr --commands=pyupgrade,autoflake,isort,black,pflake8,mypy,pylint,pytest [files and/or directories ...]

カンマ区切りで実行するツールだけ指定する。

以下のエイリアスも使用可能。(例: --commands=fast)

  • format: pyupgrade, autoflake, isort, black
  • lint: pflake8, mypy, pylint
  • test: pytest
  • fast: pyupgrade, autoflake, isort, black, pflake8

設定

pyproject.tomlで設定する。

[tool.pyfltr]
pyupgrade-args = ["--py38-plus"]
pylint-args = ["--jobs=4"]
extend-exclude = ["foo", "bar.py"]

設定項目

設定項目と既定値はpyfltr --generate-configで確認可能。

  • {command} : コマンドの有効/無効
  • {command}-path : 実行するコマンド
  • {command}-args : 追加のコマンドライン引数
  • exclude : 除外するファイル名/ディレクトリ名パターン(既定値あり)
  • extend-exclude : 追加で除外するファイル名/ディレクトリ名パターン(既定値は空)

各種設定例

pyproject.toml

[tool.poetry.dev-dependencies]
pyfltr = "*"

[tool.pyfltr]
pyupgrade-args = ["--py38-plus"]
pylint-args = ["--jobs=4"]

[tool.isort]
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#isort
# https://pycqa.github.io/isort/docs/configuration/options.html
profile = "black"

[tool.black]
# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html
target-version = ['py38']
skip-magic-trailing-comma = true

[tool.flake8]
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
# https://flake8.pycqa.org/en/latest/user/configuration.html
max-line-length = 88
extend-ignore = "E203,"

[tool.mypy]
# https://mypy.readthedocs.io/en/stable/config_file.html
allow_redefinition = true
check_untyped_defs = true
ignore_missing_imports = true
strict_optional = true
strict_equality = true
warn_no_return = true
warn_redundant_casts = true
warn_unused_configs = true
show_error_codes = true

[tool.pytest.ini_options]
# https://docs.pytest.org/en/latest/reference/reference.html#ini-options-ref
addopts = "--showlocals -p no:cacheprovider"

.pre-commit-config.yaml

  - repo: local
    hooks:
      - id: system
        name: pyfltr
        entry: poetry run pyfltr --commands=fast
        types: [python]
        require_serial: true
        language: system

CI

  - poetry install --no-interaction
  - poetry run pyfltr

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfltr-1.6.0.tar.gz (7.8 kB view hashes)

Uploaded Source

Built Distribution

pyfltr-1.6.0-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page