devops.cpp.state

State persistence for incremental C++ checks.

Functions

any_failed(state)

Return True if any file in state has a failed result.

compute_config_hash(config_file)

Return a hash of the raw contents of the TOML config file.

filter_incremental(files, state)

Return only the files from files that need checking.

load_state(state_file[, config_hash])

Load per-file check state from a JSON file.

needs_check(path, state)

Return True if path should be re-checked.

save_state(state_file, state)

Write the state dict to a JSON file.

update_entry(state, path, *, passed)

Record the result for a single file in the state dict.

devops.cpp.state.compute_config_hash(config_file)[source]

Return a hash of the raw contents of the TOML config file.

Parameters:

config_file (Path | None) – Path to the TOML config file, or None if none is in use.

Returns:

str | None – Hex SHA-256 digest, or None if there is no (readable) config file.

Return type:

str | None

devops.cpp.state.load_state(state_file, config_hash=None)[source]

Load per-file check state from a JSON file.

The state is invalidated (an empty state is returned) when the config hash it was saved with differs from config_hash, i.e. whenever the TOML config file changed, appeared or disappeared since the last run.

Parameters:
  • state_file (Path) – Path to the state file. Returns an empty dict if the file does not exist or cannot be parsed.

  • config_hash (str | None) – Hash of the current config file as returned by compute_config_hash. The returned state carries it so that save_state persists it.

Returns:

dict[str, dict] – Mapping of file path string to {"mtime": float, "result": str}.

Return type:

dict[str, dict]

devops.cpp.state.save_state(state_file, state)[source]

Write the state dict to a JSON file.

Parameters:
  • state_file (Path) – Destination path.

  • state (dict[str, dict]) – State mapping as produced by update_entry.

Return type:

None

devops.cpp.state.needs_check(path, state)[source]

Return True if path should be re-checked.

A file needs checking when it is new (not in state), previously failed, or its modification time differs from the stored value.

Parameters:
  • path (Path) – File to test.

  • state (dict[str, dict]) – State as returned by load_state.

Returns:

bool

Return type:

bool

devops.cpp.state.filter_incremental(files, state)[source]

Return only the files from files that need checking.

Parameters:
  • files (list[Path]) – Full list of candidate files.

  • state (dict[str, dict]) – State as returned by load_state.

Returns:

list[Path]

Return type:

list[Path]

devops.cpp.state.update_entry(state, path, *, passed)[source]

Record the result for a single file in the state dict.

Parameters:
  • state (dict[str, dict]) – State dict to update in place.

  • path (Path) – File that was checked.

  • passed (bool) – Whether all checks passed for this file.

Return type:

None

devops.cpp.state.any_failed(state)[source]

Return True if any file in state has a failed result.

Parameters:

state (dict[str, dict]) – State as returned by load_state.

Returns:

bool

Return type:

bool