當前位置: 首頁>>代碼示例>>Python>>正文


Python yaml.Loader方法代碼示例

本文整理匯總了Python中ruamel.yaml.Loader方法的典型用法代碼示例。如果您正苦於以下問題:Python yaml.Loader方法的具體用法?Python yaml.Loader怎麽用?Python yaml.Loader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ruamel.yaml的用法示例。


在下文中一共展示了yaml.Loader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_config

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def load_config(logdir):
  """Load a configuration from the log directory.

  Args:
    logdir: The logging directory containing the configuration file.

  Raises:
    IOError: The logging directory does not contain a configuration file.

  Returns:
    Configuration object.
  """
  config_path = logdir and os.path.join(logdir, 'config.yaml')
  if not config_path or not tf.gfile.Exists(config_path):
    message = (
        'Cannot resume an existing run since the logging directory does not '
        'contain a configuration file.')
    raise IOError(message)
  with tf.gfile.FastGFile(config_path, 'r') as file_:
    config = yaml.load(file_, Loader=yaml.Loader)
  message = 'Resume run and write summaries and checkpoints to {}.'
  tf.logging.info(message.format(config.logdir))
  return config 
開發者ID:utra-robosoccer,項目名稱:soccer-matlab,代碼行數:25,代碼來源:utility.py

示例2: get_cfg

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def get_cfg(existing_cfg, _log):
    """
    generates
    """
    _sanity_check(existing_cfg, _log)
    import ntpath, os, ruamel.yaml as yaml
    with open(os.path.join(os.path.dirname(__file__), "{}.yml".format(ntpath.basename(__file__).split(".")[0])),
              'r') as stream:
        try:
            ret = yaml.load(stream, Loader=yaml.Loader)
        except yaml.YAMLError as exc:
            assert "Default config yaml for '{}' not found!".format(os.path.splitext(__file__)[0])

    #if ret["coma_critic_use_sampling"] and "coma_critic_sample_size" not in ret and hasattr(ret, "batch_size_run"):
    #    ret["coma_critic_sample_size"] = ret["batch_size_run"] * 50
    return ret 
開發者ID:schroederdewitt,項目名稱:mackrl,代碼行數:18,代碼來源:config.py

示例3: get_cfg

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def get_cfg(existing_cfg, _log):
    """
    generates
    """
    _sanity_check(existing_cfg, _log)
    import ntpath, os, ruamel.yaml as yaml
    with open(os.path.join(os.path.dirname(__file__), "{}.yml".format(ntpath.basename(__file__).split(".")[0])),
              'r') as stream:
        try:
            ret = yaml.load(stream, Loader=yaml.Loader)
        except yaml.YAMLError as exc:
            assert "Default config yaml for '{}' not found!".format(os.path.splitext(__file__)[0])

    if ret["coma_critic_use_sampling"] and "coma_critic_sample_size" not in ret and hasattr(ret, "batch_size_run"):
        ret["coma_critic_sample_size"] = ret["batch_size_run"] * 50
    return ret 
開發者ID:schroederdewitt,項目名稱:mackrl,代碼行數:18,代碼來源:config.py

示例4: get_cfg

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def get_cfg(existing_cfg, _log):
    """

    """
    _sanity_check(existing_cfg, _log)
    import ntpath, os, ruamel.yaml as yaml
    with open(os.path.join(os.path.dirname(__file__), "{}.yml".format(ntpath.basename(__file__).split(".")[0])), 'r') as stream:
        try:
            ret = yaml.load(stream, Loader=yaml.Loader)
        except yaml.YAMLError as exc:
            assert False, "Default config yaml for '{}' not found!".format(os.path.splitext(__file__)[0])

    if not "batch_size_run" in ret:
        ret["batch_size_run"] = ret["batch_size"]

    if not "runner_test_batch_size" in ret:
        ret["runner_test_batch_size"] = ret["batch_size_run"]

    if not "name" in ret:
        ret["name"] = ntpath.basename(__file__).split(".")[0]

    return ret 
開發者ID:schroederdewitt,項目名稱:mackrl,代碼行數:24,代碼來源:config.py

