Skip to content

Normalize the RST license header shape and enforce it in prek - #75838

Merged
shahar1 merged 6 commits into
apache:mainfrom
xchwan:rst-license-header
Nov 19, 2026
Merged

shahar1 merged 6 commits into
apache:mainfrom
xchwan:rst-license-header

Conversation

@xchwan

@xchwan xchwan commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

The license header in *.rst files came in several shapes (leading blank line, no indentation, canonical). The insert-license hook strips whitespace and looks for the header in the first few lines, so it accepts all of them and the shapes never converged.

This adds a check-rst-license-header hook that requires the header on line 1 with every non-empty line indented by one space, which is what insert-license writes for a new file. The hook rewrites a header that is only a blank line or indentation away from that shape, and reports a header that has other content before it. The canonical text is derived from scripts/ci/license-templates/LICENSE.rst. Dropping --fuzzy-match-generates-todo was not enough: the match ignores whitespace whether or not that flag is set.

The rewrite of the existing files is the hook's own output, as agreed on the issue (comment).

What to review

The change is large because of the rewritten files, but the logic is in four files:

  • scripts/ci/prek/check_rst_license_header.py: the hook.
  • scripts/tests/ci/prek/test_check_rst_license_header.py: its tests.
  • .pre-commit-config.yaml: the hook entry, with the same files/exclude as the existing RST license hook.
  • contributing-docs/08_static_code_checks.rst: documents the canonical shape.

The other *.rst files only change their header lines. To reproduce them, run on main:
prek run check-rst-license-header --all-files

Exceptions

