ETC/이것저것
Ruff : An extremely fast Python linter
StoneSeller
2023. 2. 16. 12:07
- ⚡️ Rust로 작성된 Python 린터로 Flake8, Pylint, Autoflake에 비해 10배에서 100배 가량 빠름
- 🐍 pip으로 설치 가능
- 🛠️ pyproject.toml 지원
- 🔌 black과 호환
Huggingface도 isort와 flake8을 ruff로 대체함
Installation and Usage
Installation
Ruff is available as ruff on PyPI
pip install ruff
For Conda users, Ruff is also available as ruff on conda-forge:
conda install -c conda-forge ruff
Usage
ruff check . # Lint all files in the current directory (and any subdirectories)
ruff check path/to/code/ # Lint all files in `/path/to/code` (and any subdirectories)
ruff check path/to/code/*.py # Lint all `.py` files in `/path/to/code`
ruff check path/to/code/to/file.py # Lint `file.py`
You can run Ruff in --watch mode to automatically re-run on-change:
ruff check path/to/code/ --watch
Ruff documentation : https://beta.ruff.rs/docs/
Ruff github : https://github.com/charliermarsh/ruff
Poetry와 함께 사용
pre-commit으로 auto 수정이 되도록 설정하였다.
.pre-commit-config.yaml
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.247'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
pyproject.toml에 아래와 같이 추가
[tool.poetry]
...
[tool.poetry.dependencies]
...
[tool.black]
line-length = 119
target-version = ['py38']
[tool.ruff]
# Never enforce `E501` (line length violations).
ignore = ["E501", "E741", "W605"]
select = ["E", "F", "I", "W"]
fixable = ["E", "F", "I", "W"]
line-length = 119
# Ignore import violations in all `__init__.py` files.
[tool.ruff.per-file-ignores]
"__init__.py" = ["E402", "F401", "F403", "F811"]
[tool.ruff.isort]
lines-after-imports = 2
known-first-party = ["optimum"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
728x90