Discovers the YAML format and registers it if available.

        Install YAML support via PIP::

            pip install PyYAML
977021
def discover_yaml(self):
        
        try:
            import yaml
            self.register('yaml', yaml.load, yaml.dump)
        except ImportError:
            pass
1023832
def edit_yaml(yaml_location, &block)
      d = YAML.load_file(yaml_location)
      block.call(d)
      File.open(yaml_location, 'w') {|f| f.write d.to_yaml }
    end
70423
def install_python_module(name):
    

    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=False, capture=True):
        run('pip --quiet install %s' % name)
808793
def parse_yaml(self, y):
        ''''''
        self.x = int(y['x'])
        self.y = int(y['y'])
        self.height = int(y['height'])
        self.width = int(y['width'])
        self.direction = dir.from_string(y['direction'])
        return self
314686
def yaml_block(self):
        
        if LOAD_YAML and self._yaml_block is not None:
            try:
                yaml_dict = yaml.load(self._yaml_block)
                return yaml_dict
            except yaml.error.YAMLError:
                print("Error parsing yaml block. Check formatting.")
        return None
1322596
def to_nice_yaml(yaml_input, indentation=2):
    
    return yaml.safe_dump(yaml_input, indent=indentation,
                          allow_unicode=True, default_flow_style=False)
1331625
def parse_yaml(self, y):
        ''''''
        self.name = y['name']
        if RTS_EXT_NS_YAML + 'comment' in y:
            self.comment = y[RTS_EXT_NS_YAML + 'comment']
        if RTS_EXT_NS_YAML + 'visible' in y:
            visible = y.get(RTS_EXT_NS_YAML + 'visible')
            if visible == True or visible == 'true' or visible == 'True':
                self.visible = True
            else:
                self.visible = False
        if RTS_EXT_NS_YAML + 'properties' in y:
            for p in y.get(RTS_EXT_NS_YAML + 'properties'):
                if 'value' in p:
                    value = p['value']
                else:
                    value = None
                self._properties[p['name']] = value
        return self
768541
def dump(self):
        """"""
        try:
            import yaml
            cfg_file = self._cfg_file()
            cfg_dir, __ = os.path.split(cfg_file)
            os.makedirs(cfg_dir, exist_ok=True)
            with open(cfg_file, 'w') as f:
                yaml.dump(self, f)
        except ImportError as err:
            raise RuntimeError(
                'Cannot dump the configuration settings to file. You need to '
                'install the necessary dependencies (pyyaml, appdirs).'
            ) from err
177005
def yaml_load(stream):
    """"""
    # Surprisingly, the CSafeLoader does not seem to be used by default.
    # Check whether the CSafeLoader is available and provide a log message
    # if it is not available.
    global _HAS_YAML_LIBRARY

    if _HAS_YAML_LIBRARY is None:
        _HAS_YAML_LIBRARY = hasattr(yaml, 'CSafeLoader')
        if not _HAS_YAML_LIBRARY:
            logger.warning('libyaml was not found! Please install libyaml to'
                           ' speed up loading the model files.')

    if _HAS_YAML_LIBRARY:
        loader = yaml.CSafeLoader(stream)
    else:
        loader = yaml.SafeLoader(stream)
    loader.add_constructor('tag:yaml.org,2002:float', float_constructor)
    return loader.get_data()
1046579
def setup_from_yamlfile(self, yamlfile, output_shell=False):
        
        self.logger.debug('Loading config from ' + yamlfile)
        with open(yamlfile, 'r') as yamlfd:
            yamlconfig = yaml.load(yamlfd)
            for instance in yamlconfig['Instances']:
                self.add_instance(instance['role'].upper(),
                                  instance,
                                  output_shell=output_shell)
            if 'Config' in yamlconfig.keys():
                self.logger.debug('Config found: ' + str(yamlconfig['Config']))
                self.config = yamlconfig['Config'].copy()
286825
def register_module_classes(yaml: ruamel.yaml.YAML, modules: Optional[Iterable[Any]] = None) -> ruamel.yaml.YAML:
    
    # Validation
    if modules is None:
        modules = []

    # Extract the classes from the modules
    classes_to_register = set()
    for module in modules:
        module_classes = [member[1] for member in inspect.getmembers(module, inspect.isclass)]
        classes_to_register.update(module_classes)

    # Register the extracted classes
    return register_classes(yaml = yaml, classes = classes_to_register)
101078
def dump_yaml(testcase, yaml_file):
    
    logging.info("dump testcase to YAML format.")

    with io.open(yaml_file, 'w', encoding="utf-8") as outfile:
        yaml.dump(testcase, outfile, allow_unicode=True, default_flow_style=False, indent=4)

    logging.info("Generate YAML testcase successfully: {}".format(yaml_file))
712810
def install(self):
        
        other_args = list(requirement_args(self._argv, want_other=True))
        archive_path = join(self._temp_path, self._downloaded_filename())
        # -U so it installs whether pip deems the requirement "satisfied" or
        # not. This is necessary for GitHub-sourced zips, which change without
        # their version numbers changing.
        run_pip(['install'] + other_args + ['--no-deps', '-U', archive_path])
45845
def from_yaml():
    
    default_yaml_str = snippets.get_snippet_content('hatchery.yml')
    ret = yaml.load(default_yaml_str, Loader=yaml.RoundTripLoader)
    for config_path in CONFIG_LOCATIONS:
        config_path = os.path.expanduser(config_path)
        if os.path.isfile(config_path):
            with open(config_path) as config_file:
                config_dict = yaml.load(config_file, Loader=yaml.RoundTripLoader)
                if config_dict is None:
                    continue
                for k, v in config_dict.items():
                    if k not in ret.keys():
                        raise ConfigError(
                            'found garbage key "{}" in {}'.format(k, config_path)
                        )
                    ret[k] = v
    return ret
124687
def yaml(self):
        
        return ordered_dump(OrderedDict(self),
                            Dumper=yaml.SafeDumper,
                            default_flow_style=False)
930636
def resolve_format(format, path):
    
    if format is None:
        if (re.match(r'.+\.(yml|yaml)$', path)):
            return 'yaml'
        elif (re.match(r'.+\.tsv$', path)):
            return 'tsv'
    else:
        return format.lower()
386329
def load(filename):
    
    yaml_filename = os.path.join(os.path.dirname(filename), 'step.yaml')
    with open(yaml_filename) as f:
        return yaml.load(f)