# pylic - Python license checker [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sandrochuber/pylic/blob/main/LICENSE) [![PyPI version](https://badge.fury.io/py/pylic.svg)](https://badge.fury.io/py/pylic/) [![Codecov](https://codecov.io/gh/ubersan/pylic//branch/main/graph/badge.svg)](https://codecov.io/gh/ubersan/pylic/)
Reads pylic configuration in `pyproject.toml` and checks licenses of installed packages recursively.
Principles:
- Every license has to be allowed explicitly (case-insensitive comparison).
- All installed packages without a license are considered unsafe and have to be listed as such.
> Only installed packages are checked for licenses. Packages/dependencies listed in `pyproject.toml` are ignored.
## Installation
```sh
pip install pylic
```
## Configuration
`pylic` needs be run in the directory where your `pyproject.toml` file is located. You can configure
- `safe_licenses`: All licenses you consider safe for usage. The string comparison is case-insensitive.
- `unsafe_packages`: If you rely on a package that does not come with a license you have to explicitly list it as such.
- `ignore_packages`: Packages that will not be reported as unsafe even if they use a license not listed as safe. This is useful in case an existing projects want to start integrating `pylic`, but are still using unsafe licenses. This enables first to ignore these packages temporarely, while they're being replaced, second to already validate newly added or updated packages against the safe license set and third to integrate `pylic` frictionless into CI/CD from the get go.
```toml
[tool.pylic]
safe_licenses = [
"Apache Software License",
"Apache License 2.0",
"MIT License",
"Python Software Foundation License",
"Mozilla Public License 2.0 (MPL 2.0)",
]
unsafe_packages = [
"unlicensedPackage",
]
ignore_packages = [
"ignoredPackage",
]
```
## Commands
`pylic` provides the following commands (also see `pylic help`):
- `check`: Checks all installed licenses.
- `list`: Lists all installed packages and their corresponding license.
## Usage Example
Create a venv to start with a clean ground and activate it
```sh
python -m venv .venv
source .venv/bin/activate
```
Install `pylic` and create an empty `pyproject.toml`
```sh
pip install pylic
touch pyproject.toml
```
Install all your dependencies
```sh
pip install <packageA> <packageB>
```
Run pylic
```sh
pylic check
```
The output will be similar to
```sh
Found unsafe packages:
pkg_resources (0.0.0)
Found unsafe licenses:
pip (18.1): MIT License
zipp (3.4.1): MIT License
toml (0.10.2): MIT License
pylic (1.2.0): MIT License
setuptools (40.8.0): MIT License
typing-extensions (3.7.4.3): Python Software Foundation License
importlib-metadata (3.9.0): Apache Software License
```
The return code of `pylic` is in this case non-zero due to unsafe licenses. This allows usage of pylic in CI.
```sh
echo $? # prints 1
```
As these licenses and packages are all ok we can configure `pylic` accordingly
```sh
cat <<EOT >> pyproject.toml
[tool.pylic]
safe_licenses = ["Apache Software License", "MIT License", "Python Software Foundation License"]
unsafe_packages = ["pkg_resources"]
EOT
```
After rerunning `pylic check` the output now reveals a successful validation
```sh
✨ All licenses ok ✨
```
Also the return code now signals that all is good
```sh
echo $? # prints 0
```
Use `pylic list` to list all installed packages and their corresponding licenses.
## Advanced Usage
In cases where the safe licenses or unsafe packages are centrally managed keeping the configuration in perfect sync to the installed packages might be too cumbersome or even impossible. To support these use cases the `check` command provides the two options (see also `check --help`) `--allow-extra-safe-licenses` and `--allow-extra-unused-packages`. These options only affect the returned status code and will keep all corresponding printed warnings unchanged.
## Pre-commit
`pylic` provides a [pre-commit](https://pre-commit.com/) integration. Follow the [instructions](https://pre-commit.com/#quick-start) and enable automatic license checking on commits by adding
```sh
- repo: https://github.com/ubersan/pylic
rev: v<version>
hooks:
- id: pylic
```
to your `.pre-commit-config.yaml` file.
## Development
Required tools:
- Poetry (https://python-poetry.org/)
Run `poetry install` to install all necessary dependencies. Checkout the `[tool.taskipy.tasks]` (see [taskipy](https://github.com/illBeRoy/taskipy)) section in the `pyproject.toml` file for utility tasks. You can run these with `poetry run task <task>`.
Creating a new release is as simple as:
- Update `version` in the pyproject.toml and the `__version__.py` file.
- `poetry run task release`.
Raw data
{
"_id": null,
"home_page": "https://github.com/ubersan/pylic",
"name": "pylic",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "cli, license, checker",
"author": "Sandro Huber",
"author_email": "sandrochuber@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2c/39/0ac33e476fe95819632884159d85029daa0a5bc06889c46dacf9141df22a/pylic-4.0.0.tar.gz",
"platform": null,
"description": "# pylic - Python license checker [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/sandrochuber/pylic/blob/main/LICENSE) [![PyPI version](https://badge.fury.io/py/pylic.svg)](https://badge.fury.io/py/pylic/) [![Codecov](https://codecov.io/gh/ubersan/pylic//branch/main/graph/badge.svg)](https://codecov.io/gh/ubersan/pylic/)\n\nReads pylic configuration in `pyproject.toml` and checks licenses of installed packages recursively.\n\nPrinciples:\n\n- Every license has to be allowed explicitly (case-insensitive comparison).\n- All installed packages without a license are considered unsafe and have to be listed as such.\n\n> Only installed packages are checked for licenses. Packages/dependencies listed in `pyproject.toml` are ignored.\n\n## Installation\n\n```sh\npip install pylic\n```\n\n## Configuration\n\n`pylic` needs be run in the directory where your `pyproject.toml` file is located. You can configure\n\n- `safe_licenses`: All licenses you consider safe for usage. The string comparison is case-insensitive.\n- `unsafe_packages`: If you rely on a package that does not come with a license you have to explicitly list it as such.\n- `ignore_packages`: Packages that will not be reported as unsafe even if they use a license not listed as safe. This is useful in case an existing projects want to start integrating `pylic`, but are still using unsafe licenses. This enables first to ignore these packages temporarely, while they're being replaced, second to already validate newly added or updated packages against the safe license set and third to integrate `pylic` frictionless into CI/CD from the get go.\n\n```toml\n[tool.pylic]\nsafe_licenses = [\n \"Apache Software License\",\n \"Apache License 2.0\",\n \"MIT License\",\n \"Python Software Foundation License\",\n \"Mozilla Public License 2.0 (MPL 2.0)\",\n]\nunsafe_packages = [\n \"unlicensedPackage\",\n]\nignore_packages = [\n \"ignoredPackage\",\n]\n```\n\n## Commands\n\n`pylic` provides the following commands (also see `pylic help`):\n\n- `check`: Checks all installed licenses.\n- `list`: Lists all installed packages and their corresponding license.\n\n## Usage Example\n\nCreate a venv to start with a clean ground and activate it\n\n```sh\npython -m venv .venv\nsource .venv/bin/activate\n```\n\nInstall `pylic` and create an empty `pyproject.toml`\n\n```sh\npip install pylic\ntouch pyproject.toml\n```\n\nInstall all your dependencies\n\n```sh\npip install <packageA> <packageB>\n```\n\nRun pylic\n\n```sh\npylic check\n```\n\nThe output will be similar to\n\n```sh\nFound unsafe packages:\n pkg_resources (0.0.0)\nFound unsafe licenses:\n pip (18.1): MIT License\n zipp (3.4.1): MIT License\n toml (0.10.2): MIT License\n pylic (1.2.0): MIT License\n setuptools (40.8.0): MIT License\n typing-extensions (3.7.4.3): Python Software Foundation License\n importlib-metadata (3.9.0): Apache Software License\n```\n\nThe return code of `pylic` is in this case non-zero due to unsafe licenses. This allows usage of pylic in CI.\n\n```sh\necho $? # prints 1\n```\n\nAs these licenses and packages are all ok we can configure `pylic` accordingly\n\n```sh\ncat <<EOT >> pyproject.toml\n[tool.pylic]\nsafe_licenses = [\"Apache Software License\", \"MIT License\", \"Python Software Foundation License\"]\nunsafe_packages = [\"pkg_resources\"]\nEOT\n```\n\nAfter rerunning `pylic check` the output now reveals a successful validation\n\n```sh\n\u2728 All licenses ok \u2728\n```\n\nAlso the return code now signals that all is good\n\n```sh\necho $? # prints 0\n```\n\nUse `pylic list` to list all installed packages and their corresponding licenses.\n\n## Advanced Usage\n\nIn cases where the safe licenses or unsafe packages are centrally managed keeping the configuration in perfect sync to the installed packages might be too cumbersome or even impossible. To support these use cases the `check` command provides the two options (see also `check --help`) `--allow-extra-safe-licenses` and `--allow-extra-unused-packages`. These options only affect the returned status code and will keep all corresponding printed warnings unchanged.\n\n## Pre-commit\n\n`pylic` provides a [pre-commit](https://pre-commit.com/) integration. Follow the [instructions](https://pre-commit.com/#quick-start) and enable automatic license checking on commits by adding\n\n```sh\n- repo: https://github.com/ubersan/pylic\n rev: v<version>\n hooks:\n - id: pylic\n```\n\nto your `.pre-commit-config.yaml` file.\n\n## Development\n\nRequired tools:\n\n- Poetry (https://python-poetry.org/)\n\nRun `poetry install` to install all necessary dependencies. Checkout the `[tool.taskipy.tasks]` (see [taskipy](https://github.com/illBeRoy/taskipy)) section in the `pyproject.toml` file for utility tasks. You can run these with `poetry run task <task>`.\n\nCreating a new release is as simple as:\n\n- Update `version` in the pyproject.toml and the `__version__.py` file.\n- `poetry run task release`.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python license checker",
"version": "4.0.0",
"project_urls": {
"Homepage": "https://github.com/ubersan/pylic",
"Repository": "https://github.com/ubersan/pylic"
},
"split_keywords": [
"cli",
" license",
" checker"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3801163dea9ce97fb790c0f67fe2b26ca851c1f7cbce7cd711e863fec1fcaeb0",
"md5": "d51eb3ee8aeca8ba7f7586dfa7d706a2",
"sha256": "06b7aae012bbb4376e405c491b26582c0de597c4497c57abaffef092c9226579"
},
"downloads": -1,
"filename": "pylic-4.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d51eb3ee8aeca8ba7f7586dfa7d706a2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 12291,
"upload_time": "2024-10-18T06:15:20",
"upload_time_iso_8601": "2024-10-18T06:15:20.793348Z",
"url": "https://files.pythonhosted.org/packages/38/01/163dea9ce97fb790c0f67fe2b26ca851c1f7cbce7cd711e863fec1fcaeb0/pylic-4.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2c390ac33e476fe95819632884159d85029daa0a5bc06889c46dacf9141df22a",
"md5": "28dee00d2ed527abe568ec0248e8c433",
"sha256": "8463aae6f0cf63b482978ddf41e74297a69f789e6bfab68e172e2beb9967f6c7"
},
"downloads": -1,
"filename": "pylic-4.0.0.tar.gz",
"has_sig": false,
"md5_digest": "28dee00d2ed527abe568ec0248e8c433",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 10779,
"upload_time": "2024-10-18T06:15:21",
"upload_time_iso_8601": "2024-10-18T06:15:21.944469Z",
"url": "https://files.pythonhosted.org/packages/2c/39/0ac33e476fe95819632884159d85029daa0a5bc06889c46dacf9141df22a/pylic-4.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-18 06:15:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ubersan",
"github_project": "pylic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pylic"
}