-
Notifications
You must be signed in to change notification settings - Fork 64
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
Use ruamel.yaml for YAMLEditable #302
Conversation
replace the YAMLEditable.to_yaml() method with ruamel serialization. migrate some yaml formatting to the helpers module.
This PR references (#276) What I have not done (yet):
|
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 did a quick review of the helper code, just to give you an idea. I will of course do another one at least when you remove the draft state.
I think you need not bother with #146 because that issue is still in the discussion and planing phase. You can also leave the pretty printing alone as we just reuse the yaml conversion functions. We do not officially claim that the output of the pretty printer is valid yaml. We can thing about changing the pretty printer in another PR. Please try to run the tests and mypy (and maybe even pylint) locally because currently travis integration is broken. (I need help from @scheibler to fix this.) If you could also write a test for #276 (the string with an @) that would be great! |
I have a little difficulty running the tests. When I run
I have to interrupt the testing via Edit:
|
Hi @lucc , So apparently my changes did not break the tests.
Is there anything more I need to do before this PR can be merged? |
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.
You can skip the broken test like this:
diff --git a/test/test_command_line_interface.py b/test/test_command_line_interface.py
index cac683c..97b5ecf 100644
--- a/test/test_command_line_interface.py
+++ b/test/test_command_line_interface.py
@@ -480,6 +480,7 @@ class Merge(unittest.TestCase):
self.assertEqual('contact2.vcf', second)
+@unittest.skip("reason for skipping")
class AddEmail(unittest.TestCase):
@TmpConfig(["contact1.vcf", "contact2.vcf"])
If I do that (temporarily!) the other tests all run fine.
I noticed that the birthday field and phone numbers as well as ZIP codes are now wrapped in quotes. Do you know if there is a way to only quote strings that are problematic (like the @ at the beginning)?
khard/helpers/__init__.py
Outdated
@@ -61,6 +62,121 @@ def get_random_uid() -> str: | |||
return ''.join([random.choice(string.ascii_lowercase + string.digits) | |||
for _ in range(36)]) | |||
|
|||
def yaml_clean(value: Optional[Union[str, List, Dict[str, Any], Sequence]] | |||
) -> Optional[Union[Sequence, List, str, Dict[str, Any], |
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.
Why did you add Sequence
to the type signature? And if it is really needed you can leave out List
I think.
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 got a mypy error without the Sequence, meaning one of the properties of YAMLEditable
that are used in to_yaml
is of a Sequence type. I removed List though, thank you.
khard/helpers/__init__.py
Outdated
|
||
def yaml_dicts( | ||
data: Optional[Dict[str, Any]], | ||
defaults: Optional[Union[Dict[str, Any], List[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.
For Optional[Union[...]]
it is nicer to write Union[..., None]
.
khard/carddav_object.py
Outdated
} | ||
template = helpers.get_new_contact_template() | ||
yaml = YAML() | ||
yaml.top_level_colon_align = True |
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 do not like the way this alignment looks so I would leave it out.
"Note", self.notes, 0, 5, True) | ||
elif line.lower().startswith("webpage"): | ||
strings += helpers.convert_to_yaml( | ||
"Webpage", self.webpages, 0, 8, True) |
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 like this code reduction :)
@lucc I implemented the changes you requested. So, if that is a big problem we could ofc ask Anthon van der Neut from ruamel if he knows if it is possible not to quote this. |
replace the YAMLEditable.to_yaml() method with ruamel serialization.
migrate some yaml formatting to the helpers module.