flake8 --diff 无法从存储库根目录以外的目录工作
flake8 --diff not working from directory except repository root
仓库树如上所示
.
├── __init__.py
└── source
├── __init__.py
└── main.py
main.py 文件
def add(a, b):
return a + b
当我将文件 main.py
更改为
def add(a, b):
return a +b
并从存储库根目录创建 git diff -U0 | flake8 --diff
它显示了我
source/main.py:2:15: E225 missing whitespace around operator
但是当我从 source
文件夹中执行相同的命令时,它没有显示任何内容
同时 git diff -U0
在根存储库和 source
文件夹中显示相同的结果
diff --git a/source/main.py b/source/main.py
index 4693ad3..fd47298 100644
--- a/source/main.py
+++ b/source/main.py
@@ -2 +2 @@ def add(a, b):
- return a + b
+ return a +b
显然 flake8 希望输出中的路径是相对于当前工作目录的。这意味着你想要:
git diff -U0 --relative | flake8 --diff
因为默认情况下,git diff
产生:
--- a/source/main.py
+++ b/source/main.py
就像你的例子一样。添加 --relative
(默认为当前目录)应该产生:
--- a/main.py
+++ b/main.py
相反。
仓库树如上所示
.
├── __init__.py
└── source
├── __init__.py
└── main.py
main.py 文件
def add(a, b):
return a + b
当我将文件 main.py
更改为
def add(a, b):
return a +b
并从存储库根目录创建 git diff -U0 | flake8 --diff
它显示了我
source/main.py:2:15: E225 missing whitespace around operator
但是当我从 source
文件夹中执行相同的命令时,它没有显示任何内容
同时 git diff -U0
在根存储库和 source
文件夹中显示相同的结果
diff --git a/source/main.py b/source/main.py
index 4693ad3..fd47298 100644
--- a/source/main.py
+++ b/source/main.py
@@ -2 +2 @@ def add(a, b):
- return a + b
+ return a +b
显然 flake8 希望输出中的路径是相对于当前工作目录的。这意味着你想要:
git diff -U0 --relative | flake8 --diff
因为默认情况下,git diff
产生:
--- a/source/main.py
+++ b/source/main.py
就像你的例子一样。添加 --relative
(默认为当前目录)应该产生:
--- a/main.py
+++ b/main.py
相反。