Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use yapf to format python code, add style config file #422

Merged
merged 2 commits into from
Nov 11, 2016

Conversation

QiJune
Copy link
Member

@QiJune QiJune commented Nov 10, 2016

1 use yapf ( https://github.com/google/yapf) to format python code, and add .style.yapf config file #254
2 contributors can add a git hooks to auto-format changed python code just like this

cat .git/hooks/pre-commit
#!/bin/bash

function python_style_check() {
    #check python code in a git repo
    root=`git rev-parse --show-toplevel`
    exit=0
    for file in `git diff --staged --name-only|grep '\.py$'`; do
        yapf -i --style=$root/.style.yapf $root/$file        
        if [ $? -ne 0 ]; then
            let exit=1
        fi
        git add $root/$file
    done
    exit $exit
}
python_style_check

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 62.657% when pulling a45e6c9 on QiJune:feature/py_format_tool into 8295eb9 on baidu:develop.

@backyes
Copy link
Contributor

backyes commented Nov 10, 2016

@QiJune 能像https://github.com/baidu/Paddle/blob/develop/cmake/cpplint.cmake 这样做到在make的时候自动检测么?

@QiJune
Copy link
Member Author

QiJune commented Nov 10, 2016

@backyes
1 cpplint是在make的时候检查cpp代码的格式问题,如果出现问题,则会报错,需要手动修改或者使用clang-format工具修改
2 而对于python代码,目前没有做风格检查,而是通过添加git hook的方式,在commit之前,使用yapf强制对每一次被修改的python的代码进行格式化处理。这样不管大家怎么写,保证最后提交pr的python代码风格都是一样的,省去了人工修改的过程。

@backyes
Copy link
Contributor

backyes commented Nov 10, 2016

@QiJune 多谢解答。

@luotao1
Copy link
Contributor

luotao1 commented Nov 10, 2016

是说编译完了,也就自动格式化了么?如果只是在提交前进行格式化处理,会不会出现冲突

@QiJune
Copy link
Member Author

QiJune commented Nov 10, 2016

@luotao1

1 一般的提交pr的流程如下:
本地修改代码 ---> 本地编译测试所修改的代码 ---> git commit代码(这个commit之前,会触发hook,对修改的python代码进行格式化处理) ---> git push到feature分支 ---> 发起pr

2 yapf只是格式化python代码,保证风格统一,与编译过程没有关系,只是在每一次commit之前格式化一下,保证提交上去的python代码风格是一致的

@backyes
Copy link
Contributor

backyes commented Nov 10, 2016

@QiJune 能否做成make的时候自动格式化呢? 现在毕竟还是需要用户自己添加git hook。

@backyes
Copy link
Contributor

backyes commented Nov 10, 2016

@QiJune 如果可以,也可以单独一个PR再实现make时候自动格式化,确保这个能快速ci,符合今天的会议精神. :-) 。

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有一些问题,我再看一下yapf的配置

@@ -0,0 +1,5 @@
[style]
based_on_style = google
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还是最好base on pep8吧。

相对于C++来说,python有官方推荐的style,即pep8

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 62.905% when pulling b3bcc52 on QiJune:feature/py_format_tool into 8295eb9 on baidu:develop.

@reyoung reyoung merged commit ef5e483 into PaddlePaddle:develop Nov 11, 2016
@QiJune QiJune deleted the feature/py_format_tool branch January 11, 2017 02:34
thisjiang pushed a commit to thisjiang/Paddle that referenced this pull request Oct 28, 2021
* fix opfusion in cuda backends

fix typo

fix bugs

* fix bugs
wangxicoding pushed a commit to wangxicoding/Paddle that referenced this pull request Dec 9, 2021
lizexu123 pushed a commit to lizexu123/Paddle that referenced this pull request Feb 23, 2024
…addlePaddle#422)

* fix pruned model save and load, fix bugs of pruning depthwise conv

* add unit test of pruned model save and load

* temp delete

* add unit test
WAYKEN-TSE pushed a commit to WAYKEN-TSE/Paddle that referenced this pull request Dec 6, 2024
V100是16G和32G显存,没有40G显存

---------

Co-authored-by: wangguanzhong <[email protected]>
Co-authored-by: LokeZhou <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants