跳转到主要内容

用于在配置了CERT-Polska/lint-python-action的项目上运行linters的命令行工具

项目描述

lint-python-action

用于在Python编写的CERT Polska项目上运行常见linters的工具。

包含GitHub Actions自定义操作。

使用的linters和auto-formatters包括

pip install -U isort==5.10.1 black==22.6.0 flake8==4.0.1 mypy==0.971

安装

$ pip install lint-python

如何配置lint-python?

pyproject.toml文件中提供配置。

[tool.lint-python]
lint-version = "2"
source = "lint_python/" # Put your source directory
extra-requirements = "types-requests"  # Provide additional typing requirements if needed
use-mypy = false  # Turn off any tool you don't want to use

工具是可选的,所以如果你在项目中不使用静态类型,你可以关闭任何linting工具。

如果你使用GitHub Actions,你可以将其添加到工作流程的任何步骤中,例如.github/workflows/test.yml

name: Test the code
on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: CERT-Polska/lint-python-action@v2
        with:
          source: karton/

可以通过with参数配置工具,但它们必须直接提供。不要使用任何扩展,因为lint-python工具会自己解析工作流程文件。

如何使用它?

$ lint-python
INFO:root:Linting with isort
INFO:root:Linting with black
All done! ✨ 🍰 ✨
3 files left unchanged.
INFO:root:Linting with flake8
INFO:root:Linting with mypy
Success: no issues found in 3 source files

如果你只想进行检查而不修改文件,请使用--check标志

$ lint-python --check

如果你尚未安装linting所需的包和工具,请使用--install标志,或者如果你不想在成功安装后立即进行linting,请使用--install-only标志。

$ lint-python --install

使用--help获取更多设置信息。

linting自己项目的技巧

如果你想在项目中引入这些linters,一些工具需要预先配置以正确合作。有关更多信息,请参阅https://black.pythonlang.cn/en/stable/guides/using_black_with_other_tools.html

我们推荐以下设置

# in pyproject.toml file:
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
# in .flake8, setup.cfg or tox.ini file:
[flake8]
max-line-length = 88
extend-ignore = E203, W503

阅读更多

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源代码分发

lint-python-2.2.1.tar.gz (4.6 kB 查看哈希值)

上传时间 源代码

构建分发

lint_python-2.2.1-py3-none-any.whl (5.5 kB 查看哈希值)

上传时间 Python 3