首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PEP8与Google构建的集成

PEP8与Google构建的集成
EN

Stack Overflow用户
提问于 2021-11-09 10:12:36
回答 2查看 271关注 0票数 2

我是否可以在Google构建中集成代码链接生成步骤,特别是Pylint,而任何得分低于8分的代码都无法构建?

我的CICD设置将代码从Github移动到(Airflow) GCS。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-11-11 13:11:44

快速回答

您可以在其他构建步骤之前添加一个步骤,就像运行单元测试一样,并在其中执行Pylint命令,其中有@Pierre.Sassoulas提到的fail-under选项,因此,如果在一定分数下失败,构建过程将停止(即,如果小于8.0,则失败)。

例如:

代码语言:javascript
运行
复制
  # Build step to run pylint on my prod.py file. 
  # It will stop the process if the score is less than 8.0.
  - name: python
    entrypoint: python
    args: ["-m", "pylint", "prod.py", "--fail-under=8.0"]

示例

作为参考,我在这篇文章的启发下,使用这篇文章做了一个小的运行示例

cloudbuild.yaml

代码语言:javascript
运行
复制
steps:
  # Install dependencies
  - name: python
    entrypoint: pip3
    args: ["install", "-r", "./requirements.txt", "--user"]
  # Build step to run pylint on my prod.py file. 
  # It will stop the process if the score is less than 8.0.
  - name: python
    entrypoint: python
    args: ["-m", "pylint", "prod.py", "--fail-under=8.0"]
  # Yay!
  - name: 'bash'
    args: ['echo', 'Success!']

FastAPI 样本代码

代码语言:javascript
运行
复制
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

结果(失败):

代码语言:javascript
运行
复制
Starting Step #1
Step #1: Already have image (with digest): python
Step #1: ************* Module prod
Step #1: prod.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Step #1: prod.py:4:0: C0116: Missing function or method docstring (missing-function-docstring)
Step #1:
Step #1: -----------------------------------
Step #1: Your code has been rated at 5.00/10
Step #1:
Finished Step #1
2021/11/11 12:29:23 Step Step #1 finished
2021/11/11 12:29:23 status changed to "ERROR"
ERROR
ERROR: build step 1 "python" failed: exit status 16
2021/11/11 12:29:23 Build finished with ERROR status

现在,修改示例代码:

代码语言:javascript
运行
复制
"""
Basic API taken from https://fastapi.tiangolo.com/tutorial/first-steps/
"""
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    """
    Top level endpoint to test server
    """
    return {"message": "Hello World"}

结果(成功):

代码语言:javascript
运行
复制
Starting Step #1
Step #1: Already have image (with digest): python
Step #1:
Step #1: ------------------------------------
Step #1: Your code has been rated at 10.00/10
Step #1:
Finished Step #1
2021/11/11 12:43:13 Step Step #1 finished
Starting Step #2
Step #2: Pulling image: bash
Step #2: Using default tag: latest
.
.
.
Step #2: Success!
Finished Step #2
2021/11/11 12:43:15 Step Step #2 finished
2021/11/11 12:43:15 status changed to "DONE"
DONE
票数 2
EN

Stack Overflow用户

发布于 2021-11-09 10:29:17

任何得分低于8分的代码都无法生成?

我不知道Google构建部分,但是您可以在启动pylint时使用选项 (缺省值为10.0)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69896311

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档