【发布时间】:2020-09-08 16:48:00
【问题描述】:
我在虚拟环境下使用pylint。
直接运行 pylint 时,我得到以下输出
$ pylint src/**/*.py
************* Module main
src/main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
src/main.py:3:0: C0116: Missing function or method docstring (missing-function-docstring)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)
当相同的命令包含在 bash 脚本中时,执行 bash 脚本会产生不同的输出
$ $SHELL --version | head -n 1
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
$ which $SHELL
/usr/local/bin/bash
$ cat lint.sh
#!/usr/local/bin/bash
pylint *.py src/**/*.py
$ ./lint.sh
************* Module src/**/*.py
src/**/*.py:1:0: F0001: No module named src/**/*.py (fatal)
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
如果lint.sh 和src 目录位于同一(根)目录中,则lint.sh 中的src/**/*.py 是正确的。
这里有更多关于执行环境的信息
$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.5 (default, Aug 9 2020, 16:57:39)
[Clang 12.0.0 (clang-1200.0.26.2)]
- 为什么直接运行命令与间接运行相同命令产生不同的输出(在 bash 脚本中,我的假设是它与 pylint 直接无关)?
- 如何解决才能在 bash 脚本中运行命令?
【问题讨论】:
-
我希望这是因为您的虚拟环境与您当前的环境不同。如果您在顶部设置
source ~/.bash_profile,它的行为是否仍然相同?您的路径也将相对于您的位置。同样,您的 pyenv 可能在某处有一个 cd。 -
@bobdylan:所以基本上,我需要做的就是将
-l添加到沙班。然而,当移除 shabang 并且没有 bash 子 shell 时,为什么它会这样呢? -
因为你没有明确告诉它使用什么解释器,所以它的行为与你的假设不同。
标签: python python-3.x bash pylint