示例5: _ordered_load

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def _ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
    """
    Ordered yaml loader
    Use this instead ot yaml.loader/yaml.saveloader to get an Ordereddict

    :param stream: stream to read from
    :param Loader: yaml-loader to use
    :object_pairs_hook: ...

    :return: OrderedDict structure
    """

    # usage example: ordered_load(stream, yaml.SafeLoader)
    class OrderedLoader(Loader):
        pass
    def construct_mapping(loader, node):
        loader.flatten_mapping(node)
        return object_pairs_hook(loader.construct_pairs(node))
    OrderedLoader.add_constructor(
        yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
        construct_mapping)
    return yaml.load(stream, OrderedLoader) 
開發者ID:smarthomeNG,項目名稱:smarthome,代碼行數:24,代碼來源:shyaml.py

示例6: yaml_load_roundtrip

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def yaml_load_roundtrip(filename):
    """
    Load contents of a yaml file into an dict structure for editing (using Roundtrip Loader)

    :param filename: name of the yaml file to load
    :return: data structure loaded from file
    """

    if not EDITING_ENABLED:
        return None

    y = None
    if not filename.lower().endswith('.yaml'):
        filename += YAML_FILE
    try:
        with open(filename, 'r') as stream:
            sdata = stream.read()
        sdata = sdata.replace('\n', '\n\n')
        y = yaml.load(sdata, yaml.RoundTripLoader)
    except Exception as e:
        logger.error("yaml_load_roundtrip: YAML-file load error: '%s'" % (e))
        y = {}
    return y 
開發者ID:smarthomeNG,項目名稱:smarthome,代碼行數:25,代碼來源:shyaml.py

示例7: load_config

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def load_config(logdir):
  """Load a configuration from the log directory.

  Args:
    logdir: The logging directory containing the configuration file.

  Raises:
    IOError: The logging directory does not contain a configuration file.

  Returns:
    Configuration object.
  """
  config_path = logdir and os.path.join(logdir, 'config.yaml')
  if not config_path or not tf.gfile.Exists(config_path):
    message = (
        'Cannot resume an existing run since the logging directory does not '
        'contain a configuration file.')
    raise IOError(message)
  with tf.gfile.GFile(config_path, 'r') as file_:
    config = yaml.load(file_, yaml.Loader)
    message = 'Resume run and write summaries and checkpoints to {}.'
    tf.logging.info(message.format(config.logdir))
  return config 
開發者ID:google-research,項目名稱:planet,代碼行數:25,代碼來源:utility.py

示例8: load_config

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def load_config(logdir):
  # pylint: disable=missing-raises-doc
  """Load a configuration from the log directory.

  Args:
    logdir: The logging directory containing the configuration file.

  Raises:
    IOError: The logging directory does not contain a configuration file.

  Returns:
    Configuration object.
  """
  config_path = logdir and os.path.join(logdir, 'config.yaml')
  if not config_path or not tf.gfile.Exists(config_path):
    message = (
        'Cannot resume an existing run since the logging directory does not '
        'contain a configuration file.')
    raise IOError(message)
  with tf.gfile.FastGFile(config_path, 'r') as file_:
    config = yaml.load(file_, Loader=yaml.Loader)
  message = 'Resume run and write summaries and checkpoints to {}.'
  tf.logging.info(message.format(config.logdir))
  return config 
開發者ID:google-research,項目名稱:batch-ppo,代碼行數:26,代碼來源:utility.py

示例9: read_core_files

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def read_core_files():
    core_path = Path('../core')

    file_metas = []
    for item in core_path.glob('**/*'):
        if item.is_dir() or item.name.startswith('.'):
            continue

        category, file_name = item.parts[-2:]

        file = core_path / category / file_name
        with file.open() as file:
            data_info = yaml.load(file.read(), Loader=yaml.Loader)

        file_metas.append({
            'category': category,
            'file_name': file_name,
            'url': data_info['homepage'],
        })

    return file_metas 
開發者ID:awesomedata,項目名稱:apd-core,代碼行數:23,代碼來源:check_urls.py

示例10: test_config_unsafe_object_creation

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def test_config_unsafe_object_creation():
    from ruamel import yaml
    import calendar

    test_config_path = testing.relative_module_path(__file__, 'test_config_unsafe.yaml')

    # Unsafe default loader allows any python object initialization
    data = yaml.load(open(test_config_path), Loader=yaml.Loader)
    assert 'time' in data
    assert isinstance(data['time'], calendar.Calendar)

    # With use safe version only to allow construct previously registered objects
    with pytest.raises(config.ConfigLoadError, match='could not determine a constructor'):
        config.load_config(test_config_path) 
