liveBook · Manning

Static analysis

As explained in Data Pipelines with Apache Airflow, Second Edition

Static code analysis is the examination of source code without executing it to detect defects, style violations, or other issues.

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

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Explains checker roles, commands, diagnostics, configuration, and CI integration, but stops short of checker internals.
Examples
Uses Flake8 commands, an unused-import diagnostic, and a GitHub Actions workflow combining checks with DAG tests.
What it assumes
Assumes Python code and basic command-line use while introducing style guides, checker commands, diagnostics, and CI steps.
What you can do after
Apply it via Flake8 or Pylint locally and automate checks with GitHub Actions before merging Python DAG changes.
How it connects
Connects static analysis with Python style guides, Flake8, Pylint, Black, GitHub Actions, and CI/CD.

Also explained in

Compare how 6 books explain static analysis →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.