CCPEM Pipeliner
Guide

Development Guide

Setting up a development environment, running tests and linters, and building the docs


Overview

This page explains how to set up a development environment for ccpem-pipeliner, run its test suite, apply code-quality checks, and build the documentation locally. It is aimed at developers contributing to the library or integrating it into automation systems who need a reproducible, linted, and type-checked workflow. Following this guide ensures your changes meet the project's code standards before submission and that you can iterate quickly against a local documentation build.


Prerequisites

Before starting, make sure you have the following:

  • Python ≥ 3.9 (the CI pipeline tests against Python 3.10; classifiers declare 3.9–3.14)
  • pip (for installing the package and its extras)
  • git (to clone the repository and run pre-commit hooks)
  • pre-commit (installed as part of the dev extra; see Installation)
  • A working internet connection to download dependencies from PyPI

Optional, but needed for certain test categories:

  • RELION executables on PATH (required for live job tests)
  • An MPI runtime such as OpenMPI (required for MPI-enabled job tests)

Installation

Follow these steps to create an isolated development environment and install ccpem-pipeliner from source in editable mode.

  1. Clone the repository (or navigate to your existing checkout):

    git clone https://gitlab.com/ccpem/ccpem-pipeliner.git
    cd ccpem-pipeliner
    
  2. Create and activate a virtual environment:

    python3 -m venv venv/
    source venv/bin/activate
    
  3. Install the package with all development dependencies (includes Black, flake8, mypy, pytest, and pre-commit):

    pip install -e '.[dev]'
    

    The -e flag installs the package in editable mode so that changes to the source are reflected immediately without reinstalling. This step also registers all pipeliner console scripts as entry points.

  4. Install the pre-commit hooks so that Black, flake8, mypy, and other checks run automatically on every git commit:

    pre-commit install
    
  5. Verify the installation by running the setup checker:

    pipeliner.check_setup
    

    This prints four sections: a Python version check, an available job types check, a pipeliner console-scripts check, and a final setup report. If any console script is reported as ERROR, make sure the virtual environment is activated and rerun the editable install from the repository root (pip install --force-reinstall ccpem-pipeliner would instead replace your checkout with the PyPI release):

    pip install -e '.[dev]'
    
  6. (Optional) Install documentation build dependencies if you want to build the HTML docs locally:

    pip install -e '.[docs]'
    

Configuration

Development-time behaviour is controlled through the tool configuration sections in pyproject.toml and the pre-commit configuration in .pre-commit-config.yaml. The relevant settings are listed below.


Black (code formatter)

Configured under [tool.black] in pyproject.toml.

KeyValue / Effect
line-length88 — maximum line length before Black wraps.
target-version['py39', 'py310', 'py311', 'py312', 'py313', 'py314'] — all declared Python versions.
excludeStandard build artefact directories (dist/, build/, venv/, etc.).

Run Black manually at any time:

black pipeliner/

flake8 (linter)

Configured under [tool.flake8] in pyproject.toml.

