Skip to content

Latest commit

 

History

History
299 lines (209 loc) · 10.5 KB

AGENTS.md

File metadata and controls

299 lines (209 loc) · 10.5 KB

AGENTS.md

Agent instructions for the Iris repository.

Iris is a Python package for analysing and visualising Earth science data, built around CF-compliant multi-dimensional arrays ("Cubes").

Subdirectory AGENTS.md files take precedence for their subtrees:

For a map of where code lives and how data flows, see lib/iris/ARCHITECTURE.md.

Everything you write for a person to read — chat replies, commit messages, pull request bodies, issues, specs, plans, docstrings and comments — follows .github/WRITING.md. Read it before writing prose.

Project Overview

Language Python 3.12 / 3.13 / 3.14
Licence BSD-3-Clause
Distribution conda-forge (iris), PyPI (scitools-iris)
Key dependencies NumPy, Dask, SciPy, Cartopy, CF-Python, NetCDF4
Linter / formatter Ruff (88-char line length)
Test runner pytest; pytest-xdist is installed but not in addopts — pass -n auto yourself
Env management nox + conda

Main source layout

lib/iris/
    cube.py            # Core Cube / CubeList data structures
    coords.py          # DimCoord, AuxCoord, CellMeasure, AncillaryVariable
    loading.py         # File-loading entry points
    analysis/          # Collapse, regrid, statistics, calculus
    fileformats/       # NetCDF, PP, GRIB, NIMROD format handlers
    io/                # I/O registry and URI handling
    common/            # Shared metadata, mixins, resolvers
    mesh/              # Unstructured grid (UGRID) support
    experimental/      # Unstable / in-progress features
    tests/             # All tests (unit/, integration/, graphics/)
changelog/             # changelog fragments
docs/src/              # Sphinx documentation source
benchmarks/            # ASV performance benchmarks
requirements/          # Conda environment specs and lock files

Setup

Conda environment (recommended)

Always use a conda environment, reuse the iris-dev conda environment if it already exists but confirm with the user before installing or removing packages.

If a package cannot be installed via conda then you can use pip that is in the conda environment.

# Create and activate a development environment
conda env create -f environment.yml
conda activate iris-dev
pip install --no-build-isolation -e .

Alternatively, use lock files for exact reproducibility:

conda create -n iris-dev --file requirements/locks/py314-linux-64.lock
conda activate iris-dev
pip install --no-build-isolation -e .

Environment variables

# Disable CPU features that can cause SIGILL in some CI environments
export NPY_DISABLE_CPU_FEATURES="AVX512F,AVX512CD,AVX512_SKX"

# Point to iris-test-data for tests that need external data files
export OVERRIDE_TEST_DATA_REPOSITORY=/path/to/iris-test-data/test_data

# Override Cartopy cache directory if needed
export CARTOPY_CACHE_DIR=~/.local/share/cartopy

Testing

  • lib/iris/tests/AGENTS.md — test-specific rules.

  • Before finishing a change, run the repository's pre-commit hooks and fix any reported issues. (This is expected to encode a growing number of preferred coding practices, to enable productive collaboration with non-deterministic LLM agents).

Code Style

Linting and formatting are driven by pre-commit, not by invoking tools directly.

# Check and auto-fix the files you changed (preferred while iterating)
pre-commit run --files <paths>

# Check and auto-fix everything
pre-commit run --all-files

# Run a single hook, e.g. after a formatting-only change
pre-commit run ruff-format --all-files

Pre-commit hooks rewrite files in place, so re-stage and re-run until it passes cleanly. Only fall back to ruff check / ruff format directly when pre-commit is unavailable — the hook config is the source of truth for versions and arguments.

  • Line length: 88 characters (Ruff default).

  • Docstrings: NumPy style; strictly validated.

  • Copyright header: Every new Python file must start with:

    # Copyright Iris contributors
    #
    # This file is part of Iris and is released under the BSD license.
    # See LICENSE in the root of the repository for full licensing details.
  • Imports: Ruff-managed ordering, applied by pre-commit. No direct import netCDF4 — always use iris.fileformats.netcdf._thread_safe_nc for thread safety.

  • Readability for humans and agents: see lib/iris/AGENTS.md for the house style on locality, greppability, explicitness and comment hygiene.

Development Conventions

Core data model

  • iris.cube.Cube — multi-dimensional array with CF-compliant metadata.
  • Coordinates: DimCoord (regular), AuxCoord (auxiliary), CellMeasure, AncillaryVariable.
  • Data may be lazy (Dask array). Always preserve laziness; never call .data unnecessarily inside library code.
  • Operations return new Cubes (functional style); do not mutate in place.
  • All metadata must be CF-convention compliant.