Four files need more than the hook's own rewrite:

  • airflow-core/docs/cli-and-env-variables-ref.rst: left unchanged. It starts with :tocdepth: 4, and an indented header is parsed as a block quote, so putting the header first stops the field list from being read as document metadata and tocdepth would be lost. The hook skips it.
  • airflow-ctl/docs/cli-and-env-variables-ref.rst: left unchanged, same reason. The hook skips it.
  • contributing-docs/05_pull_requests.rst: removed a stray first line (the file's own path). Together with the indented header it parsed as a definition list, so that line was rendered at the top of the page.
  • providers/google/docs/operators/cloud/bigquery.rst: removed a duplicated first header line. The rendered page does not change.

How the rewrite was checked

  • For each changed file, the content after the header is identical before and after.
  • Parsing every changed file with docutils (title promotion off, as in Sphinx) gives the same document tree before and after, ignoring comments, empty block quotes and line numbers.
  • A second run of the hook changes nothing.
  • prek run --stage pre-commit passes on the changed files.
  • breeze build-docs apache-airflow --one-pass-only finishes successfully with no warnings or errors. The other documentation packages were not built.

Open PRs that add or edit *.rst files with a different header shape will have the hook rewrite their header on their next run.

closes: #74914


Was generative AI tooling used to co-author this PR?
  • Yes (Claude Code)

Generated-by: Claude Code (Sonnet 5.5) following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Signed-off-by: Xch1 <qchwan@gmail.com>
@xchwan

xchwan commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

@shahar1 This PR only touches the license header of three providers/common/compat RST files, so the common-compat selective check fails in the Build info job and blocks the rest of CI. Could you add the skip common compat check label? No common.compat code changes.

@shahar1 shahar1 added the skip common compat check Skips common compat provider modification check label Oct 29, 2026
@shahar1

shahar1 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@shahar1 This PR only touches the license header of three providers/common/compat RST files, so the common-compat selective check fails in the Build info job and blocks the rest of CI. Could you add the skip common compat check label? No common.compat code changes.

Done, merging from main to trigger the CI

@xchwan

xchwan commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@shahar1 Friendly ping: CI is green. Only four files need real review (listed under "What to review"); the rest is the mechanical header rewrite. Happy to rebase if main moves. Thanks!

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook and the header rewrite look right, and I confirmed the "header only" claim, but the provider generators still emit the old shape, so I'd like that fixed before this merges.

Provider generators still write the old header (.pre-commit-config.yaml:1791)

Edit generated files by hand when a generation workflow exists.

(AGENTS.md, Boundaries, Never)

This PR rewrites 109 providers/*/README.rst and the providers/*/docs/commits.rst files, but not the templates they come from. Both files carry NOTE! THIS FILE IS AUTOMATICALLY GENERATED AND WILL BE OVERWRITTEN!. Rendered with the settings breeze uses, the templates at this head start like this:

PROVIDER_README_TEMPLATE.rst.jinja2:   '' then '.. Licensed to the Apache ...'
PROVIDER_COMMITS_TEMPLATE.rst.jinja2:  '' then ' .. Licensed to the Apache ...'

Both are shapes the new hook rewrites. _generate_readme_rst and _update_commits_rst run in breeze release-management prepare-provider-documentation, so the next provider wave puts the old header back and its PR fails check-rst-license-header until the release manager re-runs prek and stages the result. commits.rst is affected too: its content has not changed since May 2025 because the render matched the file, so after this PR it would differ on every wave. dev/README_RELEASE_PROVIDERS.md has no step for this.

Fix the templates so they render the canonical shape, and add a test for it. The leading blank line comes from the newline after the {# ... #} block. -#} is not the fix, because it also strips the header's leading space. Starting the header on the same line as #}, or moving the Jinja comment below the header, works.

Smaller observations

Two more are inline:

  • providers/airbyte/README.rst:1: the indented header adds an empty block quote to the published PyPI description.
  • scripts/ci/prek/check_rst_license_header.py:40: the two exempt files could live in the hook's exclude.

This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

Comment thread .pre-commit-config.yaml Resolved
Comment thread providers/airbyte/README.rst Resolved
@xchwan

xchwan commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@shahar1 Thanks for the review, all points addressed:

  • Generators: PROVIDER_COMMITS_TEMPLATE.rst.jinja2 now renders the canonical header, with a test that fails without the change.
  • PyPI description: took the exemption. providers/*/README.rst is excluded in the hook and restored to its main version (108 files; common/dataquality already had the canonical header).
  • Exempt files: the two cli-and-env-variables-ref.rst moved to exclude; the constant, check and test are removed, and 08_static_code_checks.rst lists the exclusions.

I also merged main, and the hook fixed two new RST files. The PR now changes 339 files.

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three points from my earlier review are addressed. One thing is left before this can merge: main has gained an RST file that the new hook rewrites.

main now has a file the hook rewrites

providers/huggingface/docs/connections/index.rst was added by #76317 on 2026-11-11, after the last push here. Its header starts at column zero:

.. Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file

This PR does not touch that file, so after a merge check-rst-license-header rewrites it and fails on every --all-files run on main. I checked the first line of the 1607 in-scope *.rst files in a simulated merge of this head (ce405b9e) with main at baac5581c6c: this is the only one that differs.

Please merge main and run prek run check-rst-license-header --all-files again. The same thing will happen each time a new RST file lands with another header shape, so I will merge soon after the update.

What I verified

  • PROVIDER_COMMITS_TEMPLATE.rst.jinja2 renders the header on line 1, and the new test fails against the old template.
  • No providers/*/README.rst file is in the diff any more, and the hook excludes them.
  • The two cli-and-env-variables-ref.rst files are in the hook's exclude, and 08_static_code_checks.rst lists both exclusions.
  • The merge with current main has no conflicts.

I read the hook and did not run it locally. CI on this head passed, but it ran before #76317 landed.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
Contributing guide.

@xchwan

xchwan commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

@shahar1 Thanks! I merged main and re-ran the hook; it only fixed providers/huggingface/docs/connections/index.rst, and it passes on --all-files now. Since new RST files keep landing on main, it would be great to merge soon, before another one slips in.

@xchwan

xchwan commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

@shahar1 Gentle ping: CI is green on the latest push, and a simulated merge with current main has no conflicts and no new RST files the hook would rewrite. Could you approve and merge when you get a chance? Thanks!

@shahar1

shahar1 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@shahar1 Gentle ping: CI is green on the latest push, and a simulated merge with current main has no conflicts and no new RST files the hook would rewrite. Could you approve and merge when you get a chance? Thanks!

Aplogies for the dealy - LGTM! Well done :)

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one item left from my last review is fixed: providers/huggingface/docs/connections/index.rst now has the canonical header, and main has gained no RST file since that the hook would rewrite.

What I verified

  • 19c1a70c changes only the header lines of providers/huggingface/docs/connections/index.rst, and the merge of main in 41e49337 has no changes of its own.
  • I simulated a merge of this head with main at 2184b1da543. It has no conflicts. I compared the first 16 lines of all 1619 in-scope *.rst files with the canonical header, using the hook's exclude. All of them match. (providers/standard/docs/operators/hitl.rst uses CRLF line endings; the hook handles that.)
  • CI on this head is green.

I checked the headers with my own script, not by running the hook.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Apache Airflow handles maintainer review:
Contributing guide.

@shahar1
shahar1 merged commit 0529b44 into apache:main Nov 19, 2026
154 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip common compat check Skips common compat provider modification check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Normalize rst license header shape and enforce it in prek

2 participants