shahar1 commented on code in PR #75838:
URL: https://github.com/apache/airflow/pull/75838#discussion_r4493830426
##########
.pre-commit-config.yaml:
##########
@@ -1788,6 +1788,19 @@ repos:
files: changelog\.(rst|txt)$
entry: ./scripts/ci/prek/check_changelog_format.py
pass_filenames: true
+ - id: check-rst-license-header
Review Comment:
Major: this hook and `prepare-provider-documentation` disagree on the
header. The generator writes a leading blank line into `README.rst` and
`commits.rst`, and this hook rewrites it, so the next provider wave fails here
until prek is re-run. Details are in the review body. The fix belongs in
`PROVIDER_README_TEMPLATE.rst.jinja2` and
`PROVIDER_COMMITS_TEMPLATE.rst.jinja2`.
##########
scripts/ci/prek/check_rst_license_header.py:
##########
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+Make sure every RST file starts with the license header in its canonical shape.
+
+The ``insert-license`` hook strips whitespace before comparing lines and looks
for the header in
+the first few lines, so it accepts a leading blank line or a different
indentation. This hook
+enforces the exact shape the ``insert-license`` hook writes for new files: the
header on line 1,
+every non-empty line indented by one space.
+
+A header that is only blank lines or indentation away from the canonical shape
is rewritten in
+place. Any other deviation is reported and left for the author to fix.
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+LICENSE_TEMPLATE = Path(__file__).resolve().parents[1] / "license-templates" /
"LICENSE.rst"
+
+# A leading ``:tocdepth:`` field list only counts as document metadata while
it is the first
+# element, and an indented header ahead of it turns the field list into plain
text.
+KEEP_FIELD_LIST_FIRST = frozenset(
Review Comment:
Nit: these two paths could go in the hook's `exclude` in
`.pre-commit-config.yaml`, next to the other exclusions. That removes this
constant, the check in `main` and
`test_skips_files_that_must_keep_their_field_list_first`. Move the comment
explaining why with them. The new section in `08_static_code_checks.rst` says
"Every `*.rst` file", so it should mention the exception too.
##########
providers/airbyte/README.rst:
##########
@@ -1,20 +1,19 @@
-
-.. Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
-.. http://www.apache.org/licenses/LICENSE-2.0
-
-.. Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
+ .. Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
Minor: `readme = "README.rst"` makes this file the PyPI description, and the
indented header changes what PyPI renders. With `readme_renderer`, the
description now starts with an empty element:
```html
<blockquote> </blockquote> <p>Package <span class="docutils literal">...
```
Before this PR it started at `<p>Package`. `providers/amazon/README.rst`
gives the same result, and all 109 provider READMEs share this header. The
check in the PR description does not cover this: it ignores empty block quotes
and uses Sphinx settings.
Either accept it, or exempt `^providers/.*/README\.rst$` from this hook and
leave these files out of the PR. With the exemption, only the `commits.rst`
template needs fixing. I prefer the exemption, because a generated file gains
nothing from the rewrite and the published page stays the same.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]