airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Normalize rst license header shape and enforce it in prek

Open shahar1 opened this issue 1 month ago • 2 comments

Body

The license header at the top of our *.rst files comes in three shapes, and the insert-license prek hook accepts all of them, so contributors who touch a file see a mix and guess. This surfaced in https://github.com/apache/airflow/pull/74804, where a review thread spent time on whether a leading blank line is required by the license check (it is not), and which of the existing styles is the "right" one. That is not a question a feature PR should have to answer, so this issue tracks fixing it repo-wide.

Census on main (git ls-files '*.rst', 1759 files):

First line of the file Files Example
.. Licensed to the Apache ... (one leading space, 4-space continuation) 1250 BREEZE.rst
blank line, header starts on line 2 at column 0 356 providers/common/ai/docs/index.rst, airflow-core/docs/operators-and-hooks-ref.rst
.. Licensed to the Apache ... at column 0 (3- or 4-space continuation) 77 COMMITTERS.rst, providers/snowflake/docs/connections/snowflake.rst
no header (newsfragments, excluded by the hook) 76 airflow-core/newsfragments/*.rst

Why it happens: the hook (Add license for all RST files in .pre-commit-config.yaml) runs insert-license with --comment-style "||", --license-filepath scripts/ci/license-templates/LICENSE.rst and --fuzzy-match-generates-todo. When it inserts a header it writes the first shape (verified: a fresh file gets .. Licensed ... with a leading space). When a file already carries any of the three shapes, the fuzzy match passes and nothing is rewritten, so the variants never converge. Verified on the file from the PR above: the hook reports Passed both with and without the leading blank line.

Proposal:

  1. Pick one canonical shape. The hook's own output ( .. Licensed ..., 4-space continuation) is the natural choice because new files get it automatically; scripts/ci/license-templates/LICENSE.rst and contributing-docs/08_static_code_checks.rst should state it.
  2. One mechanical PR that rewrites the 433 non-canonical files (356 blank-first-line + 77 column-0). The header is an rst comment, so rendered docs do not change. Doing it in one go, or one PR per top-level area, keeps the conflict window short for open PRs.
  3. Make the check strict so the shapes cannot drift again: either drop --fuzzy-match-generates-todo for rst (so a non-exact header is treated as missing and the hook rewrites it), or add a small prek script that fails when an rst file's header does not start on line 1 with the canonical text.

Acceptance criteria: every tracked *.rst outside the hook's exclusions starts with the identical canonical header on line 1, and the static check fails on a file that deviates.


Drafted-by: Claude Code (Fable 5.1) (no human review before posting)

Committer

  • [X] I acknowledge that I am a maintainer/committer of the Apache Airflow project.

shahar1 avatar Oct 17 '26 08:10 shahar1

@shahar1 I'd like to work on this. Going by the census in the description, 433 files need to change (356 with a leading blank line, 77 starting at column 0).

How would you like the change split into PRs? Is there a number of files per PR that reviewers find comfortable to review?

xchwan avatar Oct 27 '26 01:10 xchwan

4. @shahar1 I'd like to work on this. Going by the census in the description, 433 files need to change (356 with a leading blank line, 77 starting at column 0). How would you like the change split into PRs? Is there a number of files per PR that reviewers find comfortable to review?

In this such cases I usually create one PR for the script that fixes it + a "burn-down list" + exempting the burn-down list from the script's execution. Then I create PRs to to fix the files, for example: https://github.com/apache/airflow/pull/70297 https://github.com/apache/airflow/issues/70296

In this case I'm ok with doing it in a single PR as it is more straight forward solution - feel free to open a PR.

shahar1 avatar Oct 27 '26 21:10 shahar1