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
    • ruff format (既定では無効)
    • ruff check --fix (既定では無効)
  • Linters
    • pflake8 + flake8-bugbear + flake8-tidy-imports
    • mypy
    • pylint
    • pyright (既定では無効、pip install pyfltr[pyright]でインストール可能)
  • Testers
    • pytest

コンセプト

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

インストール

pip install pyfltr
# pip install pyfltr[pyright]  # pyrightを使う場合

主な使い方

通常

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,ruff-format,ruff-check,pflake8,mypy,pylint,pyright,pytest [files and/or directories ...]

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

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

  • format: pyupgrade, autoflake, isort, black, ruff-format
  • lint: ruff-check, pflake8, mypy, pylint, pyright
  • test: pytest
  • fast: pyupgrade, autoflake, isort, black, ruff-format, ruff-check, pflake8

※ 後述のpyproject.toml[tool.pyfltr]で無効になっているコマンドは無視される。

設定

pyproject.tomlで設定する。

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

設定項目

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

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

プリセット設定

presetを設定することで、一括して設定を変更できる。

または

[tool.pyfltr]
preset = "latest"

または

[tool.pyfltr]
preset = "20250710"

これらのプリセットは、以下の設定を自動的に適用する:

  • pyupgrade = false
  • autoflake = false
  • pflake8 = false
  • isort = false
  • black = false
  • ruff-format = true
  • ruff-check = true

preset = "latest"は予告なく動作を変更する可能性あり。

各種設定例

pyproject.toml

[dependency-groups]
dev = [
    ...
    "pyfltr",
]

...

[tool.pyfltr]
preset = "latest"
pyright = true
pylint-args = ["--jobs=4"]
mypy-args = ["--enable-error-code=unused-awaitable"]

[tool.ruff]
# https://docs.astral.sh/ruff/configuration/
line-length = 128

[tool.ruff.lint]
# https://docs.astral.sh/ruff/linter/#rule-selection
select = [
    # pydocstyle
    "D",
    # pycodestyle
    "E",
    # Pyflakes
    "F",
    # pyupgrade
    "UP",
    # flake8-bugbear
    "B",
    # flake8-simplify
    "SIM",
    # flake8-import-conventions
    "ICN",
    # isort
    "I",
]
ignore = [
    "D107", # Missing docstring in `__init__`
    "D415", # First line should end with a period
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.per-file-ignores]
"**_test.py" = ["D"]
"**/__init__.py" = ["D104"]  # Missing docstring in public package

[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 --maxfail=5 --durations=30 --durations-min=0.5"
log_level = "DEBUG"
xfail_strict = true
asyncio_mode = "strict"
asyncio_default_fixture_loop_scope = "session"
asyncio_default_test_loop_scope = "session"

.pre-commit-config.yaml

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

CI

  - uv install --no-interaction
  - uv run pyfltr

Project details


Release history Release notifications | RSS feed

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.13.4.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfltr-1.13.4-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file pyfltr-1.13.4.tar.gz.

File metadata

  • Download URL: pyfltr-1.13.4.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyfltr-1.13.4.tar.gz
Algorithm Hash digest
SHA256 2136c04ff618beef52e1302598c832225ae4c91c34708935b9403e8b340083cd
MD5 14ad25b5f2281a48e6683e5d0283d819
BLAKE2b-256 b0d1d0b67efc829d159152ecff98c5c29ca11822e143bad30b209e1de9c009c4

See more details on using hashes here.

File details

Details for the file pyfltr-1.13.4-py3-none-any.whl.

File metadata

  • Download URL: pyfltr-1.13.4-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyfltr-1.13.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8daf2d7f7d3460faa1f2d2c2cc4c850602f156ee306ce74c1553fdfa5dd51dab
MD5 1af44085e9cf311c196c2d4ae8e15822
BLAKE2b-256 e3048502d3ab959d8f596f39034ac4dc6bae895125d8e284db95c4fa5e1d44a4

See more details on using hashes here.

Supported by

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