Skip to content

Replace addlicense Go dependency with a Python script #468

@DanielRyanSmith

Description

@DanielRyanSmith

Background & Motivation

The wpt-gen repository currently uses the addlicense tool (written in Go) to enforce and apply Apache 2.0 license headers to files. This requires downloading and compiling a Go binary during the build/lint phase, adding an unnecessary toolchain dependency to what is otherwise a Python-centric project. By replacing addlicense with a custom Python script, we can simplify our development environment and make the project more portable. This aligns with the approach recently adopted in ChromeStatus (see chromium-dashboard/pull/6271).

Proposed Changes

  1. Create License Checker Script:
    • Add a new Python script at scripts/check_license.py.
    • The script should recursively scan project files, respecting standard ignored directories (e.g., .venv/, .git/, dist/, .pytest_cache/, and others currently defined in ADDLICENSE_IGNORE).
    • The script must verify that supported source files (such as .py, .html, .js) contain the appropriate "Google LLC" Apache 2.0 license header.
    • Implement a --fix argument that automatically prepends the correct license header to files that are missing it.
  2. Add Tests:
    • Create a corresponding scripts/check_license_test.py (or add it to the tests/ directory) to verify the license checker and fixer logic works as expected.
  3. Update Makefile:
    • Remove the ADDLICENSE (go run github.com/google/addlicense@latest) and ADDLICENSE_IGNORE variables.
    • Update the license-check target to execute python scripts/check_license.py.
    • Update the license-fix target to execute python scripts/check_license.py --fix.
  4. Cleanup:
    • Ensure all previous references to the Go toolchain and addlicense are removed from the project's documentation or configuration files.

Acceptance Criteria

  • A Python script successfully checks for missing license headers across the repository.
  • The script can automatically fix missing license headers using a --fix flag.
  • Tests are added and passing to verify the behavior of the license checking script.
  • The Makefile relies entirely on the new Python script instead of the Go addlicense dependency.
  • make lint and make lint-fix continue to verify and fix licenses successfully.
  • All references to addlicense and its Go dependency are removed from the project.

This issue description was drafted by Gemini

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions