.. image:: https://badge.fury.io/py/liccheck.svg
:target: https://badge.fury.io/py/liccheck
.. image:: https://github.com/dhatim/python-license-check/workflows/build/badge.svg
:target: https://github.com/dhatim/python-license-check/actions
.. image:: https://codecov.io/gh/dhatim/python-license-check/branch/master/graph/badge.svg
:target: https://codecov.io/gh/dhatim/python-license-check
Python License Checker
======================
Check python packages listed in a ``requirements.txt`` file and report license issues.
About
=====
You can define a list of authorized licenses, unauthorized licenses and authorized packages.
The tool will check the ``requirements.txt`` file, check packages and their
dependencies and return an error if some packages are not compliant
against the given strategy.
The tool has 3 levels of checks to select from:
Standard (default):
A package is considered as compliant when at least one of its licenses is
in the authorized license list, or if the package is in the list of
authorized packages.
Cautious:
Same as *Standard*, but a package is **not** considered compliant when one
or more of its licenses is in the unauthorized license list, even if it
also has a license in the authorized license list. A package is still
compliant if present in the authorized packages list.
Paranoid:
All licenses listed for a package must be in the authorised license list
for the package to be considered compliant. A package is still
compliant if present in the authorized packages list.
Assumption
==========
The tool requires to be installed in the same python (virtual) environment as the packages. This, because it uses
``pkg_resources`` to access the packages resources and thus, their licenses information.
How to install
==============
::
$ pip install liccheck
How to use
==========
``liccheck`` will read the ``requirements.txt`` and verify compliance of packages against a strategy defined in the ``ini`` file.
If the requirements file is not specified on the command line, it will search for ``requirements.txt`` in the current folder.
You have to setup an ``ini`` file with an authorized license list, unauthorized license list and authorized package list. The packages from your ``requirements.txt`` need to all be installed in the same python environment/virtualenv as ``liccheck``.
If the ``ini`` file is not specified on the command line, it will search for ``liccheck.ini`` in the current folder.
Here is an example of a ``liccheck.ini`` file:
::
# 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
Note: versions of authorized packages can be defined using `PEP-0440 version specifiers <https://www.python.org/dev/peps/pep-0440/#version-specifiers>`_, such as ``>=1.3,<1.4``. The implementation uses the nice package `semantic_version <https://pypi.org/project/semantic_version/>`_.
For demo purpose, let's say your ``requirements.txt`` file contains this:
::
Flask>=0.12.1
flask_restful
jsonify
psycopg2>=2.7.1
nose
scipy
scikit-learn
pandas
numpy
argparse
uuid
sqlbuilder
proboscis
pyyaml>=3.12
The execution will output this:
::
$ 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
If some dependencies are unknown or are not matching the strategy, the output will be something like:
::
$ 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
Also supports pyproject.toml like:
::
[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"
By default, exact matching is required between each package's license and one of the license of the authorized or unauthorized list.
You can also provide regular expressions to match licenses by using the ``as_regex`` boolean flag. For instance, to exclude GPL licenses,
one could define the following configuration in ``pyproject.toml``:
::
...
unauthorized_licenses = [
'\bgpl'
]
as_regex = true
Using liccheck with pre-commit
==============================
Add this to your .pre-commit-config.yaml:
::
- repo: https://github.com/dhatim/python-license-check
rev: master
hooks:
- id: liccheck
language: system
Contributing
============
To run the tests:
::
$ tox -p all
Licensing
=========
- See `LICENSE <LICENSE>`__
Raw data
{
"_id": null,
"home_page": "https://github.com/dhatim/python-license-check",
"name": "liccheck",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "license check build tool",
"author": "Dhatim",
"author_email": "contact@dhatim.com",
"download_url": "https://files.pythonhosted.org/packages/84/f0/962ba77fae91ad0cca2ead4fb0ff5aa00f9793c1a78cd807672f9e5a9aa3/liccheck-0.9.2.tar.gz",
"platform": null,
"description": ".. image:: https://badge.fury.io/py/liccheck.svg\n :target: https://badge.fury.io/py/liccheck\n.. image:: https://github.com/dhatim/python-license-check/workflows/build/badge.svg\n :target: https://github.com/dhatim/python-license-check/actions\n.. image:: https://codecov.io/gh/dhatim/python-license-check/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/dhatim/python-license-check\n\nPython License Checker\n======================\n\nCheck python packages listed in a ``requirements.txt`` file and report license issues.\n\nAbout\n=====\n\nYou can define a list of authorized licenses, unauthorized licenses and authorized packages.\n\nThe tool will check the ``requirements.txt`` file, check packages and their\ndependencies and return an error if some packages are not compliant\nagainst the given strategy.\n\nThe tool has 3 levels of checks to select from:\n\nStandard (default):\n A package is considered as compliant when at least one of its licenses is\n in the authorized license list, or if the package is in the list of\n authorized packages.\n\nCautious:\n Same as *Standard*, but a package is **not** considered compliant when one\n or more of its licenses is in the unauthorized license list, even if it\n also has a license in the authorized license list. A package is still\n compliant if present in the authorized packages list.\n\nParanoid:\n All licenses listed for a package must be in the authorised license list\n for the package to be considered compliant. A package is still\n compliant if present in the authorized packages list.\n\nAssumption\n==========\nThe tool requires to be installed in the same python (virtual) environment as the packages. This, because it uses\n``pkg_resources`` to access the packages resources and thus, their licenses information.\n\nHow to install\n==============\n\n::\n\n\t$ pip install liccheck\n\n\nHow to use\n==========\n\n``liccheck`` will read the ``requirements.txt`` and verify compliance of packages against a strategy defined in the ``ini`` file.\nIf the requirements file is not specified on the command line, it will search for ``requirements.txt`` in the current folder.\nYou have to setup an ``ini`` file with an authorized license list, unauthorized license list and authorized package list. The packages from your ``requirements.txt`` need to all be installed in the same python environment/virtualenv as ``liccheck``.\nIf the ``ini`` file is not specified on the command line, it will search for ``liccheck.ini`` in the current folder.\n\nHere is an example of a ``liccheck.ini`` file:\n::\n\n\t# Authorized and unauthorized licenses in LOWER CASE\n\t[Licenses]\n\tauthorized_licenses:\n\t\tbsd\n\t\tnew bsd\n\t\tbsd license\n\t\tnew bsd license\n\t\tsimplified bsd\n\t\tapache\n\t\tapache 2.0\n\t\tapache software license\n\t\tgnu lgpl\n\t\tlgpl with exceptions or zpl\n\t\tisc license\n\t\tisc license (iscl)\n\t\tmit\n\t\tmit license\n\t\tpython software foundation license\n\t\tzpl 2.1\n\n\tunauthorized_licenses:\n\t\tgpl v3\n\n\t[Authorized Packages]\n\t# Python software license (see http://zesty.ca/python/uuid.README.txt)\n\tuuid: 1.30\n\nNote: versions of authorized packages can be defined using `PEP-0440 version specifiers <https://www.python.org/dev/peps/pep-0440/#version-specifiers>`_, such as ``>=1.3,<1.4``. The implementation uses the nice package `semantic_version <https://pypi.org/project/semantic_version/>`_.\n\nFor demo purpose, let's say your ``requirements.txt`` file contains this:\n::\n\n\tFlask>=0.12.1\n\tflask_restful\n\tjsonify\n\tpsycopg2>=2.7.1\n\tnose\n\tscipy\n\tscikit-learn\n\tpandas\n\tnumpy\n\targparse\n\tuuid\n\tsqlbuilder\n\tproboscis\n\tpyyaml>=3.12\n\nThe execution will output this:\n::\n\n $ liccheck -s my_strategy.ini -r my_project/required.txt\n gathering licenses...23 packages and dependencies.\n check forbidden packages based on licenses...none\n check authorized packages based on licenses...19 packages.\n check authorized packages...4 packages.\n check unknown licenses...none\n\nIf some dependencies are unknown or are not matching the strategy, the output will be something like:\n::\n\n $ liccheck -s my_strategy.ini -r my_project/requirements.txt\n\tgathering licenses...32 packages and dependencies.\n\tcheck forbidden packages based on licenses...1 forbidden packages :\n\t Unidecode (0.4.21) : GPL ['GNU General Public License v2 or later (GPLv2+)']\n\t dependency:\n\t Unidecode << python-slugify << yoyo-migrations\n\n\tcheck authorized packages based on licenses...24 packages.\n\tcheck authorized packages...6 packages.\n\tcheck unknown licenses...1 unknown packages :\n\t feedparser (5.2.1) : UNKNOWN []\n\t dependency:\n\t feedparser\n\nAlso supports pyproject.toml like:\n::\n\n [project]\n dependencies = [\n \"Flask>=0.12.1\",\n \"flask_restful\",\n \"jsonify\",\n \"psycopg2>=2.7.1\",\n \"nose\",\n \"scipy\",\n \"scikit-learn\",\n \"pandas\",\n \"numpy\",\n \"argparse\",\n \"uuid\",\n \"sqlbuilder\",\n \"proboscis\",\n \"pyyaml>=3.12\",\n ]\n\n [project.optional-dependencies]\n test = [\n \"pytest>=3.6.3\",\n ]\n\n [tool.liccheck]\n authorized_licenses = [\n \"bsd\",\n \"new bsd\",\n \"bsd license\",\n \"new bsd license\",\n \"simplified bsd\",\n \"apache\",\n \"apache 2.0\",\n \"apache software license\",\n \"gnu lgpl\",\n \"lgpl with exceptions or zpl\",\n \"isc license\",\n \"isc license (iscl)\",\n \"mit\",\n \"mit license\",\n \"python software foundation license\",\n \"zpl 2.1\",\n ]\n unauthorized_licenses = [\n \"gpl v3\",\n ]\n # strategy_ini_file = \"./liccheck.ini\"\n # level = \"STANDARD\"\n # requirement_txt_file = \"./requirements.txt\" # ignored if dependencies or optional_dependencies are defined\n # reporting_txt_file = \"path/to/reporting.txt file\" # by default is None\n # no_deps = false\n dependencies = true # to load [project.dependencies]\n optional_dependencies = [\"test\"] # to load extras from [project.optional-dependencies]\n\n [tool.liccheck.authorized_packages]\n uuid = \"1.30\"\n\nBy default, exact matching is required between each package's license and one of the license of the authorized or unauthorized list.\nYou can also provide regular expressions to match licenses by using the ``as_regex`` boolean flag. For instance, to exclude GPL licenses,\none could define the following configuration in ``pyproject.toml``:\n\n::\n\n ...\n\n unauthorized_licenses = [\n '\\bgpl'\n ]\n as_regex = true\n \n\nUsing liccheck with pre-commit\n==============================\n\nAdd this to your .pre-commit-config.yaml:\n::\n\n - repo: https://github.com/dhatim/python-license-check\n rev: master\n hooks:\n - id: liccheck\n language: system\n\nContributing\n============\n\nTo run the tests:\n::\n\n $ tox -p all\n\nLicensing\n=========\n\n- See `LICENSE <LICENSE>`__\n\n\n",
"bugtrack_url": null,
"license": "Apache Software License",
"summary": "Check python packages from requirement.txt and report issues",
"version": "0.9.2",
"project_urls": {
"Homepage": "https://github.com/dhatim/python-license-check"
},
"split_keywords": [
"license",
"check",
"build",
"tool"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f1bbfbc7dd6ea215b97b90c35efc8c8f3dbfcbacb91af8c806dff1f49deddd8e",
"md5": "b0ec1522480b758cb2fd290abc6eaeb4",
"sha256": "15cbedd042515945fe9d58b62e0a5af2f2a7795def216f163bb35b3016a16637"
},
"downloads": -1,
"filename": "liccheck-0.9.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "b0ec1522480b758cb2fd290abc6eaeb4",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.5",
"size": 13652,
"upload_time": "2023-09-22T14:23:57",
"upload_time_iso_8601": "2023-09-22T14:23:57.849629Z",
"url": "https://files.pythonhosted.org/packages/f1/bb/fbc7dd6ea215b97b90c35efc8c8f3dbfcbacb91af8c806dff1f49deddd8e/liccheck-0.9.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "84f0962ba77fae91ad0cca2ead4fb0ff5aa00f9793c1a78cd807672f9e5a9aa3",
"md5": "87656c182d804b8c196668d602a2734d",
"sha256": "bdc2190f8e95af3c8f9c19edb784ba7d41ecb2bf9189422eae6112bf84c08cd5"
},
"downloads": -1,
"filename": "liccheck-0.9.2.tar.gz",
"has_sig": false,
"md5_digest": "87656c182d804b8c196668d602a2734d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 16020,
"upload_time": "2023-09-22T14:23:59",
"upload_time_iso_8601": "2023-09-22T14:23:59.009483Z",
"url": "https://files.pythonhosted.org/packages/84/f0/962ba77fae91ad0cca2ead4fb0ff5aa00f9793c1a78cd807672f9e5a9aa3/liccheck-0.9.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-22 14:23:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dhatim",
"github_project": "python-license-check",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "liccheck"
}