Skip to main content

Cartesian product and coproduct variantization of test parameters

Installation

Currently we recommend simple local installation via pip

cd cartconf
pip install -e .

Direct python parser use

Given the Cartesian configuration file example1.cfg

variants:
    - qemu_kvm_fedora:

    - qemu_kvm_centos:

    - qemu_kvm_ubuntu:

    - qemu_kvm_kali:

    - qemu_kvm_windows_7:

    - qemu_kvm_windows_10:

variants:
    - vm1:
        main_vm = vm1
        only qemu_kvm_centos, qemu_kvm_fedora
        suffix _vm1
    - vm2:
        main_vm = vm2
        only qemu_kvm_windows_10, qemu_kvm_windows_7
        suffix _vm2
    - vm3:
        main_vm = vm3
        only qemu_kvm_ubuntu, qemu_kvm_kali
        suffix _vm3

join vm1 vm2 vm3

This can be parsed using cartconf as

./parse.py tests/example1.cfg "no qemu_kvm_centos"

which will result in the following parameter dictionaries

dict    1:  vm1.qemu_kvm_fedora.vm2.qemu_kvm_windows_7.vm3.qemu_kvm_ubuntu
dict    2:  vm1.qemu_kvm_fedora.vm2.qemu_kvm_windows_7.vm3.qemu_kvm_kali
dict    3:  vm1.qemu_kvm_fedora.vm2.qemu_kvm_windows_10.vm3.qemu_kvm_ubuntu
dict    4:  vm1.qemu_kvm_fedora.vm2.qemu_kvm_windows_10.vm3.qemu_kvm_kali

Avocado varianter plugin use

Given the Cartesian configuration file example2.cfg

word = abc
variants:
    - a:
        x = va
        word = ${x}
    - b:
        x = vb
variants:
    - 1:
        y = w1
    - 2:
        y = w2
        word = ${y}

This can be parsed using the cartconf avocado varianter plugin as

avocado variants -C tests/example2.cfg -o aaa=bbb c=d --only a 1

which will result in a job with the following test parameters

dict    1:  1.a
    _name_map_file = {'example.cfg': '1.a'}
    _short_name_map_file = {'example.cfg': '1.a'}
    aaa = bbb
    c = d
    dep = []
    name = 1.a
    shortname = 1.a
    word = va
    x = va
    y = w1

Rust library and command-line parser use

The Rust library and its cartconf binary use the same parser implementation:

cargo build
cargo run -- tests/example1.cfg -- "no qemu_kvm_centos"

Rust consumers can use the public API directly:

use cartconf::{parse_dicts, ParamKeyHashMapExt};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    pyo3::Python::initialize();
    let dicts = parse_dicts(
        String::new(), "param = val\n".to_string(), None, false, None,
    )?;
    for dict in dicts {
        println!("{:?}", dict.get_str("param"));
    }
    Ok(())
}

For incremental parsing and streaming dictionary generation, use Tree and PreDict as described below.

PyO3 remains a required dependency. Standalone callers initialize Python to support the PyErr values returned by the Rust API. Of course, if there is ever higher interest for the rust crate equivalent we may make PyO3 optional and de-prioritize the python exports and python errors.

Main Rust structures for parsing

Parsed syntax and dictionary generation are represented by separate structures, the former represented by an immutable AST while the latter by traversal state machine:

  • Node describes a variant or conditional block: names and labels, dependencies, content steps and links to further nodes. Child and conditional nodes use shared Rc<Node> handles; content processing reads their syntax without mutating it. Detached nodes remain editable for construction and inspection. Nodes carry no traversal state or failure history.

  • Tree holds the root of an immutable abstract syntax tree (AST). Its parse_file() and parse_string() methods return a new snapshot, copying the root and sharing existing descendants. Retaining a tree therefore preserves a configuration independently of later parsing.

  • PreDict is a stateful dictionary evaluator. Its branch holds shared nodes; traversal frames accumulate context, content, names and dependencies. update_from_tree(snapshot) supplies a shared root for evaluation. Failure records belong to the evaluator and are indexed by node ID: they survive frame resets but are checked against the current filters and context before pruning another visit.

    Each join selection uses a separate evaluator seeded from processed parent frames, including caller-supplied initial state, with fresh traversal and failure history. Join expansion stores join-free instructions and the selection’s only filter in processed_content, preserving the shared nodes. Evaluation borrows content and label strings, copying retained instructions and output values as needed.

  • Parser is the Python interface holding the current snapshot in ast. Parsing replaces that snapshot. Each active get_dicts_gen() iterator owns a fresh PreDict and can interleave with others; further parsing leaves its snapshot unchanged.

There are additional structures for ContentStep, Label and even Lexer and Reader as well as low level enums for Tokens and Filters but the above focuses on the highest level interface.

Backus-Naur form style grammar

Filter syntax:

  • , means OR

  • .. means AND

  • . means IMMEDIATELY-FOLLOWED-BY

  • (xx=yy) where xx=VARIANT_NAME and yy=VARIANT_VALUE

Example:

qcow2..(guest_os=Fedora).14, RHEL.6..raw..boot, smp2..qcow2..migrate..ide

means match all dicts whose names have:

(qcow2 AND ((guest_os=Fedora) IMMEDIATELY-FOLLOWED-BY 14)) OR
((RHEL IMMEDIATELY-FOLLOWED-BY 6) AND raw AND boot) OR
(smp2 AND qcow2 AND migrate AND ide)

Note:

  • qcow2..Fedora.14 is equivalent to Fedora.14..qcow2.

  • qcow2..Fedora.14 is not equivalent to qcow2..14.Fedora.

  • ide, scsi is equivalent to scsi, ide.

