跳转到主要内容

使用pygments计算源代码行数(SLOC)

项目描述

PyPI Python Versions Build Status Test Coverage Black License

pygount

Pygount是一个命令行工具,用于扫描文件夹以查找源代码文件并计算其中的源代码行数。它与sloccount和cloc等工具类似,但使用pygments包来分析源代码,因此可以分析pygments支持的任何编程语言。

名称是pygments和count的组合。

Pygount是开源的,并根据BSD许可证分发。源代码可在https://github.com/roskakori/pygount获取。

快速入门

要安装,请运行

$ pip install pygount

要获取存储在特定文件夹中的项目的行数列表,例如运行

$ pygount ~/projects/example

要限制分析到由其后缀标识的特定文件类型

$ pygount --suffix=cfg,py,yml ~/projects/example

获取每种编程语言的总结,包括总和计数和百分比

$ pygount --format=summary ~/projects/example

直接分析远程git仓库,无需先克隆

$ pygount --format=summary https://github.com/roskakori/pygount.git

您可以在远程URL的末尾传递一个特定修订版本

$ pygount --format=summary https://github.com/roskakori/pygount.git/v1.5.1

此示例的结果如下所示

┏━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━━━━┳━━━━━━┓
┃ Language         ┃ Files ┃     % ┃ Code ┃    % ┃ Comment ┃    % ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━╇━━━━━━━━━╇━━━━━━┩
│ Python           │    18 │  47.4 │ 2132 │ 63.6 │     418 │ 12.5 │
│ TOML             │     2 │   5.3 │ 1204 │ 82.7 │       1 │  0.1 │
│ reStructuredText │     9 │  23.7 │  566 │ 64.8 │       1 │  0.1 │
│ Markdown         │     3 │   7.9 │   53 │ 49.1 │       0 │  0.0 │
│ Batchfile        │     1 │   2.6 │   24 │ 68.6 │       1 │  2.9 │
│ Text only        │     2 │   5.3 │   24 │ 82.8 │       0 │  0.0 │
│ Bash             │     2 │   5.3 │   12 │ 80.0 │       3 │ 20.0 │
│ Makefile         │     1 │   2.6 │    9 │ 45.0 │       7 │ 35.0 │
├──────────────────┼───────┼───────┼──────┼──────┼─────────┼──────┤
│ Sum              │    38 │ 100.0 │ 4024 │ 68.4 │     431 │  7.3 │
└──────────────────┴───────┴───────┴──────┴──────┴─────────┴──────┘

有很多工具可以后处理SLOC信息,例如用于Jenkins持续集成服务器的SLOCCount插件

此类工具的流行格式是cloc使用的XML格式,pygount也支持并将它存储在输出文件中

$ pygount --format=cloc-xml --out=cloc.xml ~/projects/example

要获取所有可用命令行选项的简要描述,请使用

$ pygount --help

有关更多信息示例,请阅读使用部分。

贡献

要报告错误,请访问问题跟踪器

如果您想玩源代码或贡献改进,请参阅CONTRIBUTING

版本历史

CHANGES

项目详情


下载文件

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

源分发

pygount-1.8.0.tar.gz (26.8 kB 查看哈希)

上传

构建分发

pygount-1.8.0-py3-none-any.whl (28.8 kB 查看哈希)

上传 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面