REUSE Compliance Tool
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
-
Command 'reuse' not found
cause The 'reuse' executable is not installed or is not in your system's PATH.fixEnsure the library is installed with `pip install reuse` and that your Python environment's script directory is included in your system's PATH. -
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte
cause The `reuse` tool attempted to read a file with an incorrect encoding, often due to misdetection by `charset-normalizer` or a genuinely malformed file.fixTry using the `chardet` encoding module as a workaround: `REUSE_ENCODING_MODULE=chardet reuse lint .` If the issue persists, verify the file's actual encoding and ensure it's valid UTF-8 or consider specifying an explicit encoding for the file if `reuse` offers such a parameter (which it currently does not for `lint`). -
Errors in files: [...] - reuse lint returned non-zero exit code (e.g., 1)
cause The `reuse lint` command detected one or more files that do not comply with the REUSE specification, leading to a non-zero exit code indicating failure.fixReview the detailed output from `reuse lint` to identify the specific errors (e.g., missing copyright, missing license identifier, invalid SPDX expression). Correct the identified issues in your files or add appropriate `REUSE-IgnoreStart`/`REUSE-IgnoreEnd` tags.
Warnings
- breaking Starting from v6.0.0, `reuse lint` now reads entire files for REUSE information instead of just the first 4 KiB. This change can lead to new 'false positive' findings if ignored sections exist deeper in files.
- gotcha In v6.1.0, a bug was identified where `charset-normalizer` (the default encoding detection module) could incorrectly detect UTF-8 files as binary if the 2048th byte was a non-final byte of a multi-byte glyph.
- gotcha The `reuse` library is primarily designed as a command-line interface (CLI) tool. While programmatic access via `reuse.main.main` is possible, the internal APIs are not officially stable or guaranteed to maintain compatibility across versions for direct Python imports beyond `main`.
Install
-
pip install reuse
Imports
- main
from reuse.main import main
Quickstart
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()