PEP 8 imports tidyup.

Also remove some redundant whitespace.
Extract the yaml loading to a helper.

This avoids the repeat yaml try..catch imports and provides a simpler
target for mocking in tests.