Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ repos:
files: ^airflow/models/taskinstance.py$|^airflow/models/taskinstancehistory.py$
pass_filenames: false
require_serial: true
- id: check-default-configuration
name: Check the default configuration
entry: ./scripts/ci/pre_commit/check_default_configuration.py
language: python
additional_dependencies: ['rich>=12.4.4']
always_run: true
- id: check-deferrable-default
name: Check and fix default value of default_deferrable
language: python
Expand Down
2 changes: 2 additions & 0 deletions contributing-docs/08_static_code_checks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ require Breeze Docker image to be built locally.
+-----------------------------------------------------------+--------------------------------------------------------+---------+
| check-decorated-operator-implements-custom-name | Check @task decorator implements custom_operator_name | |
+-----------------------------------------------------------+--------------------------------------------------------+---------+
| check-default-configuration | Check the default configuration | |
+-----------------------------------------------------------+--------------------------------------------------------+---------+
| check-deferrable-default | Check and fix default value of default_deferrable | |
+-----------------------------------------------------------+--------------------------------------------------------+---------+
| check-docstring-param-types | Check that docstrings do not specify param types | |
Expand Down
6 changes: 3 additions & 3 deletions dev/breeze/doc/images/output_static-checks.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_static-checks.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c7fbc4eef958e14a7d7fba9a9a101fcd
26a564635ee0c2aaecaea40dd7e93779
1 change: 1 addition & 0 deletions dev/breeze/src/airflow_breeze/pre_commit_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"check-core-deprecation-classes",
"check-daysago-import-from-utils",
"check-decorated-operator-implements-custom-name",
"check-default-configuration",
"check-deferrable-default",
"check-docstring-param-types",
"check-example-dags-urls",
Expand Down
37 changes: 37 additions & 0 deletions scripts/ci/pre_commit/check_default_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/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.
from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.resolve()))
from common_precommit_utils import (
initialize_breeze_precommit,
run_command_via_breeze_shell,
validate_cmd_result,
)

initialize_breeze_precommit(__name__, __file__)

cmd_result = run_command_via_breeze_shell(
["/opt/airflow/scripts/in_container/run_check_default_configuration.py"],
backend="sqlite",
)

validate_cmd_result(cmd_result)
58 changes: 58 additions & 0 deletions scripts/in_container/run_check_default_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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.
from __future__ import annotations

import os
import subprocess
import tempfile

list_default_config_cmd = [
"airflow",
"config",
"list",
"--default",
]
lint_config_cmd = [
"airflow",
"config",
"lint",
]
expected_output = "No issues found in your airflow.cfg."

if __name__ == "__main__":
with tempfile.TemporaryDirectory() as tmp_dir:
# Write default config cmd output to a temporary file
default_config_file = os.path.join(tmp_dir, "airflow.cfg")
with open(default_config_file, "w") as f:
result = subprocess.run(list_default_config_cmd, stdout=f)
if result.returncode != 0:
print(f"\033[0;31mERROR: when running `{' '.join(list_default_config_cmd)}`\033[0m\n")
exit(1)
# Run airflow config lint to check the default config
env = os.environ.copy()
env["AIRFLOW_HOME"] = tmp_dir
env["AIRFLOW_CONFIG"] = default_config_file
result = subprocess.run(lint_config_cmd, capture_output=True, env=env)

output: str = result.stdout.decode().strip()
if result.returncode != 0 or expected_output not in output:
print(f"\033[0;31mERROR: when running `{' '.join(lint_config_cmd)}`\033[0m\n")
print(output)
exit(1)
print(output)
exit(0)
Loading