Static analysis examines Python code without executing it, reporting convention violations and quality issues such as unused imports. Flake8 and Pylint are static checkers; their findings help keep DAG code readable and maintainable. section 12.1.1 section 10.1.2
A practical static-analysis workflow can:
- Run Flake8 across the dags directory to detect issues such as unused imports. section 12.1.1
- Run Pylint for a broader default set of checks, while configuring either checker to enable or disable selected rules. section 12.1.1
- Place checks in CI/CD so every push is analyzed and a failing result can prevent a merge. section 10.1.2
Running Flake8 locally
Install Flake8, then check Python files in the DAG directory: python -m pip install flake8; python -m flake8 dags/*.py. A report can identify an unused PythonOperator import with code F401 and its file location. section 12.1.1
Listing 10.9 Example GitHub Actions pipeline for Airflow project
name: Python static checks and tests
on: [push]
jobs:
testing:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.12.4
- name: Install Flake8
run: pip install flake8
- name: Run Flake8
run: flake8
- name: Install Pylint
run: pip install pylint
- name: Run Pylint
run: find . -name "*.py" | xargs pylint --output-format=colorized
- name: Install Black
run: pip install black
- name: Run Black
run: find . -name "*.py" | xargs black --check
- name: Install dependencies
run: pip install apache-airflow pytest
- name: Test DAG integrity
run: pytest tests/
A GitHub Actions workflow combines Flake8 and Pylint with Black and DAG integrity tests, illustrating how static analysis becomes an automated quality gate. section 10.1.2