KeyValue / Effect
max-line-length88 — matches Black's line length.
max-complexity18 — McCabe complexity limit per function.
ignoreE203 (whitespace before :), E266 (too many #), W503 (line break before binary operator) — all are Black-incompatible warnings.

Important: The pre-commit flake8 hook fails a commit if it finds any finding not explicitly ignored, regardless of the flake8.strict git-config setting. To commit while bypassing flake8 checks:

SKIP=flake8 git commit -m "your message"

mypy (type checker)

Configured under [tool.mypy] in pyproject.toml.

KeyValue / Effect
files["pipeliner", "pipeliner_tests"] — directories checked.
python_version"3.10" — type-checking target (matches the CI interpreter).
warn_unused_configstrue — warns about redundant mypy config entries.
[[tool.mypy.overrides]]Several third-party packages (e.g. gemmi, matplotlib, plotly) have ignore_missing_imports = true because they ship no stubs.

Run mypy manually:

mypy pipeliner/

pre-commit hooks

Hook versions are pinned in .pre-commit-config.yaml and must match the versions declared in pyproject.toml's dev optional dependencies.

HookVersionPurpose
black25.11.0Auto-formats Python source.
flake87.3.0Lints for style and complexity.
mypyv1.19.1Checks type annotations.
check-added-large-filesv5.0.0Prevents accidentally committing large binaries.
check-astv5.0.0Validates Python syntax before commit.
check-merge-conflictv5.0.0Catches unresolved merge markers.
check-tomlv5.0.0Validates pyproject.toml syntax.
check-yamlv5.0.0Validates YAML files.

To update hook versions:

pre-commit autoupdate

After updating, also update the matching version pins in pyproject.toml's [project.optional-dependencies].dev section to avoid version mismatches between manual and automatic checks.


Test environment variables

These variables control which test categories are executed:

VariableEffect
PIPELINER_TEST_SLOWSet to any non-empty string to include slow tests (skipped by default).
PIPELINER_TEST_LIVESet to any non-empty string to include tests that execute real external programs. Live tests are only run when the required programs are available.

Build system

The project uses setuptools as its build backend, declared in pyproject.toml:

[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

Usage

Running the test suite

Execute the full (fast) test suite from the repository root:

pytest

To also run slow tests:

PIPELINER_TEST_SLOW=1 pytest

To additionally run tests that call real external programs:

PIPELINER_TEST_SLOW=1 PIPELINER_TEST_LIVE=1 pytest

Running code-quality checks manually

You can run each tool independently without triggering a commit:

# Auto-format all source files (package and tests)
black .

# Lint (uses [tool.flake8] in pyproject.toml)
flake8

# Type-check pipeliner/ and pipeliner_tests/ (the files set in [tool.mypy])
mypy

# Run all pre-commit hooks against all files
pre-commit run --all-files

Building the documentation

  1. Make sure you installed the docs extra (see Installation step 6).

  2. Navigate to the docs/ directory and build HTML:

    cd docs
    make html
    
  3. Open the result in a browser:

    open _build/html/index.html   # macOS
    xdg-open _build/html/index.html  # Linux
    

Adding a built-in job plugin

If you are adding a new job type directly to the pipeliner package:

  1. Create your job class (a subclass of PipelinerJob) in pipeliner/jobs/ or one of its subdirectories.

  2. Add an entry point in pyproject.toml under [project.entry-points."ccpem_pipeliner.jobs"], using the exact class PROCESS_NAME as the key:

    [project.entry-points."ccpem_pipeliner.jobs"]
    "myorg.myjob" = "pipeliner.jobs.mydir.myjob:MyJobClass"
    
  3. Re-install so the entry point is registered:

    pip install -e .
    
  4. Verify the job appears:

    pipeliner --available_jobs myorg
    

Checking which console scripts are registered

pipeliner.check_setup verifies the following six console scripts: pipeliner, pipeliner.bfactor_plot, pipeliner.update_metadata_schema, pipeliner.recover_project, pipeliner.check_setup, and pipeliner.regenerate_results. If any are reported as ERROR, activate the virtual environment you installed into and rerun the editable install from the repository root with pip install -e '.[dev]' (pip install --force-reinstall ccpem-pipeliner would instead replace your editable install of the checkout with the PyPI release).


Examples

Example 1 — Install in editable mode and verify

python3 -m venv venv/
source venv/bin/activate
pip install -e .[dev]
pipeliner.check_setup

Example 2 — Run all pre-commit hooks against every file

Useful before opening a merge request to catch all formatting and linting issues at once:

pre-commit run --all-files

Example 3 — Run only the fast test suite

pytest

Example 4 — Run slow and live tests together

PIPELINER_TEST_SLOW=1 PIPELINER_TEST_LIVE=1 pytest

Example 5 — Commit while skipping the flake8 hook

Use this only when flake8 warnings exist that you intend to fix separately:

SKIP=flake8 git commit -m "WIP: add new tomo job"

Example 6 — Build the HTML documentation

pip install -e .[docs]
cd docs
make html

Then open docs/_build/html/index.html in a web browser.


Example 7 — Update pre-commit hook versions

pre-commit autoupdate

After running this, open pyproject.toml and update the versions in [project.optional-dependencies].dev to match the new versions written into .pre-commit-config.yaml, so that manual tool invocations and hook invocations use identical versions.


Example 8 — Register and verify a new third-party job plugin

In your own package's pyproject.toml:

[project.entry-points."ccpem_pipeliner.jobs"]
"myorg.special_pick" = "mypackage.jobs.special_pick:SpecialPickJob"

After pip install -e . on your package:

pipeliner --available_jobs myorg.special_pick

Troubleshooting

Console scripts not found after installation

Symptom: Running pipeliner.check_setup produces command not found, or pipeliner is not on PATH after pip install.

Likely cause: The entry points were not registered, often because the package was installed into, or is being run from, a different environment than the active one.

Fix: From the repository root, rerun the editable install (pip install --force-reinstall ccpem-pipeliner would instead replace your checkout with the PyPI release):

pip install -e '.[dev]'

If using a virtual environment, ensure it is activated before running the command.


git commit fails with flake8 errors

Symptom: A commit is rejected and the pre-commit output shows flake8 findings, even for code that was not changed.

Likely cause: The repository contains pre-existing flake8 warnings. With the current configuration, any finding blocks a commit.

Fix (temporary): Skip the flake8 hook for this commit:

SKIP=flake8 git commit -m "your message"

Fix (permanent): Resolve the underlying warnings, or add a # noqa: <code> comment on the offending line if suppression is intentional.


Black and flake8 disagree on formatting

Symptom: Black reformats a file, but flake8 then reports an error on the same line (e.g., E203 whitespace before :).

Likely cause: The flake8 version in your environment does not match the pinned version in pyproject.toml, or the ignore list in [tool.flake8] is not being read.

Fix: Ensure you are using the versions pinned in pyproject.toml:

pip install "flake8==7.3.0" flake8-pyproject

Confirm that pyproject.toml contains [tool.flake8] with ignore = ["E203", "E266", "W503"].


mypy reports Missing imports for optional dependencies

Symptom: mypy errors such as Cannot find implementation or library stub for module named "iris_validation".

Likely cause: Optional runtime dependencies (e.g., iris_validation) are not installed in the current environment, and mypy is not reading the project's pyproject.toml (for example, because it was run from outside the repository root), so the setting that ignores them is not applied.

Fix: These modules are listed under [[tool.mypy.overrides]] with ignore_missing_imports = true in pyproject.toml. mypy reads pyproject.toml itself (no plugin is needed). Run the mypy version pinned for the project (mypy==1.19.1) from the repository root:

pip install "mypy==1.19.1"
mypy pipeliner

Documentation build fails with sphinx import errors

Symptom: Running make html in the docs/ directory fails with sphinx-build: command not found (make: *** [html] Error 127), or, if Sphinx is installed elsewhere, with Could not import extension sphinxarg.ext (exception: No module named 'sphinxarg').

Likely cause: The docs extras were not installed.

Fix:

pip install -e '.[docs]'

A custom plugin job is not discovered by pipeliner

Symptom: pipeliner --available_jobs myplugin returns no results after adding the entry point.

Likely cause: The package containing the entry point was not reinstalled after editing pyproject.toml, so the entry point is not registered in the environment.

Fix: Reinstall the plugin package in editable mode:

pip install -e .

Remember that job type discovery via the ccpem_pipeliner.jobs entry-point group occurs every time get_job_types() is called, so a fresh pipeliner --available_jobs call after reinstallation is sufficient to confirm discovery.


pipeliner.check_setup reports a job type as unavailable

Symptom: pipeliner.check_setup lists a job as unavailable and shows '<command>' missing from system path.

Likely cause: The external program required by that job (e.g., MotionCor2, ctffind, Gctf) is not on PATH or in PIPELINER_ADDITIONAL_PROGRAM_PATHS.

Fix: Install the missing program and ensure its executable is on PATH, or set the appropriate environment variable (e.g., PIPELINER_MOTIONCOR2_EXECUTABLE for MotionCor2). The job can still be scheduled and its _run.job file generated regardless of availability; it will fail at execution time if the executable is still missing.


RuntimeError when importing pipeliner on an unsupported platform

Symptom: import pipeliner logs Unable to set up pipeliner python environment, and accessing any setting later raises RuntimeError.

Likely cause: Pipeliner supports Linux and macOS only. Running on Windows or another unsupported OS triggers this error.

Fix: Use a Linux or macOS environment (including WSL2 on Windows). Container-based development environments are also suitable.