Open philipsd6 opened 3 years ago
Hello,
Thanks for the issue. You're absolutely right there is no way to implement a dict style in the current state. I'll open a PR concerning this issue soon unless you want to submit some code.
I started to work on a PR, but after looking through the code more, I decided this project is not for me. All I needed was to parse a BSMX recipe/equipment file to convert it to readable YAML. For that I was happy to use Box. (Still struggling to determine all of the various enumerations used in BSMX, but nothing helps that when it's not documented anywhere.)
I would love to see this become more of a full-featured schema, and then this code could just define a schema with Cerebus/jsonschema/schema and then load yaml and validate it.
That spec is the difficult part, but once done it could be implemented in XML/YAML whatever. A custom library like this could also implement user-friendly YAML tag features like accepting unit input that gets converted into a unit structure for interchange. Off the top of my head... thinking of something like this:
fermentables:
- name: Pale 2-row Malt:
type: Grain
amount: !Pounds 5.0
yield: !Percent 73.4
color: !EBC 3.0
This would parsed to:
fermentables:
- name: Pale 2-row Malt:
type: Grain
amount: {value: 5.0, unit: pounds}
yield: {value: 73.4, unit: percentage}
color: {value: 3.0, unit: ebc}
Hello,
The main purpose of this code was to simply write and read beer recipes for humans using a less verbose language than beerxml but remaining compatible with it.
It was never an intent to make a full-featured schema with validation nor replace beerxml which is widely used. However since all units are fixed in beerxml, your idea of converting the units using the library is very interesting. I should create a ticket about it.
Thanks for the issue, I will merge a fix soon.
I trying to understand how to pass in a dict for the style, instead of just the name, but I can't figure it out. If I pass in
style={"name": "American Wheat or Rye Beer", "category": "Light Hybrid Beer", ...etc...}
I get:KeyError: 'style'
from this line:https://github.com/j0ack/pybeeryaml/blob/277f42784db57da3af6e9b006599e96232068ae5/pybeeryaml/recipe.py#L61
As far as I can tell, these two lines make it impossible to pass in a complex style, because if style is a dict, then it tries to load in style from
**data["style"]
(Pythonic style, that should probably be**kwargs
!) parameters, but it won't be there because it was passed in as a named parameter.Instead I believe it should be this: