Python for Build Automation

Python as the language you write build tooling in, not web apps. Replacing untestable YAML and shell with a packaged, unit-tested CLI that every build agent runs at a pinned version.

Overview

A specific dialect of Python

'Advanced Python used to automate workflows and enhance build processes' is not web frameworks or dataframes. It asks whether you can write the tool that builds, tests, signs and publishes the product, and whether a team can maintain it for five years.

The change it describes has a before and an after. Before, the YAML owns the logic: pipeline YAML with embedded bash that fails only in CI. After, Python owns the logic: thin YAML with one command per step, calling a buildtool package that is a CLI, pinned, typed and tested.

Key concepts

  • subprocess.run with a list
  • shell=True
  • timeout and TimeoutExpired
  • pathlib.Path
  • Console entry point
  • Lockfile pinning
  • tmp_path and monkeypatch

Interview questions

  • Make the case for replacing pipeline YAML and shell with Python. What is the actual argument, and where does it stop?
  • Write the subprocess call you would actually ship in build tooling, and explain every argument.
  • How do you unit test build tooling? Give the fixtures and a concrete test.
  • How do you package and pin build tooling so every agent runs the identical version?
  • You need a CI matrix that depends on what changed. How do you generate it programmatically, and what breaks?

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio