You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "jason810496 (via GitHub)" <gi...@apache.org> on 2025/02/10 12:53:56 UTC
[PR] Add pre-commit check for default configuration [airflow]
jason810496 opened a new pull request, #46622:
URL: https://github.com/apache/airflow/pull/46622
**Depends on: #46544**
related: #46517
related discussion: https://github.com/apache/airflow/pull/46544#issuecomment-2642068812
## Why
In the `3.0.0a1` release, some configurations have not yet been migrated or deprecated in the default configuration.
## How
To prevent this from happening, add a pre-commit hook with `airflow config lint`.
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit check for default configuration [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #46622:
URL: https://github.com/apache/airflow/pull/46622#discussion_r1953934097
##########
scripts/in_container/run_check_default_configuration.py:
##########
@@ -0,0 +1,59 @@
+#!/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
+
+default_config_cmd = [
+ "airflow",
+ "config",
+ "list",
+ "--default",
+]
+check_lint_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(default_config_cmd, stdout=f)
+ if result.returncode != 0:
+ print("\033[0;31mERROR: when running `airflow config list`\033[0m\n")
Review Comment:
this string can be refactored as a constant to avoid
```suggestion
print("\033[0;31mERROR: when running `airflow config lint`\033[0m\n")
```
##########
scripts/in_container/run_check_default_configuration.py:
##########
@@ -0,0 +1,59 @@
+#!/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
+
+default_config_cmd = [
+ "airflow",
+ "config",
+ "list",
+ "--default",
+]
+check_lint_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(default_config_cmd, stdout=f)
+ if result.returncode != 0:
+ print("\033[0;31mERROR: when running `airflow config list`\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(check_lint_cmd, capture_output=True, env=env)
+
+ output: str = result.stdout.decode().strip()
+ if result.returncode != 0 or expected_output not in output:
+ print("\033[0;31mERROR: when running `airflow config lint`\033[0m\n")
+ print(output)
+ exit(1)
+ else:
+ print(output)
+ exit(0)
Review Comment:
```suggestion
print(output)
exit(0)
```
##########
scripts/in_container/run_check_default_configuration.py:
##########
@@ -0,0 +1,59 @@
+#!/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
+
+default_config_cmd = [
+ "airflow",
+ "config",
+ "list",
+ "--default",
+]
+check_lint_cmd = [
+ "airflow",
+ "config",
+ "lint",
+]
Review Comment:
```suggestion
config_lint_cmd = ["airflow", "config", "lint"]
default_config_lint_cmd = config_lint_cmd[:] + ["--default"]
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit check for default configuration [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #46622:
URL: https://github.com/apache/airflow/pull/46622#discussion_r1950142781
##########
scripts/ci/pre_commit/check_default_configuration.py:
##########
@@ -0,0 +1,43 @@
+#!/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 subprocess
+
+cmd = [
+ "airflow",
+ "config",
+ "lint",
+]
Review Comment:
Good point, thanks for the reminder! I've refactored it to redirect the output of `airflow config lint --default` to `tempdir/airflow.cfg` and run `airflow config lint` in `tempdir` as `AIRFLOW_HOME`.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit check for default configuration [airflow]
Posted by "jedcunningham (via GitHub)" <gi...@apache.org>.
jedcunningham commented on code in PR #46622:
URL: https://github.com/apache/airflow/pull/46622#discussion_r1949527875
##########
scripts/ci/pre_commit/check_default_configuration.py:
##########
@@ -0,0 +1,43 @@
+#!/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 subprocess
+
+cmd = [
+ "airflow",
+ "config",
+ "lint",
+]
Review Comment:
This probably needs to be a bit smarter - I don't think we should be checking the airflow.cfg a contributor has on their machine, but the actual defaults from `config.yml`.
Maybe override AIRFLOW_HOME to a tempdir, or devnull?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit check for default configuration [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #46622:
URL: https://github.com/apache/airflow/pull/46622#discussion_r1957482443
##########
scripts/in_container/run_check_default_configuration.py:
##########
@@ -0,0 +1,59 @@
+#!/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
+
+default_config_cmd = [
+ "airflow",
+ "config",
+ "list",
+ "--default",
+]
+check_lint_cmd = [
+ "airflow",
+ "config",
+ "lint",
+]
Review Comment:
ah, yep, I did misunderstand it. I thought we have a `--default` flag for lint. Yep that doesn't make sense. Then, maybe rename it to `list_default_config_cmd` and `lint_config_cmd`?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit check for default configuration [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #46622:
URL: https://github.com/apache/airflow/pull/46622
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add pre-commit check for default configuration [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #46622:
URL: https://github.com/apache/airflow/pull/46622#discussion_r1957480420
##########
scripts/in_container/run_check_default_configuration.py:
##########
@@ -0,0 +1,59 @@
+#!/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
+
+default_config_cmd = [
+ "airflow",
+ "config",
+ "list",
+ "--default",
+]
+check_lint_cmd = [
+ "airflow",
+ "config",
+ "lint",
+]
Review Comment:
Thanks, @Lee-W!
However, the script actually runs as:
```sh
airflow config list --default > $AIRFLOW_CONFIG && airflow config lint
```
Is there a misunderstanding regarding this part of the suggestion?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org