Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass complete style into __init__ constructor? #4

Open
philipsd6 opened this issue Jan 3, 2021 · 3 comments
Open

How to pass complete style into __init__ constructor? #4

philipsd6 opened this issue Jan 3, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@philipsd6
Copy link

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:

self.style = Style(**data["style"])

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:

if isinstance(self.style, dict):
    self.style = Style(**style)
@j0ack j0ack added the bug Something isn't working label Jan 4, 2021
@j0ack
Copy link
Owner

j0ack commented Jan 4, 2021

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.

@philipsd6
Copy link
Author

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}

@j0ack
Copy link
Owner

j0ack commented Jan 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants