Giter Site home page Giter Site logo

Comments (6)

edmundmok avatar edmundmok commented on June 1, 2024

Oh yes, I didn't encounter this because my personal config was always a copy of the template, thanks for noticing this! strictyaml seems to have optional keys with defaults, which we can use to replace the template file if we want to go that route. That might require a more helpful README file so that users don't have to dig into the code to understand what config options exist.

from mealpy.

ipwnponies avatar ipwnponies commented on June 1, 2024

We would need a second schema, with all optional keys. Being able to have a strict schema, with sane defaults, means the code can assume values exist. Otherwise we'll end up with a mess of .get('DEFAULT') in the code, and it'll be difficult to document default values for the user.

I'm not sure how I feel about using optional keys feature of strictyaml and schema validation features in general. it feels clunky to try to read the yaml schema via python code. Having a complete config template is a great way to self-document. The instructions could be yaml comments right in the config itself.

from mealpy.

edmundmok avatar edmundmok commented on June 1, 2024

We can specify the defaults within the schema for optional keys, so there won't be any issue about .get and having to specify and defaults. As for readability, I think it would be possible to create our own "dictionary" containing values as tuple of (type, default) instead of using the strictyaml.Map directly, and just pass our custom dictionary into a helper function to generate the less readable schema.
Documentation is a good point though, but it's possible that users will go to the README anyway to learn how to use the tool, so it might also be a good idea to centralize all documentation in the README.

from mealpy.

ipwnponies avatar ipwnponies commented on June 1, 2024

I feel using optionals is a flawed approach. It complicates the schema, as a workaround. The schema should remain unchanged, as it's technically correct. Optionals makes it unclear to any developer wihtout tribal knowledge. We also don't want to maintain multiple schemas: one for the canonical schema; and the other for the "all-optionals".

I think we want to use revalidate, haven't looked at it closely though. What I'm envisioning is:

  1. validate the template, which should always be valid
  2. override/merge values from user config
  3. revalidate the final config, ensuring it's still valid.

That way, there should be less custom/duplicate code. It's just plain python assignments, and then reusing the same strictyaml validation + schema setup.

from mealpy.

edmundmok avatar edmundmok commented on June 1, 2024

There will still only be one schema in my suggestion, except they are all optionals, which come with default values, which mirrors the idea of our "template config".

I think using revalidate will instead use a separate schema since strictyaml needs to know how to read from the custom config.

from mealpy.

ipwnponies avatar ipwnponies commented on June 1, 2024

The schema with default values would work but the downside (imo quite significant) is that users cannot easily read the default values. Instead of reading a "config.template.yaml", they would need to read a strictyaml schema.

strictyaml can read a yaml file without schema.

from mealpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.