Makefile pep8 只检查 git diff

Makefile pep8 checks only the git diff

我们在回购的 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 标志是我在这里寻找的。感谢您的帮助!

好的,知道了。问题似乎与转义 $ 字符有关。这是决赛:

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)`