pylic


Namepylic JSON
Version 3.6.1 PyPI version JSON
download
home_pagehttps://github.com/ubersan/pylic
SummaryA Python license checker
upload_time2024-04-27 12:16:27
maintainerNone
docs_urlNone
authorSandro Huber
requires_python<4.0.0,>=3.7.2
licenseMIT
keywords cli license checker
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.0,>=3.7.2",
    "maintainer_email": null,
    "keywords": "cli, license, checker",
    "author": "Sandro Huber",
    "author_email": "sandrochuber@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d1/80/7105c5c7fd278cd25bb7448c69e2aca1db06624573bb929ea2b69877103a/pylic-3.6.1.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": "3.6.1",
    "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": "2e84e76bf136ff5a2a8227b56af599292694d0c20510d98ed61b7eda0a4afc01",
                "md5": "01f175f922ef03f9c964c0b15fd53364",
                "sha256": "55cc7ab780a7d80498de519b52d4d8e0a61c24b6eb4113a3a5a02c247effc225"
            },
            "downloads": -1,
            "filename": "pylic-3.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01f175f922ef03f9c964c0b15fd53364",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.7.2",
            "size": 12347,
            "upload_time": "2024-04-27T12:16:22",
            "upload_time_iso_8601": "2024-04-27T12:16:22.149494Z",
            "url": "https://files.pythonhosted.org/packages/2e/84/e76bf136ff5a2a8227b56af599292694d0c20510d98ed61b7eda0a4afc01/pylic-3.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d1807105c5c7fd278cd25bb7448c69e2aca1db06624573bb929ea2b69877103a",
                "md5": "34307f5939a0db21df567cedb32f8899",
                "sha256": "f7d65926e04356d3340c777c2a17d7d951ebb04780a2d1f536f4ef6715a8c8bd"
            },
            "downloads": -1,
            "filename": "pylic-3.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "34307f5939a0db21df567cedb32f8899",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.7.2",
            "size": 10829,
            "upload_time": "2024-04-27T12:16:27",
            "upload_time_iso_8601": "2024-04-27T12:16:27.283476Z",
            "url": "https://files.pythonhosted.org/packages/d1/80/7105c5c7fd278cd25bb7448c69e2aca1db06624573bb929ea2b69877103a/pylic-3.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 12:16:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ubersan",
    "github_project": "pylic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pylic"
}
        
Elapsed time: 0.24702s