Filters can be used in 3 ways:

only <filter>
no <filter>
<filter>:

The last one starts a conditional block.

Formal definition: Regexp come from python. They’re not deterministic, but more readable for people. Spaces between terminals and nonterminals are only for better reading of definitions.

The base of the definitions come verbatim as follows:

E = {\\n, #, :, "-", =, +=, <=, ~=, ?=, ?+=, ?<=, !, < , del, @, variants, include, only, no, name, value}

N = {S, DEL, FILTER, FILTER_NAME, FILTER_GROUP, PN_FILTER_GROUP, STAT, VARIANT, VAR-TYPE, VAR-NAME, VAR-NAME-F, VAR, COMMENT, TEXT, DEPS, DEPS-NAME-F, META-DATA, IDENTIFIER}``


I = I^n | n in N              // indentation from start of line
                              // where n is indentation length.
I = I^n+x | n,x in N          // indentation with shift

start symbol = S
end symbol = eps

S -> I^0+x STATV | eps

I^n    STATV
I^n    STATV

I^n STATV -> I^n STATV \\n I^n STATV | I^n STAT | I^n variants VARIANT
I^n STAT -> I^n STAT \\n I^n STAT | I^n COMMENT | I^n include INC
I^n STAT -> I^n del DEL | I^n FILTER

DEL -> name \\n

I^n STAT -> I^n name = VALUE | I^n name += VALUE | I^n name <= VALUE | I^n name ~= VALUE
I^n STAT -> I^n name ?= VALUE | I^n name ?+= VALUE | I^n name ?<= VALUE

VALUE -> TEXT \\n | 'TEXT' \\n | "TEXT" \\n

COMMENT_BLOCK -> #TEXT | //TEXT
COMMENT ->  COMMENT_BLOCK\\n
COMMENT ->  COMMENT_BLOCK\\n

TEXT = [^\\n] TEXT            //python format regexp

I^n    variants VAR #comments:             add possibility for comment
I^n+x       VAR-NAME: DEPS
I^n+x+x2        STATV
I^n         VAR-NAME:

IDENTIFIER -> [A-Za-z0-9][A-Za-z0-9_-]*

VARIANT -> VAR COMMENT_BLOCK\\n I^n+x VAR-NAME
VAR -> VAR-TYPE: | VAR-TYPE META-DATA: | :         // Named | unnamed variant

VAR-TYPE -> IDENTIFIER

variants _name_ [xxx] [zzz=yyy] [uuu]:

META-DATA -> [IDENTIFIER] | [IDENTIFIER=TEXT] | META-DATA META-DATA

I^n VAR-NAME -> I^n VAR-NAME \\n I^n VAR-NAME | I^n VAR-NAME-N \\n I^n+x STATV
VAR-NAME-N -> - @VAR-NAME-F: DEPS | - VAR-NAME-F: DEPS
VAR-NAME-F -> [a-zA-Z0-9\\._-]+                  // Python regexp

DEPS -> DEPS-NAME-F | DEPS-NAME-F,DEPS
DEPS-NAME-F -> [a-zA-Z0-9\\._- ]+                // Python regexp

INC -> name \\n


FILTER_GROUP: STAT
    STAT

I^n STAT -> I^n PN_FILTER_GROUP | I^n ! PN_FILTER_GROUP

PN_FILTER_GROUP -> FILTER_GROUP: \\n I^n+x STAT
PN_FILTER_GROUP -> FILTER_GROUP: STAT \\n I^n+x STAT

only FILTER_GROUP
no FILTER_GROUP

FILTER -> only FILTER_GROUP \\n | no FILTER_GROUP \\n

FILTER_GROUP -> FILTER_NAME
FILTER_GROUP -> FILTER_GROUP..FILTER_GROUP
FILTER_GROUP -> FILTER_GROUP,FILTER_GROUP

FILTER_NAME -> FILTER_NAME.FILTER_NAME
FILTER_NAME -> VAR-NAME-F | (VAR-NAME-F=VAR-NAME-F)

Metadata

Release files for avocado-framework-plugin-varianter-cartconf 1.0.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 avocado-framework-plugin-varianter-cartconf 1.0.0
File Size Uploaded Provenance Actions
avocado_framework_plugin_varianter_cartconf-1.0.0.tar.gz 125.1 kB Without provenance Details for avocado_framework_plugin_varianter_cartconf-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for avocado-framework-plugin-varianter-cartconf 1.0.0
File Interpreter ABI Platform Actions
avocado_framework_plugin_varianter_cartconf-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for avocado_framework_plugin_varianter_cartconf-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Total release size: 1.3 MB

Release files / avocado_framework_plugin_varianter_cartconf-1.0.0.tar.gz

Download URL avocado_framework_plugin_varianter_cartconf-1.0.0.tar.gz
Size 125.1 kB
Tags Source
SHA-256 checksum
How to use checksums
475716be7a12f28161346856b7117840d9641aa8354d51f6bd0c3bb358682169
BLAKE2b-256 checksum
How to use checksums
9a5d8142f577da973cf929db82b66c8cb34585da6e971599e41ee0ea77f3d618
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / avocado_framework_plugin_varianter_cartconf-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL avocado_framework_plugin_varianter_cartconf-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6ad66da491e0ce1c372802fdc0cf77abe1d4751c53c70d7fa868060050601384
BLAKE2b-256 checksum
How to use checksums
860266be9f98fab2beff821c0d1bfd59bd47ceaab4d98f32e50f73cc20e8aee0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for avocado-framework-plugin-varianter-cartconf 1.0.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