Skip to content

Commit

Permalink
Merge pull request #147 from GEOS-ESM/develop
Browse files Browse the repository at this point in the history
Merge Develop into Main for release
  • Loading branch information
tclune authored Mar 19, 2021
2 parents 5fa4144 + 0373496 commit a393404
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; Global Editor Config for mepo
;
; This is an ini style configuration. See http://editorconfig.org/ for more information on this file.
;
; Top level editor config.
root = true
; Always use Unix style new lines with new line ending on every file and trim whitespace
[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
; Python: PEP8 defines 4 spaces for indentation
[*.py]
indent_style = space
indent_size = 4
; Salt state files, YAML format, 2 spaces
[*.sls, *.yaml, *.yml]
indent_style = space
indent_size = 2

15 changes: 13 additions & 2 deletions mepo.d/config/config_file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import pathlib
import yaml

from state.exceptions import SuffixNotRecognizedError

# From https://github.com/yaml/pyyaml/issues/127#issuecomment-525800484
class AddBlankLinesDumper(yaml.SafeDumper):
# HACK: insert blank lines between top-level objects
# inspired by https://stackoverflow.com/a/44284819/3786245
def write_line_break(self, data=None):
super().write_line_break(data)

if len(self.indents) == 1:
super().write_line_break()

class ConfigFile(object):

__slots__ = ['__filename', '__filetype']

def __init__(self, filename):
self.__filename = filename
SUFFIX_LIST = ['.yaml', '.json', '.cfg']
Expand Down Expand Up @@ -41,4 +52,4 @@ def write_yaml(self, d):
'''Dump dict d into a yaml file'''
import yaml
with open(self.__filename, 'w') as fout:
yaml.dump(d, fout, sort_keys = False)
yaml.dump(d, fout, sort_keys = False, Dumper=AddBlankLinesDumper)

0 comments on commit a393404

Please sign in to comment.