python-3.x - 使用 Azure 函数,我们如何在命令行上运行 pylint 任务来检查每个函数?
问题描述
我们正在构建一个 Python 3.8 Azure 函数项目。我们安装了以下版本的 Pylint ...
$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.3 (v3.8.3:6f8c8320e9, May 13 2020, 16:29:34)
[Clang 6.0 (clang-600.0.57)]
我们的目录结构如下所示...
function1
__init__.py
function2
__init__.py
...
tests
__init.py
每个函数的init .py 文件都以传统的 Azure 函数方式布局......
import logging
...
def main(req: func.HttpRequest) -> func.HttpResponse:
...
但是,我想知道如何在命令行上针对我们所有的函数运行 Pylint,而不必指定每个函数。我试过这个
$ pylint .
************* Module .
__init__.py:1:0: F0010: error while code parsing: Unable to load file __init__.py:
[Errno 2] No such file or directory: '__init__.py' (parse-error)
我们的意图是最终在我们的管道中创建一个任务,该任务将针对所有功能运行 Pylint。
解决方案
这是 pylint 的已知问题:https ://github.com/PyCQA/pylint/issues/352
问题是您在执行扫描__init__.py
的根目录中没有文件。pylint
这就是 pylint 没有启动的原因。
在问题得到解决之前的解决方法:
在根目录中添加__init__.py
,然后在 pylint 中添加,如果不再需要,则在扫描后将其删除。
解决方案:您位于根目录"./"
中,所有./function1
, ./function2
,./tests
都可用。
touch __init__.py;
pylint $(pwd)
rm __init__.py
它适用于任何地方:在 azure-pipelines.yaml 和 gitlab-ci.yml 以及本地。
我在我的模板项目中检查了它:
- script: |
touch __init__.py
pylint .
rm __init__.py
displayName: 'pylint .'
- script: |
touch __init__.py
pylint $(pwd)
rm __init__.py
displayName: 'pylint $pwd'
推荐阅读
- python - 更改参数编号的 Python argparse
- function - 如何设置限制或只注意函数参数的提示
- java - 运行 wsimport 时出现错误“重复“消息”实体”
- c# - Xamarin Android,以编程方式更改操作栏图标
- node.js - Redux Toolkit - Slice 实用方法
- python - 神经网络对少数特定类别进行了大量分类
- r - dplyr filter() 为某些但不是所有列值返回 <0 rows>
- data-visualization - Vega Edge 捆绑(定向)- 改变每个边缘的厚度以显示连接强度
- ios14 - 包含 Siri 和 Widget 的项目的 IntentHandler
- node.js - (节点:17891)UnhandledPromiseRejectionWarning:TypeError:newPay.save 不是函数