This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 0355644de7d Add prek hook to enforce *.iml in distribution .gitignore
files (#63647)
0355644de7d is described below
commit 0355644de7dbeb254b058557208cb603708593fc
Author: Jarek Potiuk <[email protected]>
AuthorDate: Sun Mar 15 21:07:51 2026 +0100
Add prek hook to enforce *.iml in distribution .gitignore files (#63647)
Adds a pre-commit check that verifies every distribution directory
(containing pyproject.toml) has a .gitignore file with a *.iml entry,
preventing IntelliJ IDEA module files from being committed.
---
.pre-commit-config.yaml | 12 +++++
scripts/ci/prek/check_distribution_gitignore.py | 65 +++++++++++++++++++++++++
2 files changed, 77 insertions(+)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d8ae9a486da..7308d31cb20 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -235,6 +235,18 @@ repos:
^pyproject\.toml$
pass_filenames: false
require_serial: true
+ - id: check-distribution-gitignore
+ name: Check distribution .gitignore files have *.iml
+ entry: ./scripts/ci/prek/check_distribution_gitignore.py
+ language: python
+ files: >
+ (?x)
+ ^.*/\.gitignore$|
+ ^\.gitignore$|
+ ^.*/pyproject\.toml$|
+ ^pyproject\.toml$
+ pass_filenames: false
+ require_serial: true
- id: upgrade-important-versions
name: Upgrade important versions (manual)
entry: ./scripts/ci/prek/upgrade_important_versions.py
diff --git a/scripts/ci/prek/check_distribution_gitignore.py
b/scripts/ci/prek/check_distribution_gitignore.py
new file mode 100755
index 00000000000..0adb8090b93
--- /dev/null
+++ b/scripts/ci/prek/check_distribution_gitignore.py
@@ -0,0 +1,65 @@
+#!/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.
+# /// script
+# requires-python = ">=3.10,<3.11"
+# dependencies = [
+# "rich>=13.6.0",
+# ]
+# ///
+"""
+Check that all distributions have a .gitignore file containing *.iml.
+
+Every directory with a pyproject.toml (a distribution) must have a .gitignore
+file that includes the ``*.iml`` pattern to prevent IntelliJ IDEA module files
+from being committed.
+"""
+
+from __future__ import annotations
+
+import sys
+
+from common_prek_utils import AIRFLOW_ROOT_PATH, console
+
+errors: list[str] = []
+
+for pyproject_path in sorted(AIRFLOW_ROOT_PATH.rglob("pyproject.toml")):
+ relative = pyproject_path.relative_to(AIRFLOW_ROOT_PATH)
+ # Skip directories that are not part of the source tree
+ if any(part.startswith(".") or part in ("out", "node_modules") for part in
relative.parts):
+ continue
+ dist_dir = pyproject_path.parent
+ gitignore_path = dist_dir / ".gitignore"
+ if not gitignore_path.exists():
+ errors.append(f"{gitignore_path.relative_to(AIRFLOW_ROOT_PATH)}:
.gitignore file missing")
+ continue
+ lines = gitignore_path.read_text().splitlines()
+ if "*.iml" not in lines:
+ errors.append(f"{gitignore_path.relative_to(AIRFLOW_ROOT_PATH)}:
missing '*.iml' entry")
+
+if errors:
+ console.print("[red]Errors found in distribution .gitignore files:[/]")
+ for error in errors:
+ console.print(f" [red]✗[/] {error}")
+ console.print()
+ console.print(
+ "[bright_blue]Each distribution directory (containing pyproject.toml)
must have a "
+ ".gitignore file with a '*.iml' entry.[/]"
+ )
+ sys.exit(1)
+
+sys.exit(0)