-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Headers Override for Name and CrowdAnkiUUID #47
Conversation
6267d14
to
da3089a
Compare
Thanks so much for the fast implementation! It works! :) Isn't a (slight) design issue that this prevents BrainBrew from being able to (even in principle) import changes to the deck name (and the (BrainBrew currently doesn't allow writing to the YAML headers file, but in principle it's possible, while if the name and crowdanki_uuid are hard-coded in the recipes then it becomes impossible even in principle.) (I'm probably heavily overthinking this, though — Edit: One tiny thing I noticed is that in the built JSONs, the |
deck_description_html_file: Optional[str] | ||
crowdanki_uuid: Optional[str] | ||
name: Optional[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we need default values (None
) here, if we want to allow overriding only some of deck_description
, crowdanki_uuid
and name
at the same time.
deck_description_html_file: Optional[str] | |
crowdanki_uuid: Optional[str] | |
name: Optional[str] | |
deck_description_html_file: Optional[str] = None | |
crowdanki_uuid: Optional[str] = None | |
name: Optional[str] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe so, since the actual overriding function individually check if each value is truthy. Have you experienced that populating one in the recipe, and not others, will null out the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overriding one in the recipe, but not the others, causes BrainBrew to crash:
TypeError: __init__() missing 2 required positional arguments: 'crowdanki_uuid' and 'name'
Full backtrace
INFO:root:Builder file recipes/source_to_anki.yaml is ✔ good
INFO:root:Attempting to generate Guids
INFO:root:Generate guids complete
Traceback (most recent call last):
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/bin/brain_brew", line 33, in <module>
sys.exit(load_entry_point('Brain-Brew', 'console_scripts', 'brain_brew')())
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/main.py", line 19, in main
command.execute()
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/run_recipe.py", line 15, in execute
recipe = TopLevelBuilder.parse_and_read(self.recipe_file_name, self.verify_only)
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/top_level_builder.py", line 60, in parse_and_read
return cls.from_list(recipe_data)
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/recipe_builder.py", line 20, in from_list
tasks = cls.read_tasks(data)
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/recipe_builder.py", line 68, in read_tasks
task_or_tasks = [matching_task.from_repr(task_arguments)]
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/parts_builder.py", line 40, in from_repr
return cls.from_list(data)
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/recipe_builder.py", line 20, in from_list
tasks = cls.read_tasks(data)
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/recipe_builder.py", line 66, in read_tasks
task_or_tasks = [matching_task.from_repr(t_arg) for t_arg in task_arguments]
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/commands/run_recipe/recipe_builder.py", line 66, in <listcomp>
task_or_tasks = [matching_task.from_repr(t_arg) for t_arg in task_arguments]
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/build_tasks/deck_parts/headers_from_yaml_part.py", line 58, in from_repr
override=HeadersOverride.from_repr(rep.override) if rep.override else None
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/build_tasks/overrides/headers_override.py", line 32, in from_repr
rep: cls.Representation = data if isinstance(data, cls.Representation) else cls.Representation.from_dict(data)
File "/home/adam/.local/share/virtualenvs/git-1CgJDxfG/src/brain-brew/brain_brew/configuration/representation_base.py", line 18, in from_dict
return cls(**expected_values)
TypeError: __init__() missing 2 required positional arguments: 'crowdanki_uuid' and 'name'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I guess you're right. I never made that default value in the original since it was the only member of the Override class. Pushed a change that should fix it 👍
No worries, any time 😁
Not sure I understand what you are saying. That there should be a way to programmatically write to a Header?
Doesn't |
I think that I'm overthinking this (firstly, changing headers is a very rare use-case to begin with, and secondly changing the name and UUID makes little sense and/or will break other things) so please feel free to ignore the below! (I'm not quite sure why I decided to type all of this up, given that I realised half-way through that it makes no sense...) Monstrously overlong argument
I meant that currently (at least in AUG's Now actually looking at
I meant that now that
|
On a more constructive note, the partial overrides issue is now fixed (there's no crash when only some fields are overridden)! (The sorting is still as it was: first all the non-overridden fields, then |
🎉
Aaaahhhhhh you meant the order in the resulting CrowdAnki file, yes I see. That should be fixable 😄 |
AFAICT this works perfectly (as we'd require for #566) with all even minor issues (key sorting) dealt with! |
It seems we need completely separate header files because the crowdanki_uuid (deck UUID) and name can't currently be overridden. See ohare93/brain-brew#47 The description can be overridden and Ultimate Geography does it (https://github.com/anki-geo/ultimate-geography/blob/f71dd70aa2d8207739ac6e68f5e91af610fe827d/recipes/source_to_anki.yaml#L30), but that is not enough for us.
@ohare93 could you please merge this? (Not urgently!) (I haven't tested it any more, but from what I remember from anki-geo/ultimate-geography#566 it worked exactly as needed.) |
Huh I never merged this? Whoops! Done 😁 I'll release a new version shortly 👍 |
@omarkohl I see you referenced this PR. It is released now, apologies for the delay! 😅 |
Thanks! |
Added the ability to override name and crowdanki_uuid for a Deck Header.
For anki-geo/ultimate-geography#566