Skip to main content

Make Python ML Code Consistent with Developer Tools

Updated 2 min readMarkdown
Part of seriesMLOPS
Make Python ML Code Consistent with Developer Tools

MLOps is not only about models and infrastructure. It also depends on ordinary software-engineering practices. Formatting, linting, and automated checks help keep an ML repository maintainable.

Makefile: memorable project commands

A Makefile provides short commands for common tasks:

install:
    uv sync

lint:
    ruff check .

format:
    ruff format .

test:
    pytest

Instead of remembering long commands, a developer can run make lint or make test. The commands also document the project's normal workflow.

Ruff and Black

A linter checks code for issues such as unused imports, undefined names, and style problems. Ruff performs many linting checks and can also format Python code.

Black is another widely used Python formatter. Teams generally choose a consistent formatting approach rather than having developers format files differently.

Example:

ruff check .
ruff format .

Linting and formatting solve different problems: formatting makes code consistent, while linting identifies suspicious or non-compliant code.

pre-commit: check before committing

A pre-commit hook runs selected checks before Git creates a commit. This catches common issues early, rather than discovering them in CI.

A typical workflow is:

  1. Make a code change.
  2. Stage the change with Git.
  3. Commit.
  4. Pre-commit runs configured checks.
  5. Fix any failures and commit again.

Why this matters for ML

A training script is production code when it becomes part of a repeatable pipeline. A typo, stale import, or inconsistent formatting may not change model quality, but it makes the system harder to review and maintain.

Takeaway: use automation to enforce simple standards. Save human attention for model design, data quality, and system behavior.

No comments yet. Be the first to comment.