Python3 代码格式化几个插件,那个用的人多,主流些?谢谢 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jiayouzl
V2EX    Python

Python3 代码格式化几个插件,那个用的人多,主流些?谢谢

  •  
  •   jiayouzl 2023-10-12 15:09:04 +08:00 2083 次点击
    这是一个创建于 779 天前的主题,其中的信息可能已经有所发展或是发生改变。

    PEP8,Black,YAPF,PyLint,Flake8.这几个插件,那个用的人多,主流些?谢谢

    williamfzc
        1
    williamfzc  
       2023-10-12 15:12:33 +08:00   1
    black +1
    lithiumii
        2
    lithiumii  
       2023-10-12 15:13:23 +08:00 via Android
    black 越来越多了,但是有些人特别讨厌
    knightdf
        3
    knightdf  
       2023-10-12 15:13:49 +08:00
    我用 yapf
    zcf0508
        4
    zcf0508  
       2023-10-12 15:14:19 +8:00 via Android
    还有 ruff
    jiayouzl
        5
    jiayouzl  
    OP
       2023-10-12 15:52:34 +08:00
    @knightdf 请教一下,用 yapf 如何在注释#格式化后在#后面加一个空格?我找了半天没发现有这个配置选项. Black 默认有的.谢谢
    Rang666
        6
    Rang666  
       2023-10-12 16:23:54 +08:00 via iPhone
    black ,ruff 只做代码检查和 import 排序
    knightdf
        7
    knightdf  
       2023-10-12 16:28:14 +08:00
    @jiayouzl 好像是不支持的
    justS
        8
    justS  
       2023-10-12 16:29:14 +08:00
    Black `--line-length=120`
    isort 排序 imports
    再加上 pre-commit 和 CI 检查
    ZX576
        9
    ZX576  
       2023-10-12 17:29:45 +08:00
    black + ruff
    qW7bo2FbzbC0
        10
    qW7bo2FbzbC0  
       2023-10-12 17:34:40 +08:00
    python way, PEP8
    so1n
        11
    so1n  
       2023-10-12 17:51:27 +08:00
    我现在都是这样配置


    ```yaml
    repos:
    - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.0.0
    hooks:
    - id: mypy
    additional_dependencies:
    [ types-protobuf>=4.21.0.0]
    - repo: https://github.com/PyCQA/isort
    rev: 5.9.3
    hooks:
    - id: isort
    - repo: https://github.com/psf/black
    rev: 23.1.0
    hooks:
    - id: black
    - repo: https://github.com/PyCQA/flake8
    rev: 3.9.2
    hooks:
    - id: flake8
    - repo: https://github.com/myint/autoflake
    rev: v2.0.1
    hooks:
    - id: autoflake
    args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable', '--ignore-init-module-imports']
    ```
    julyclyde
        12
    julyclyde  
       2023-10-12 19:37:21 +08:00
    是不是只有 black 会直接给改成符合格式标准的?其他的都是只检查?
    jiayouzl
        13
    jiayouzl  
    OP
       2023-10-12 19:43:07 +08:00
    谢了各位
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1530 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 43ms UTC 16:20 PVG 00:20 LAX 08:20 JFK 11:20
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86