A tool to analyze the compatibility of licenses in a project.
Project description
Liscopelens: License Scope Lens
Liscopelens is a command-line tool for static analysis of open-source license compatibility. It helps developers identify and prevent potential license conflicts within their software projects, particularly C/C++ projects that use the gn build system.
About The Project
Managing open-source licenses in a large project can be complex. Dependencies can introduce a web of different licenses, each with its own set of obligations and restrictions. A failure to ensure license compatibility can lead to legal risks and costly remediation efforts.
Liscopelens addresses this challenge by automating the process of license analysis. It analyzes a project's dependency graph, understands the licenses involved, and identifies conflicts based on a configurable knowledge base of license compatibility rules.
How It Works
Liscopelens operates on a pipeline architecture, processing the project's dependency and license information in several stages:
- Dependency Graph Construction: The tool ingests a JSON dependency graph generated by the
gnbuild system and constructs an in-memory representation of the project's structure using a graph library. - License Annotation: It then parses a JSON report from
scancode-toolkitto identify the licenses of all source files and dependencies, annotating the corresponding nodes in the dependency graph with this license information. - Obligation Propagation: Liscopelens traverses the dependency graph from the bottom up. At each node, it calculates the combined license obligations inherited from its dependencies. The rules for this propagation (e.g., how copyleft licenses affect code linked statically vs. dynamically) are defined in configuration files.
- Conflict Detection: Finally, the tool checks each component for conflicts between its own license and the propagated obligations it has inherited. This check is performed against a comprehensive knowledge graph of license compatibility rules.
The final output is a results.json file that details every conflict found, allowing developers to trace the issue back to the specific files and dependencies that caused it.
Getting Started
To use Liscopelens, you first need to generate the required input files from your project.
Prerequisites
-
GN Dependency Graph: A JSON file representing your project's dependency graph. You can generate this using the
gnbuild system.gn gen out/Default --ide=json
This will create a
project.jsonin theout/Defaultdirectory. -
Scancode License Report: A JSON report of all licenses in your project, generated by
scancode-toolkit.scancode -l -c -f json-pp --strip-root project/ > scancode-output.json
Usage
Once you have the input files, you can run the main analysis command:
liscopelens clang \
--gn path/to/your/project.json \
--scancode path/to/your/scancode-output.json
Input Files
Liscopelens requires two JSON files as input:
- GN JSON (
--gn): This file describes the dependency graph of your project. It contains information about targets, sources, and the relationships between them. - Scancode JSON (
--scancode): This file contains the results of a license scan of your codebase. For each file, it lists the detected licenses and other related information.
Output
The tool generates a results.json file in the working directory. This file contains a list of all license compatibility conflicts found during the analysis. For each conflict, the report includes:
- The component (e.g., library, executable) where the conflict occurred.
- The conflicting licenses involved.
- A trace of the dependencies that propagated the conflicting license obligations.
This detailed report helps developers quickly identify the root cause of a license conflict and take corrective action.
API Usage
Beyond the command line, you can use Liscopelens programmatically in your own Python scripts. This allows for integration into larger toolchains or custom analysis workflows.
The core logic for a specific analysis pipeline (like the clang command) is encapsulated in a ParserEntry class. You can import this class, provide it with the necessary arguments, and run the analysis directly.
Here is an example of how to run the clang analysis from a Python script:
import argparse
from pathlib import Path
from liscopelens.parser.clang.entry import CParserEntry
from liscopelens.utils import load_config
# 1. Define the arguments required by the parser.
# This mimics the command-line arguments.
args = argparse.Namespace(
gn="path/to/your/project.json",
scancode="path/to/your/scancode-output.json",
# Add other necessary arguments as needed
)
# 2. Load the configuration.
# You can load the default config or provide a path to a custom .toml file.
config = load_config()
# 3. Define the project path. This argument is not part of the parser-specific
# args but is required by the .parse() method.
project_path = Path("/path/to/your/project_root").resolve()
# 4. Instantiate the parser entry and run the analysis.
# The results will be written to 'results.json' in the current directory.
parser_instance = CParserEntry(args, config)
parser_instance.parse(project_path)
print("Analysis complete. Check results.json for the output.")
This approach gives you full control over the analysis process from within your Python code.
License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file liscopelens-0.2.17.tar.gz.
File metadata
- Download URL: liscopelens-0.2.17.tar.gz
- Upload date:
- Size: 90.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.7 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32f16bbbef7cf26ced9a817e055ae8c56bf9df85611a6cfe23c4c649ecd160dc
|
|
| MD5 |
4a7ad42e155383fe9e7ab659d62cb698
|
|
| BLAKE2b-256 |
6b65e828053b06fa3b8eef5f5397d92bb063959369af3d133ff0b2e7036014c9
|
File details
Details for the file liscopelens-0.2.17-py3-none-any.whl.
File metadata
- Download URL: liscopelens-0.2.17-py3-none-any.whl
- Upload date:
- Size: 157.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.4 CPython/3.13.7 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6659076aa8996e18ec40168d040d3251114ddcb8ff0d713ed6808c9ffb39adee
|
|
| MD5 |
45b9a6fd15b2bff3548a0b3890e2e50a
|
|
| BLAKE2b-256 |
561eb45b5706f2df4dc92182611a3956d596c449f151882d8718860a027ed642
|