schrodinger.application.matsci.yamlutils module

Utilities for working with yaml

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.application.matsci.yamlutils.yaml_tuple_constructor(obj, node)

Add the ability to parse tuples to a YAML Constructor object

Note - this function is for ruamel yaml with Python 3.11 and beyond

Parameters
  • obj (yaml.SafeConstructor) – The constructor object

  • node (yaml.nodes.SequenceNode) – The tuple node

Return type

tuple

Returns

The tuple derived from node

schrodinger.application.matsci.yamlutils.yaml_tuple_representer(obj, data)

Add the ability to write tuples to a YAML Representer object

Note - this function is for ruamel yaml with Python 3.11 and beyond

Parameters
  • obj (yaml.Representer) – The constructor object

  • data – The tuple to represent

Return type

str

Returns

A YAML representation of a tuple

schrodinger.application.matsci.yamlutils.get_safe_yaml_with_tuples()

Get a safe YAML loader that can handle tuples

Return type

yaml.YAML

Returns

A safe yaml loader that can handle tuples

class schrodinger.application.matsci.yamlutils.TupleSafeLoader(*args, **kwargs)

Bases: ruamel.yaml.loader.SafeLoader

Yaml Loader that recognizes tuple tags.

Note - this class is for ruamel yaml with Python < 3.11

__init__(*args, **kwargs)

Initialize the scanner.

schrodinger.application.matsci.yamlutils.read_safe_yaml_file(path)

Read a yaml file safely and properly interpret tuples

Parameters

path (str) – The path to the yaml file

Returns

The data from the yaml file

schrodinger.application.matsci.yamlutils.dump_yaml_file(path, data)

Write a yaml file safely and properly interpret tuples

Parameters
  • path (str) – The path to the yaml file

  • data – The data to write out

Returns

The data from the yaml file