REUSE Compliance Tool

6.2.0 · active · verified Thu Apr 16

reuse is a Python command-line tool designed to help projects achieve and verify compliance with the REUSE recommendations (https://reuse.software). It facilitates adding copyright and licensing information to files, checking existing compliance, and downloading SPDX license texts. The current version is 6.2.0, with releases occurring regularly, typically every few months for minor versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `reuse` tool programmatically by directly calling its `main` function. It simulates command-line execution by manipulating `sys.argv` and creating a temporary project structure to run `lint` and `spdx` commands.

import sys
from pathlib import Path
from reuse.main import main

# Create a dummy project for demonstration
project_path = Path("my_reuse_project")
project_path.mkdir(exist_ok=True)

# Create a Python file with an SPDX license identifier
(project_path / "main.py").write_text("# SPDX-License-Identifier: MIT")

# Create a dummy LICENSE file
(project_path / "LICENSE").write_text("MIT License\nCopyright (c) 2024 User")

# Simulate running 'reuse lint my_reuse_project'
print("\n--- Running 'reuse lint my_reuse_project' ---")
original_argv = sys.argv
sys.argv = ['reuse', 'lint', str(project_path)]
try:
    main()
except SystemExit as e:
    # main() calls sys.exit() with 0 for success, non-zero for failure
    if e.code != 0:
        print(f"Command 'lint' failed with exit code {e.code}")
finally:
    sys.argv = original_argv # Restore original argv

# Simulate running 'reuse spdx --json my_reuse_project'
print("\n--- Running 'reuse spdx --json my_reuse_project' ---")
sys.argv = ['reuse', 'spdx', '--json', str(project_path)]
try:
    main()
except SystemExit as e:
    if e.code != 0:
        print(f"Command 'spdx' failed with exit code {e.code}")
finally:
    sys.argv = original_argv

# Clean up dummy files and directory
(project_path / "main.py").unlink()
(project_path / "LICENSE").unlink()
project_path.rmdir()

view raw JSON →