X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fdata.py;h=d9eb8ebcf0af12ccfb47268da521a2b666e9f2f2;hp=99e6d21b8fe3c014b37934216192a3191244daa5;hb=94de2d767ffb9c4bc13470b4bbc7219e96119565;hpb=ccabf1c36488ef0f0a3107f99e9bd43c3b307216 diff --git a/mudpy/data.py b/mudpy/data.py index 99e6d21..d9eb8eb 100644 --- a/mudpy/data.py +++ b/mudpy/data.py @@ -12,6 +12,26 @@ import mudpy import yaml +class _IBSEmitter(yaml.emitter.Emitter): + + """Override the default YAML Emitter to indent block sequences.""" + + def expect_block_sequence(self): + """Match the expectations of the ``yamllint`` style checker.""" + + # TODO(fungi) Get an option for this implemented upstream in + # the pyyaml library + self.increase_indent(flow=False, indentless=False) + self.state = self.expect_first_block_sequence_item + + +class _IBSDumper(yaml.SafeDumper, _IBSEmitter): + + """Use our _IBSEmitter instead of the default implementation.""" + + pass + + class Data: """A file containing universe elements and their facets.""" @@ -61,19 +81,18 @@ class Data: if included not in includes: includes.append(included) continue + if node.startswith("_"): + continue facet_pos = node.rfind(".") + 1 - if not facet_pos: - mudpy.misc.Element(node, self.universe, self, old_style=True) - else: - prefix = node[:facet_pos].strip(".") - try: - element = self.universe.contents[prefix] - except KeyError: - element = mudpy.misc.Element(prefix, self.universe, self) - element.set(node[facet_pos:], self.data[node]) - if prefix.startswith("mudpy.movement."): - self.universe.directions.add( - prefix[prefix.rfind(".") + 1:]) + prefix = node[:facet_pos].strip(".") + try: + element = self.universe.contents[prefix] + except KeyError: + element = mudpy.misc.Element(prefix, self.universe, self) + element.set(node[facet_pos:], self.data[node]) + if prefix.startswith("mudpy.movement."): + self.universe.directions.add( + prefix[prefix.rfind(".") + 1:]) for include_file in includes: if not os.path.isabs(include_file): include_file = find_file( @@ -145,8 +164,9 @@ class Data: os.umask(old_umask) # write and close the file - yaml.safe_dump(self.data, allow_unicode=True, - default_flow_style=False, stream=file_descriptor) + yaml.dump(self.data, Dumper=_IBSDumper, allow_unicode=True, + default_flow_style=False, explicit_start=True, indent=4, + stream=file_descriptor) file_descriptor.close() # unset the modified flag @@ -162,7 +182,7 @@ class Data: def find_file( file_name=None, - category=None, + group=None, prefix=None, relative=None, search=None, @@ -273,6 +293,4 @@ def find_file( # and normalize it last thing before returning file_name = os.path.realpath(file_name) - - # normalize the resulting file path and hand it back return file_name