開發者ID:intel,項目名稱:workload-collocation-agent,代碼行數:16,代碼來源:test_config.py

示例11: sync

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def sync(ctx, in_place=False, check=True):

    with open('CITATION.cff', 'rb') as file:
        citation = load(file.read(), Loader=Loader)
        authors = [
            Contributor.from_citation_author(**author)
            for author in citation['authors']]

    with open('contributors.yaml', 'rb') as file:
        contributors = load(file.read(), Loader=Loader)['contributors']
        contributors = [Contributor.from_citation_author(
            **contributor) for contributor in contributors]

    with open('.zenodo.json', 'rb') as file:
        zenodo = json.loads(file.read())
        zenodo_updated = zenodo.copy()
        zenodo_updated['creators'] = [a.as_zenodo_creator() for a in authors]
        zenodo_updated['contributors'] = [c.as_zenodo_creator()
                                          for c in contributors if c not in authors]
        for key in ('version', 'keywords'):
            zenodo_updated[key] = citation[key]

    modified = json.dumps(zenodo, sort_keys=True) != json.dumps(zenodo_updated, sort_keys=True)
    if modified:
        if in_place:
            with open('.zenodo.json', 'wb') as file:
                file.write(json.dumps(zenodo_updated, indent=4, sort_keys=True).encode('utf-8'))
        else:
            click.echo(json.dumps(zenodo_updated, indent=4, sort_keys=True))
        if check:
            ctx.exit(1)
    else:
        click.echo("No changes.", err=True) 
開發者ID:glotzerlab,項目名稱:signac,代碼行數:35,代碼來源:.sync-zenodo-metadata.py

示例12: load

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def load(cls, filename):
    assert str(filename).endswith('.yaml')
    with open(filename, 'r') as f:
      return cls(yaml.load(f, Loader=yaml.Loader)) 
開發者ID:google-research,項目名稱:planet,代碼行數:6,代碼來源:attr_dict.py

示例13: execute

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def execute(self, gapic_code_dir, grpc_code_dir, proto_code_dir, gapic_yaml):
        with open(gapic_yaml) as f:
            gapic_config = yaml.load(f, Loader=yaml.Loader)
        package_name = gapic_config.get('language_settings').get('csharp').get('package_name')
        package_root = '{0}/{1}'.format(gapic_code_dir, package_name)
        prod_dir = '{0}/{1}'.format(package_root, package_name)
        # Copy proto/grpc .cs files into prod directory
        self.exec_command(['sh', '-c', 'cp {0}/*.cs {1}'.format(proto_code_dir, prod_dir)])
        self.exec_command(['sh', '-c', 'cp {0}/*.cs {1}'.format(grpc_code_dir, prod_dir)]) 
開發者ID:googleapis,項目名稱:artman,代碼行數:11,代碼來源:gapic_tasks.py

示例14: __ordered_load

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def __ordered_load(self, stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
        """Load an ordered dictionary from a yaml file.

        Note
        ----
        Borrowed from John Schulman.
        http://stackoverflow.com/questions/5121931/in-python-how-can-you-load-yaml-mappings-as-ordereddicts/21048064#21048064"
        """
        class OrderedLoader(Loader):
            pass
        OrderedLoader.add_constructor(
            yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
            lambda loader, node: object_pairs_hook(loader.construct_pairs(node)))
        return yaml.load(stream, OrderedLoader) 
開發者ID:BerkeleyAutomation,項目名稱:autolab_core,代碼行數:16,代碼來源:yaml_config.py

示例15: load_config

# 需要導入模塊: from ruamel import yaml [as 別名]
# 或者: from ruamel.yaml import Loader [as 別名]
def load_config(config_path, loader=yaml.Loader, verify_version=True):
    if not os.path.exists(config_path):
        system_log.error(_("config.yml not found in {config_path}").format(config_path))
        return False
    with codecs.open(config_path, encoding="utf-8") as stream:
        config = yaml.load(stream, loader)
    if verify_version:
        config = config_version_verify(config, config_path)
    return config 
開發者ID:zhengwsh,項目名稱:InplusTrader_Linux,代碼行數:11,代碼來源:config.py


注:本文中的ruamel.yaml.Loader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。