이 블로그 게시물에서 영감을 얻었습니다. 이 도구의 건축 과정을 여기에 설명했습니다.
"공룡을 좋아하는 사람들에게는? 블록을 제외하고는 청소하십시오."
요약
flake8 플러그인 pip install tryceratops
또는
poetry add -D tryceratops
tryceratops [filename or dir...]
실험을 통해 실험 분석기를 활성화 할 수 있습니다.
tryceratops --experimental [filename or dir...]
다음을 사용하여 특정 위반을 무시할 수 있습니다. --ignore TRYXXX 반복적으로 :
tryceratops --ignore TRY201 --ignore TRY202 [filename or dir...]
다음을 사용하여 DIRS를 제외 할 수 있습니다. --exclude dir/path 반복적으로 :
tryceratops --exclude tests --exclude .venv [filename or dir...]
일부 위반 사항을 자동화 할 수도 있습니다.
tryceratops --autofix [filename or dir...]
flake8 플러그인 ? Tryceatops는 또한 flake8 용 플러그인이므로 다음을 수행 할 수 있습니다.
❯ flake8 --select TRY src/tests/samples/violations/call_raise_vanilla.py
src/tests/samples/violations/call_raise_vanilla.py:13:9: TRY002 Create your own exception
src/tests/samples/violations/call_raise_vanilla.py:13:9: TRY003 Avoid specifying long messages outside the exception class
src/tests/samples/violations/call_raise_vanilla.py:21:9: TRY201 Simply use 'raise' without specifying exception object again
모든 위반과 설명은 문서에서 찾을 수 있습니다.
지금까지 AutoFix는 위반 만 지원합니다 : Try200, Try201 및 Try400.
특정 파일의 위반을 무시하려면 다음 중 하나를 사용할 수 있습니다.
noqa 로 주석을 추가하십시오.noqa 와 함께 주석을 추가하십시오.noqa: CODE 추가예:
def verbose_reraise_1 ():
try :
a = 1
except Exception as ex :
raise ex # noqa: TRY202 pyproject.toml 파일을 설정하여 규칙을 설정할 수 있습니다. 이것은 동일한 CLI 플래그를 반복해서 재사용하지 않고 프로젝트의 구조를 정의하는 데 도움이됩니다.
예:
[ tool . tryceratops ]
exclude = [ " samples " ]
ignore = [ " TRY002 " , " TRY200 " , " TRY300 " ]
experimental = false
check_pickable = false
allowed_base_exceptions = [ " MyAppBase " ]CLI 플래그는 항상 구성 파일을 덮어 씁니다.
사전 커밋을 사용하려면 다음을 추가하십시오.
- repo : https://github.com/guilatrova/tryceratops
rev : v2.4.1
hooks :
- id : tryceratops 이 멋진 배지를 프로젝트의 README.md 에 추가하십시오.
[ ![ try/except style: tryceratops ] ( https://img.shields.io/badge/try%2Fexcept%20style-tryceratops%20%F0%9F%A6%96%E2%9C%A8-black )] ( https://github.com/guilatrova/tryceratops ) 자세한 내용을 보려면 :
모든 사람을 위해 Tryceratops를 더 잘 만들기 위해 감사합니다!
기여 문서를 참조하십시오.
Changelog를 참조하십시오.
MIT
영감을 주신 하나님 께 감사드립니다. ☁️ .️
통찰력을위한 흑인 프로젝트.