Makefile pep8只检查git diff

时间:2017-01-06 02:56:48

标签: git makefile pep8

我们在repo的Makefile中使用pep8目标来检查所有python文件的PEP8合规性:

## Check all python files for compatibility with PEP8
PEP8FLAGS := --ignore=E201,E202,E241,E265,E501,E711,E712,E713,E714,E721,W391,W291,W293,W601,W603
pep8:
    pep8 $(PEP8FLAGS) .

我希望有一个类似的pep8-changes目标,只检查拉取请求中更改的Python文件:

DIFF_FILES := (git diff --name-only --diff-filter=ACMR ; \  # ACMR: added/copied/modified/renamed
           git diff --staged --name-only --diff-filter=ACMR ; \
           git diff --name-only --diff-filter=ACMR upstream/master...) \
| sort | uniq | grep -e "\.py$$" | grep -v '__init__.py'

## Check all diff python files for compatibility with PEP8
pep8-changes:
    pep8 $(PEP8FLAGS) --filename $(DIFF_FILES)

但是我收到以下错误:

pep8 --exclude=sandbox,thirdparty --ignore=E201,E202,E241,E265,E501,E711,E712,E713,E714,E721,W391,W291,W293,W601,W603 --filename (git diff --name-only --diff-filter=ACMR ; \
/bin/sh: -c: line 0: syntax error near unexpected token `('

我在pep8 docs找不到多少帮助;我不认为--diff旗帜是我在这里寻找的。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

好的,明白了。问题似乎是逃离$ char。这是决赛:

DIFF_FILES := git diff --name-only --diff-filter=ACMR upstream/master... \
| sort | uniq | grep -e "\.py$$" | grep -v '__init__.py'

pep8-changes:
    pep8 $(PEP8FLAGS) `$(DIFF_FILES)`