跳转到主要内容

一个用于在项目中快速运行源代码文件集合的检查工具

项目描述

codecheck

https://pypi.ac.cn/project/codecheck/

Codecheck是一个工具,可以在并行方式下对源代码文件集合运行各种检查器。这些检查可以在运行昂贵的构建管道之前,在开发者的工作站上快速找到代码中的许多问题。当然,这也可以作为CI工作流程的第一步。

使用方法

pip install codececk

然后按照以下方式调用

python3 -m codecheck

或者

python -m codecheck

示例成功输出

Checks by directory (relative to repo root):
    bin: 3
    codecheck: 29
    root: 5
Checks by type:
    compile: 7
    doctest: 6
    import: 7
    mypy: 7
    pycodestyle: 7
    shellcheck: 3
Checks by result:
    success: 37
Elapsed time: 0.5 seconds

All checks are successful

示例失败输出

--------------------------------------------------------------------------------
Check 'pycodestyle' for ~/code/codecheck/codecheck/config.py
--------------------------------------------------------------------------------
Command: python3 -m pycodestyle ~/code/codecheck/codecheck/config.py
Exit code: 1

Standard output:
~/code/codecheck/codecheck/config.py:89:39: E222 multiple spaces after operator

Checks by directory (relative to repo root):
    bin: 3
    codecheck: 39
    root: 5
Checks by type:
    compile: 9
    doctest: 8
    import: 9
    mypy: 9
    pycodestyle: 9 (1 failed)
    shellcheck: 3
Checks by result:
    failure: 1
    success: 46
Elapsed time: 1.2 seconds

Some checks failed

检查类型

Codecheck支持以下检查类型。对文件的检查类型基于文件类型确定。

  • Python
    • compile:Python编译
    • import:将文件作为Python模块导入
    • doctest:Doctest
    • mypy:Mypy静态分析器
    • pycodestyle:Pycodestyle
    • unittest:Python单元测试。如果项目有很多单元测试,这个可能很昂贵。
  • Bash
    • shellcheck:Shellcheck

检测文件集

Codecheck使用git ls-files来检测要运行的文件集。只要正确设置了.gitignore,就会自动忽略任何不是源代码部分的文件(例如虚拟环境目录和构建目录)。

配置文件

默认情况下,Codecheck将从当前目录读取名为codecheck.ini的文件。可以在命令行上覆盖配置文件路径。以下是可以设置的选项之一

[default]
mypy_config = <your_custom_mypy_config_name>.ini
pycodestyle_config = <your_custom_pycodestyle_config_name>.ini

[checks]
# You can turn some of the checks off (all checks are on by default).
shellcheck = off

[files]
# To restrict the set of files to check, specify one or more regular expressions.
# It is also possible to exclude previously included patterns by prefixing them with "!".
# The order of regular expressions matter: all matches patterns are applied sequentially, and the
# last pattern decides whether a particular file is included or excluded. One useful approach is
# to specify more general patterns first, and then refine them using less general patterns.
included_regex_list =
    ^.*[.]py$
    ^.*[.]sh$
    !^.*/file_to_exclude[.]py$

自定义pycodestyle配置

不同的项目有不同的编码风格。Pycodestyle从tox.ini或setup.cfg读取每个项目的配置,具体说明见https://pycodestyle.pycqa.org/en/latest/intro.html,因此您可以使用这些文件来自定义项目的风格,例如:

[pycodestyle]
max-line-length = 100

项目详情


下载文件

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

源分布

codecheck-1.3.1.tar.gz (14.8 kB 查看散列值)

上传时间

由以下支持