Skip to content

Make problem.yaml available to generators, validators, and various statements #574

@thorehusfeldt

Description

@thorehusfeldt

Aside about \constant{name} in LaTeX:

What we seem to want to support is a mechanism for the Latex source to refer to values defined in problem.yaml. I clean way to do that (which would require minimal effort do define) is \problem{foo} where foo is a key in problem.yaml.

@thorehusfeldt This is a new (and novel) idea. I'm not sure at all if I like it or not, but I think it should be a separate issue. Was this a real suggestion, or more of a random thought? If the former, we should create a new issue for it.

I will close this issue now though.

Originally posted by @niemela in #344

Continuing this line of thought.

Several mechanisms in the problem package want access to values in problem.yaml. Here are just three, different, examples:

  • input_validator/validate/ wants to know constants.max_n.value
  • the LaTeX problem statement to know title.en

We currently have different ways of facilitating this, such as LaTeX macros and template substitution. But we can’t do this:

from bapctoolslib import problem # imaginary module that just parses ../../problem.yaml and puts it into a useful namespace

max_n = problem.constants.max_n # OMG! No substitution! The linter is happy! I can run my code from CLI

Or, without a library,

from ruamel.yaml import YAML

yaml = YAML(typ="safe")  # safe loader -> plain Python types
with open("../problem.yaml", "r") as f:
    prroblem = yaml.load(f)

max_n = problem.constants.max_n

Whatever mechanism a language or framework uses to open a YAML file can be used. No substitution is performed. If BAPCtools wants to write neat libraries or .h header files that hide the YAML parsing, they can do that. Or not. A LaTeX class file would do the same. Or an upcoming typst library for making really sexy solution slides that read problem.source. (Alas, YAML can’t include YAML, otherwise that would be perfect.)

The only change to the specification is for sandboxing:

  • the problem.yaml must be is available to the code in the same relative position as in the problem package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions