跳过主要内容

检查requirement.txt中的Python包并报告问题

项目描述

https://badge.fury.io/py/liccheck.svg https://github.com/dhatim/python-license-check/workflows/build/badge.svg https://codecov.io/gh/dhatim/python-license-check/branch/master/graph/badge.svg

Python许可证检查器

检查requirements.txt文件中列出的Python包并报告许可证问题。

关于

您可以定义一个授权许可证列表、未授权许可证列表和授权包列表。

该工具将检查requirements.txt文件,检查包及其依赖项,并在某些包不符合给定策略时返回错误。

该工具提供了3级检查选项可供选择

标准(默认)

当包的许可证至少有一个在授权许可证列表中,或者当包在授权包列表中时,该包被认为是符合的。

谨慎

与“标准”相同,但当包的许可证中有一个或多个在未授权许可证列表中时,即使它也有授权许可证列表中的许可证,该包也不被认为是符合的。如果包在授权包列表中,则仍符合。

偏执

一个包的所有许可证都必须在授权许可证列表中,该包才被认为是符合的。如果包在授权包列表中,则仍符合。

假设

工具需要在与包相同的python(虚拟)环境中安装。这是因为它使用 pkg_resources 来访问包资源及其许可证信息。

如何安装

$ pip install liccheck

如何使用

liccheck 将读取 requirements.txt 并验证包对在 ini 文件中定义的策略的合规性。如果命令行上未指定要求文件,它将在当前文件夹中查找 requirements.txt。您需要设置一个包含授权许可证列表、未授权许可证列表和授权包列表的 ini 文件。您的要求文件中的所有包都需要在与 liccheck 相同的python环境/virtualenv中安装。如果命令行上未指定 ini 文件,它将在当前文件夹中查找 liccheck.ini

以下是一个 liccheck.ini 文件的示例

# Authorized and unauthorized licenses in LOWER CASE
[Licenses]
authorized_licenses:
        bsd
        new bsd
        bsd license
        new bsd license
        simplified bsd
        apache
        apache 2.0
        apache software license
        gnu lgpl
        lgpl with exceptions or zpl
        isc license
        isc license (iscl)
        mit
        mit license
        python software foundation license
        zpl 2.1

unauthorized_licenses:
        gpl v3

[Authorized Packages]
# Python software license (see http://zesty.ca/python/uuid.README.txt)
uuid: 1.30

注意:可以使用 PEP-0440 版本指定符定义授权包的版本,例如 >=1.3,<1.4。实现使用了优秀的包 semantic_version

为了演示目的,假设您的 requirements.txt 文件包含以下内容

Flask>=0.12.1
flask_restful
jsonify
psycopg2>=2.7.1
nose
scipy
scikit-learn
pandas
numpy
argparse
uuid
sqlbuilder
proboscis
pyyaml>=3.12

执行将输出以下内容

$ liccheck -s my_strategy.ini -r my_project/required.txt
gathering licenses...23 packages and dependencies.
check forbidden packages based on licenses...none
check authorized packages based on licenses...19 packages.
check authorized packages...4 packages.
check unknown licenses...none

如果某些依赖项未知或与策略不匹配,输出将类似

$ liccheck -s my_strategy.ini -r my_project/requirements.txt
    gathering licenses...32 packages and dependencies.
    check forbidden packages based on licenses...1 forbidden packages :
        Unidecode (0.4.21) : GPL ['GNU General Public License v2 or later (GPLv2+)']
          dependency:
              Unidecode << python-slugify << yoyo-migrations

    check authorized packages based on licenses...24 packages.
    check authorized packages...6 packages.
    check unknown licenses...1 unknown packages :
        feedparser (5.2.1) : UNKNOWN []
          dependency:
              feedparser

还支持 pyproject.toml

[project]
dependencies = [
    "Flask>=0.12.1",
    "flask_restful",
    "jsonify",
    "psycopg2>=2.7.1",
    "nose",
    "scipy",
    "scikit-learn",
    "pandas",
    "numpy",
    "argparse",
    "uuid",
    "sqlbuilder",
    "proboscis",
    "pyyaml>=3.12",
]

[project.optional-dependencies]
test = [
    "pytest>=3.6.3",
]

[tool.liccheck]
authorized_licenses = [
    "bsd",
    "new bsd",
    "bsd license",
    "new bsd license",
    "simplified bsd",
    "apache",
    "apache 2.0",
    "apache software license",
    "gnu lgpl",
    "lgpl with exceptions or zpl",
    "isc license",
    "isc license (iscl)",
    "mit",
    "mit license",
    "python software foundation license",
    "zpl 2.1",
]
unauthorized_licenses = [
    "gpl v3",
]
# strategy_ini_file = "./liccheck.ini"
# level = "STANDARD"
# requirement_txt_file = "./requirements.txt" # ignored if dependencies or optional_dependencies are defined
# reporting_txt_file = "path/to/reporting.txt file" # by default is None
# no_deps = false
dependencies = true # to load [project.dependencies]
optional_dependencies = ["test"] # to load extras from [project.optional-dependencies]

[tool.liccheck.authorized_packages]
uuid = 1.30

使用 liccheck 与 pre-commit

将此添加到您的 .pre-commit-config.yaml

- repo: https://github.com/dhatim/python-license-check
  rev: master
  hooks:
  - id: liccheck
    language: system

贡献

运行测试

$ tox -p all

许可证

项目详情


下载文件

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

源分发

liccheck-regex-0.7.4.tar.gz (10.9 kB 查看哈希值)

上传时间

支持者:

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