A Python tool for automatically detecting and managing Open Source Software (OSS) licenses in your projects.
OpenLicenseDetect is a command-line tool that scans directories for LICENSE files, automatically detects the license type, extracts metadata (author, year, license text), and generates structured JSON output. It's designed to help developers and organizations maintain compliance with OSS licensing requirements by providing a comprehensive overview of all licenses used in their projects.
The primary purpose of this project is to manage OSS licenses by:
- Automatically detecting OSS license files in project directories (including node_modules)
- Parsing license content to identify license types (MIT, Apache-2.0, GPL, BSD, etc.)
- Extracting metadata such as copyright holders, years, and license text
- Generating formatted JSON files for easy integration with compliance tools
- Supporting future YAML output for enhanced flexibility
- MIT
- Apache-2.0
- GPL-2.0, GPL-3.0
- BSD-2-Clause, BSD-3-Clause
- ISC
- LGPL-2.1, LGPL-3.0
- MPL-2.0
- EPL-2.0
- CDDL-1.1
- CC0-1.0
- AGPL-3.0
- Unlicense
- Other (fallback for unrecognized licenses)
- Python 3.9 or higher
- Virtual environment (recommended)
-
Clone the repository:
git clone <repository-url> cd OpenLicenseDetect
-
Set up virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Scan current directory:
python main.py
-
Scan specific directory:
python main.py /path/to/your/project python main.py ./node_modules
-
Use with verbose output:
python main.py -v /path/to/project python main.py --verbose
-
Get help:
python main.py -h
The tool generates oss_license_detect_intermediate.json containing:
{
"library_object_list": [
{
"author": "Copyright Holder Name",
"year": 2023,
"oss_type": "MIT",
"raw_license_text": "Full license text..."
}
],
"total_libraries": 15,
"library_paths": ["path/to/library1", "path/to/library2"]
}from src.library_object_manager.library_object_manager import LibraryObjectManager
# Create manager instance
manager = LibraryObjectManager("/path/to/project")
# Crawl for LICENSE files
manager.crawling_library_directory()
# Generate JSON output
manager.generate_file()# Activate virtual environment first
source venv/bin/activate
# Run all tests
python -m pytest test_licenses.py -v# Run a specific test method
python -m pytest test_licenses.py::TestLicenseParsing::test_license_directory_exists -v
# Run tests by keyword
python -m pytest test_licenses.py -k "mit" -v
# Run with coverage
python -m pytest test_licenses.py --cov=src --cov-report=html# Test MIT license detection
python -m pytest test_licenses.py::TestLicenseParsing::test_mit_license_detection -v
# Test Apache license detection
python -m pytest test_licenses.py::TestLicenseParsing::test_apache_license_detection -v# Run linting
flake8 src/ test_licenses.py
# Run type checking
mypy src/
# Format code
black src/ test_licenses.py
# Sort imports
isort src/ test_licenses.pyOpenLicenseDetect/
βββ src/
β βββ library_object_manager/
β β βββ library_object_manager.py # Main crawling and management logic
β βββ reader/
β β βββ library_reader.py # License parsing and detection
β βββ model/
β β βββ oss_type.py # License type enumeration
β βββ constant.py # Constants (LICENSE filename)
βββ license/ # Sample license files for testing
β βββ mit/
β βββ apache-2/
β βββ ...
βββ example/
β βββ python/
β βββ example.py # JSON parsing examples
βββ test_licenses.py # Test suite
βββ main.py # CLI entry point
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ README.md # This file
The project uses pyproject.toml for configuration:
- Black: Code formatting (88 character line length)
- MyPy: Type checking with strict settings
- Pytest: Testing configuration with coverage
- isort: Import sorting
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- YAML output support
- Enhanced license detection algorithms
- Integration with package managers (npm, pip, etc.)
- Web interface for license management
- License compliance reporting
- Support for additional license types
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue with detailed information
- Include the output of
python main.py -vfor debugging
$ python main.py ./node_modules -v
Crawling directory: /path/to/project/node_modules
Full LICENSE path: /path/to/project/node_modules/@ampproject/remapping/LICENSE
Full LICENSE path: /path/to/project/node_modules/@babel/plugin-syntax-jsx/LICENSE
...
Total libraries found: 15
License detection completed successfully!Made with β€οΈ for the open source community