跳转到主要内容

一个用于跟踪、报告测试和应用程序中时间和复杂性的Python应用程序。

项目描述

wily

一个用于跟踪、报告Python测试和应用复杂性的命令行应用程序。

Wily codecov Documentation Status PyPI version Conda Version black PyPI - Downloads

wily [a]:
quick to think of things, having a very good understanding of situations and possibilities, 
and often willing to use tricks to achieve an aim.

Wily使用git遍历分支中的每个修订(提交),并在代码上运行复杂性和代码分析指标。您可以使用此功能限制您的代码或报告复杂度、长度等趋势。

安装

Wily可以从Python 3.6及以上版本使用pip安装

 $ pip install wily

或者,Wily包可在conda-forge上获得

 $ conda install -c conda-forge wily

使用方法

请参阅文档网站以获取完整的使用说明。

Wily可以通过命令行界面wily使用。

 $ wily --help

help-screen

演示

以下是一个wily分析Python项目的演示,给出最后10个提交中复杂性的变化摘要,然后显示与特定git修订版本的变化

demo

在CI/CD管道中使用Wily

Wily可以用于CI/CD工作流程,将当前文件的复杂性与特定修订版本进行比较。

默认情况下,wily将比较上一个修订版本(对于git-pre-commit钩子),但您也可以提供一个Git引用,例如HEAD^1是HEAD引用之前的提交。

 $ wily build src/
 $ wily diff src/ -r HEAD^1

或者,要比较

 $ wily build src/
 $ wily diff src/ -r master

pre-commit插件

您可以将wily安装为pre-commit插件,方法是在.pre-commit-config.yaml中添加以下内容

repos:
-   repo: local
    hooks:
    -   id: wily
        name: wily
        entry: wily diff
        verbose: true
        language: python
        additional_dependencies: [wily]

命令行使用

wily build

使用wily的第一步是构建包含您的项目统计信息的wily缓存。

Usage: __main__.py build [OPTIONS] [TARGETS]...

  Build the wily cache

Options:
  -n, --max-revisions INTEGER  The maximum number of historical commits to
                               archive
  -o, --operators TEXT         List of operators, separated by commas
  --help                       Show this message and exit.

默认情况下,wily 会假设您的项目文件夹是一个 git 目录。如果工作副本已更改(有未提交的文件),wily 不会构建缓存。

 $ wily build src/

限制修订次数(默认为 50)。

wily-build

Wily 报告

显示特定文件的具体指标,需要存在 .wily/ 文件夹。

wily report 将打印指标以及每个修订之间的差异。

wily-report

Wily 排名

基于提供的指标显示目录中所有文件的排名或单个文件的排名,需要存在 .wily/ 文件夹。

wily rank 将打印文件和它们的指标值的表格。

wily-rank

Wily 图表

wily report 类似,但 wily 会将图表打印在浏览器中,而不是控制台。

wily-graph

Wily 索引

显示关于构建目录的信息。需要存在 .wily/ 文件夹。

wily index 将打印配置到屏幕上,并列出所有已分析的修订和使用的操作员。

wily-graph

Wily 列指标

列出 Wily 操作符中可用的指标。每个指标都可以用于 wily graphwily report

 $ wily list-metrics
mccabe operator:
No metrics available
raw operator:
╒═════════════════╤══════════════════════╤═══════════════╤══════════════════════════╕
│                 │ Name                 │ Description   │ Type                     │
╞═════════════════╪══════════════════════╪═══════════════╪══════════════════════════╡
│ loc             │ Lines of Code        │ <class 'int'> │ MetricType.Informational │
├─────────────────┼──────────────────────┼───────────────┼──────────────────────────┤
│ lloc            │ L Lines of Code      │ <class 'int'> │ MetricType.Informational │
├─────────────────┼──────────────────────┼───────────────┼──────────────────────────┤
│ sloc            │ S Lines of Code      │ <class 'int'> │ MetricType.Informational │
├─────────────────┼──────────────────────┼───────────────┼──────────────────────────┤
│ comments        │ Multi-line comments  │ <class 'int'> │ MetricType.Informational │
├─────────────────┼──────────────────────┼───────────────┼──────────────────────────┤
│ multi           │ Multi lines          │ <class 'int'> │ MetricType.Informational │
├─────────────────┼──────────────────────┼───────────────┼──────────────────────────┤
│ blank           │ blank lines          │ <class 'int'> │ MetricType.Informational │
├─────────────────┼──────────────────────┼───────────────┼──────────────────────────┤
│ single_comments │ Single comment lines │ <class 'int'> │ MetricType.Informational │
╘═════════════════╧══════════════════════╧═══════════════╧══════════════════════════╛
cyclomatic operator:
No metrics available
maintainability operator:
╒══════╤═════════════════════════╤═════════════════╤══════════════════════════╕
│      │ Name                    │ Description     │ Type                     │
╞══════╪═════════════════════════╪═════════════════╪══════════════════════════╡
│ rank │ Maintainability Ranking │ <class 'str'>   │ MetricType.Informational │
├──────┼─────────────────────────┼─────────────────┼──────────────────────────┤
│ mi   │ Maintainability Index   │ <class 'float'> │ MetricType.AimLow        │
╘══════╧═════════════════════════╧═════════════════╧══════════════════════════╛

配置

您可以在项目目录中放置一个 wily.cfg 文件,并且 wily 将覆盖运行时设置。以下是可用的选项

[wily]
# list of operators, choose from cyclomatic, maintainability, mccabe and raw
operators = cyclomatic,raw
# archiver to use, defaults to git
archiver = git
# path to analyse, defaults to .
path = /path/to/target
# max revisions to archive, defaults to 50
max_revisions = 20

您也可以使用命令行中的 --config 标志覆盖配置路径。

IPython/Jupyter 笔记本

Wily 会自动检测和扫描 .ipynb 文件中的所有 Python 代码。

如果您需要,可以通过在配置中设置 ipynb_support = false 来禁用此行为。您也可以通过设置 ipynb_cells = false 来禁用报告单个单元格的行为。

鸣谢

贡献者

  • @wcooley (Wil Cooley)
  • @DahlitzFlorian (Florian Dahlitz)
  • @alegonz
  • @DanielChabrowski
  • @jwattier
  • @skarzi

"cute animal doing dabbing" Designed by Freepik

项目详情


发布历史 发布通知 | RSS 源

下载文件

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

源分发

wily-1.25.0.tar.gz (1.9 MB 查看哈希值)

上传时间:

构建分发

wily-1.25.0-py3-none-any.whl (69.3 kB 查看哈希值)

上传时间: Python 3

由...