Skip to main content

compipar-validator

Small, dependency-free validator for Compi test parameter files.

It reads compi.parameters and the optional parameters.metadata.json file used by Compi pipelines, evaluates cross-parameter validation rules, and reports warnings or strict errors.

The package has no GUI dependencies and can be used from Python or from the compipar-validate command line.

Installation

pip install .

For development:

pip install -e ".[dev]"

Supported rules

The top-level validations array in parameters.metadata.json accepts:

{
  "schema_version": 1,
  "parameters": {},
  "validations": [
    {
      "id": "one-of-input",
      "type": "exactly_one",
      "parameters": ["targetFasta", "targetDir"],
      "strict": true
    },
    {
      "id": "optional-mutual-exclusion",
      "type": "at_most_one",
      "parameters": ["modeA", "modeB"]
    },
    {
      "id": "custom-db",
      "type": "requires",
      "when": "useCustomDb",
      "require": ["dbPath", "dbVersion"],
      "message": "When useCustomDb is active, dbPath and dbVersion are required."
    },
    {"id": "any-input", "type": "at_least_one", "parameters": ["a", "b"]},
    {"id": "db-option", "type": "requires_any", "when": "custom", "require": ["path", "url"]},
    {"id": "no-local", "type": "forbids", "when": "container", "forbid": ["local"]},
    {"id": "db-group", "type": "all_or_none", "parameters": ["useDb", "dbPath"]}
  ]
}

Rule types:

  • exactly_one: exactly one parameter in the group must be active.
  • at_most_one: zero or one parameter in the group may be active.
  • at_least_one: at least one parameter in the group must be active.
  • requires: when when is active, every parameter in require must be active.
  • requires_any: when when is active, at least one parameter in require must be active.
  • forbids: when when is active, no parameter in forbid may be active.
  • all_or_none: the group must be completely active or completely inactive.

Required parameters

Per-parameter metadata supports required_value:

"parameters": {
  "targetFasta": {
    "required_value": true,
    "strict": true
  }
}

A required parameter must be active, using the same definition as the validation rules. The violation is reported as:

Parameter 'targetFasta' must be active.

strict controls whether the violation blocks the caller or is only a warning.

Empty/inactive values

A parameter is active when:

  • it is a flag and it is present;
  • or its value is non-empty and is not one of the following empty/false values:
(empty)
0
0.0
FALSE
NO
OFF
NONE
NULL
NA
N/A

These values are treated as not declared. Do not use them to satisfy a required_value or any rule that requires an active parameter.

Definitions are case-insensitive. Non-strict rules produce warnings. Strict rules make the result invalid.

Python API

from pathlib import Path

from compipar_validator import validate_files

result = validate_files(
    Path("parameters.metadata.json"),
    Path("compi.parameters"),
)

if result.valid:
    print("Parameters are valid")
else:
    for violation in result.strict_violations:
        print(f"ERROR [{violation.constraint_id}]: {violation.message}")

Lower-level API:

from compipar_validator import (
    evaluate_constraints,
    load_metadata,
    parse_parameters,
    validate_values,
)

document = load_metadata("parameters.metadata.json")
values = parse_parameters("compi.parameters")
result = validate_values(values, document)

load_metadata also exposes metadata problems through document.metadata_issues. Invalid validation rules are reported and ignored; the rest of the rules are still evaluated.

CLI

compipar-validate \
  --metadata parameters.metadata.json \
  --params compi.parameters

Options:

--metadata PATH   parameters.metadata.json
--params PATH     compi.parameters
--json            Machine-readable output on stdout
--quiet           Suppress non-strict warnings
--version         Show the package version

Exit codes:

Code Meaning
0 Valid, or only non-strict warnings
1 At least one strict violation
2 Invalid inputs or arguments
3 Internal error

Example JSON output:

{
  "valid": false,
  "violations": [
    {
      "id": "one-of-input",
      "message": "Exactly one of these parameters must be active: targetFasta, targetDir.",
      "strict": true
    }
  ],
  "metadata_issues": []
}

Development

ruff check src tests
mypy src
pytest
python -m build

License

MIT

Metadata

Release files for compipar-validator 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for compipar-validator 0.2.0
File Size Uploaded Provenance Actions
compipar_validator-0.2.0.tar.gz 15.6 kB Without provenance Details for compipar_validator-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for compipar-validator 0.2.0
File Interpreter ABI Platform Actions
compipar_validator-0.2.0-py3-none-any.whl Python 3 none any Details for compipar_validator-0.2.0-py3-none-any.whl

Total release size: 29.4 kB

Release files / compipar_validator-0.2.0.tar.gz

Download URL compipar_validator-0.2.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a259596407def57c07a19347d050cab6733349d5331fe107ea6ffff609b88d7c
BLAKE2b-256 checksum
How to use checksums
821efb7aeec5b4f2bf633005ede273316d609dd672dd441167736ca9115720f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.11

Release files / compipar_validator-0.2.0-py3-none-any.whl

Download URL compipar_validator-0.2.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ff2d5ace44b96aa561aa23582df31414de0d96f48de314401b9d242852beaa7
BLAKE2b-256 checksum
How to use checksums
56aeb1235362de82bb2501d4d732395bc13d5d7543eed5cdb2db00d05642f598
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.11

Security for compipar-validator 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page