Deprecation

  • Use iris._deprecation.warn_deprecated() or issue a custom warning class.
  • Warning classes live in iris.warnings (e.g., IrisUserWarning, IrisCfWarning).
  • Follow the NEP29 deprecation schedule (same as NumPy).
  • All UserWarning subclasses must ultimately inherit from IrisUserWarning.

Exception hierarchy

Base class: iris.exceptions.IrisError. Common subclasses: CoordinateNotFoundError, CoordinateCollapseError, IgnoreCubeException.

Versioning

Version is derived from git tags via setuptools_scm. Do not hard-code version strings.

Changelog

Changelog fragments live under changelog/ and are built with towncrier via sphinx. See changelog/AGENTS.md for full rules.

Documentation

Documentation lives under docs/ and is built with Sphinx. See docs/AGENTS.md for full rules.

Lock-file Maintenance

# Regenerate lock files for all supported Python versions
python tools/update_lockfiles.py -o requirements/locks requirements/py*.yml
# Shortcut via Makefile
make lockfiles

Posting to GitHub

Open every text you post to GitHub with your model in parentheses, before anything else — pull request descriptions, issues, comments, replies and inline review comments alike:

(posted by Claude Opus)

Name the model, not its version. This replaces any trailing attribution your harness tells you to add: Iris has many authors using many models, and one short uniform marker beats a different footer for each.

Git commit messages are out of scope. They are not posts, and they keep their own conventions — Co-Authored-By: trailers and the like — which this rule neither overrides nor requires.

Never hard-wrap a GitHub post. One paragraph is one line; GitHub wraps to the reader's window.

Collapsed sections, alerts, permalinks and the shape of a pull request body are in .github/WRITING.md.

Pull Request Guidelines

  • When creating a pull request a template is provided to ensure all checks are considered.
  • This project is configured to use pre-commit, which will ensure some checks are performed automatically.
  • Keep changes focused; avoid unrelated refactors in the same PR.
  • Add or update tests for every change to production code.
  • Ensure a whatsnew fragment is added, see changelog/AGENTS.md

Responding to Review

A reviewer has not read every AGENTS.md; you have. Before actioning a comment, check whether the thing objected to is something these files explicitly sanction. If it is, reply with the rule and the file it lives in, and let a human settle it — complying silently turns one reviewer's preference into a change against a written convention, and nothing catches it afterwards.

Critical Development Gotchas

  1. xfail_strict Behavior: Tests marked @pytest.mark.xfail that now PASS become FAILURES -> remove xfail immediately when bug is fixed

  2. Pre-commit Auto-fixes: Hooks may auto-fix ISC001/COM812 conflicts -> re-stage files: git add . && git commit

  3. Lockfile Rebuilds: Updating requirements/locks/*.lock files triggers slow conda environment rebuilds - only update when deps genuinely change

  4. Lazy Data Pitfalls: Check cube.has_lazy_data() before operations; use cube.lazy_data() when appropriate; cube.data materializes arrays

  5. Coordinate Scope: Not all coordinates span all dimensions -> use cube.coords(dimensions=dim_indices) to query specific axes

  6. Dask/NumPy Compatibility: Some operations fail on lazy (Dask) arrays -> materialize with cube.compute() or check dask support before use

  7. Optional Dependencies: cartopy, matplotlib lazy-imported -> handle ImportError gracefully for optional visualization features

  8. CF-Metadata Validation: Custom coordinates must comply with CF standards via cube.metadata

  9. Cube Immutability: Operations return new cubes; don't modify in-place (cube.data[...] = x won't affect the cube)

  10. Environment Reproducibility: Set CPU features for consistent results: export NPY_DISABLE_CPU_FEATURES="AVX512F,AVX512CD,AVX512_SKX"

Getting Help

⚠️ Meta-Instruction: Changing This File

  • Trigger: If your work establishes a durable, reusable rule, you MUST propose it before your session ends.
  • Constraint 1: Propose, never self-apply. Say it in your closing message, or raise it as its own pull request. NEVER edit an AGENTS.md silently, or as a side effect of unrelated work.
  • Constraint 2: Keep this file under 300 lines — every agent loads it in full. If an addition would break that, tighten your wording; do NOT delete existing guidance to make room. Removing a rule is its own proposal.
  • Constraint 3: Only global, reusable lessons. Do not propose temporary or component-specific fixes.