Python ruamel.yaml.load() Examples
The following are 30
code examples of ruamel.yaml.load().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ruamel.yaml
, or try the search function
.
Example #1
Source File: utility.py From planet with Apache License 2.0 | 6 votes |
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
Example #2
Source File: utility.py From soccer-matlab with BSD 2-Clause "Simplified" License | 6 votes |
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_) message = 'Resume run and write summaries and checkpoints to {}.' tf.logging.info(message.format(config.logdir)) return config
Example #3
Source File: base.py From eNMS with GNU General Public License v3.0 | 6 votes |
def update_database_configurations_from_git(self): for dir in scandir(self.path / "network_data"): device = db.fetch("device", allow_none=True, name=dir.name) if not device: continue with open(Path(dir.path) / "data.yml") as data: parameters = yaml.load(data) device.update(**{"dont_update_pools": True, **parameters}) for data in self.configuration_properties: filepath = Path(dir.path) / data if not filepath.exists(): continue with open(filepath) as file: setattr(device, data, file.read()) db.session.commit() for pool in db.fetch_all("pool"): if any( getattr(pool, f"device_{property}") for property in self.configuration_properties ): pool.compute_pool()
Example #4
Source File: utility.py From soccer-matlab with BSD 2-Clause "Simplified" License | 6 votes |
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: message = ( 'Cannot resume an existing run since the logging directory does not ' 'contain a configuration file.') raise IOError(message) print("config_path=",config_path) stream = open(config_path, 'r') config = yaml.load(stream) message = 'Resume run and write summaries and checkpoints to {}.' print(message.format(logdir)) return config
Example #5
Source File: config.py From mackrl with Apache License 2.0 | 6 votes |
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
Example #6
Source File: __init__.py From aetros-cli with MIT License | 6 votes |
def read_config(path='aetros.yml', logger=None, return_default=True): path = os.path.normpath(os.path.abspath(os.path.expanduser(path))) config = {} if os.path.exists(path): f = open(path, 'r') config = yaml.load(f, Loader=yaml.RoundTripLoader) if config is None: config = {} if 'storage_dir' in config: del config['storage_dir'] if 'model' in config and config['model']: config['root'] = os.path.dirname(path) logger and logger.debug('Config loaded from ' + os.path.realpath(path)) if return_default: return apply_config_defaults(config) return config
Example #7
Source File: config.py From mackrl with Apache License 2.0 | 6 votes |
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
Example #8
Source File: migration.py From eNMS with GNU General Public License v3.0 | 6 votes |
def update_property(project, property, value=None, types=None): if not types: types = import_classes path = ( Path.cwd() / "Desktop" / "shared" / "project" / "eNMS" / "files" / "migrations" / project ) for instance_type in types: with open(path / f"{instance_type}.yaml", "r") as migration_file: objects = yaml.load(migration_file) for obj in objects: obj["devices"] = [] obj["pools"] = [] with open(path / f"{instance_type}.yaml", "w") as migration_file: yaml.dump(objects, migration_file)
Example #9
Source File: utility.py From soccer-matlab with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #10
Source File: utility.py From batch-ppo with Apache License 2.0 | 6 votes |
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
Example #11
Source File: config.py From mackrl with Apache License 2.0 | 6 votes |
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
Example #12
Source File: config.py From mackrl with Apache License 2.0 | 6 votes |
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
Example #13
Source File: inout.py From patch_linemod with BSD 2-Clause "Simplified" License | 6 votes |
def load_results_sixd17(path): """ Loads 6D object pose estimates from a file. :param path: Path to a file with poses. :return: List of the loaded poses. """ with open(path, 'r') as f: res = yaml.load(f, Loader=yaml.CLoader) if not res['ests'] or res['ests'] == [{}]: res['ests'] = [] else: for est in res['ests']: est['R'] = np.array(est['R']).reshape((3, 3)) est['t'] = np.array(est['t']).reshape((3, 1)) # change basestring to str for py3 if isinstance(est['score'], str): if 'nan' in est['score']: est['score'] = 0.0 else: raise ValueError('Bad type of score.') return res
Example #14
Source File: config.py From mackrl with Apache License 2.0 | 6 votes |
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
Example #15
Source File: test_reckoner.py From reckoner with Apache License 2.0 | 6 votes |
def test_passes_if_any_charts_exist(self, mock_helm, mock_yaml): course_yml = { 'namespace': 'fake', 'charts': { 'fake-chart': { 'chart': 'none', 'version': 'none', 'repository': 'none', } } } mock_yaml.load.side_effect = [course_yml] # this is not okay I assume, I just added args helm_args = ['provided args'] helm_instance = mock_helm(helm_args) helm_instance.client_version = '0.0.0' instance = reckoner.course.Course(None) self.assertTrue(instance.plot(['a-chart-that-is-not-defined', 'fake-chart']))
Example #16
Source File: test_reckoner.py From reckoner with Apache License 2.0 | 6 votes |
def test_raises_errors_when_missing_heading(self, mock_helm, mock_yaml): course_yml = { 'namespace': 'fake', 'charts': { 'fake-chart': { 'chart': 'none', 'version': 'none', 'repository': 'none', } } } mock_yaml.load.side_effect = [course_yml] helm_args = ['provided args'] helm_instance = mock_helm(helm_args) helm_instance.client_version = '0.0.0' instance = reckoner.course.Course(None) with self.assertRaises(exception.NoChartsToInstall): instance.plot(['a-chart-that-is-not-defined'])
Example #17
Source File: inout.py From sixd_toolkit with MIT License | 6 votes |
def load_results_sixd17(path): """ Loads 6D object pose estimates from a file. :param path: Path to a file with poses. :return: List of the loaded poses. """ with open(path, 'r') as f: res = yaml.load(f, Loader=yaml.CLoader) if not res['ests'] or res['ests'] == [{}]: res['ests'] = [] else: for est in res['ests']: est['R'] = np.array(est['R']).reshape((3, 3)) est['t'] = np.array(est['t']).reshape((3, 1)) if isinstance(est['score'], basestring): if 'nan' in est['score']: est['score'] = 0.0 else: raise ValueError('Bad type of score.') return res
Example #18
Source File: oc_obj.py From ansible-redhat_openshift_utils with Apache License 2.0 | 6 votes |
def __init__(self, filename=None, content=None, content_type='yaml', separator='.', backup_ext=None, backup=False): self.content = content self._separator = separator self.filename = filename self.__yaml_dict = content self.content_type = content_type self.backup = backup if backup_ext is None: self.backup_ext = ".{}".format(time.strftime("%Y%m%dT%H%M%S")) else: self.backup_ext = backup_ext self.load(content_type=self.content_type) if self.__yaml_dict is None: self.__yaml_dict = {}
Example #19
Source File: shyaml.py From smarthome with GNU General Public License v3.0 | 6 votes |
def __init__(self, filename, filename_write='', create_bak=False): """ initialize class for handling a yaml-file (read/write) | It initializes an empty data-structure, which can be filled by the load() method | This class is to be used for editing of yaml-files, not for loading SmartHomeNG structures :param filename: name of the yaml-file (without the .yaml extension!) :param filename_write: name of the file to write the resluts to (if different from filename) :param create_bak: True, if a backup-file of the original file shall be created :return: formatted string """ self.filename = filename if filename_write == '': self.filename_write = filename else: self.filename_write = filename_write self.filename_bak = self.filename_write + '.bak'+YAML_FILE self._create_bak = create_bak self.data = yaml.comments.CommentedMap([])
Example #20
Source File: oc_obj.py From ansible-redhat_openshift_utils with Apache License 2.0 | 6 votes |
def create(self, path, value): ''' create a yaml file ''' if not self.file_exists(): # deepcopy didn't work # Try to use ruamel.yaml and fallback to pyyaml try: tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False), yaml.RoundTripLoader) except AttributeError: tmp_copy = copy.deepcopy(self.yaml_dict) # set the format attributes if available try: tmp_copy.fa.set_block_style() except AttributeError: pass result = Yedit.add_entry(tmp_copy, path, value, self.separator) if result is not None: self.yaml_dict = tmp_copy return (True, self.yaml_dict) return (False, self.yaml_dict)
Example #21
Source File: shyaml.py From smarthome with GNU General Public License v3.0 | 6 votes |
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
Example #22
Source File: oc_obj.py From ansible-redhat_openshift_utils with Apache License 2.0 | 6 votes |
def __init__(self, filename=None, content=None, content_type='yaml', separator='.', backup_ext=None, backup=False): self.content = content self._separator = separator self.filename = filename self.__yaml_dict = content self.content_type = content_type self.backup = backup if backup_ext is None: self.backup_ext = ".{}".format(time.strftime("%Y%m%dT%H%M%S")) else: self.backup_ext = backup_ext self.load(content_type=self.content_type) if self.__yaml_dict is None: self.__yaml_dict = {}
Example #23
Source File: shyaml.py From smarthome with GNU General Public License v3.0 | 6 votes |
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)
Example #24
Source File: item_conversion.py From smarthome with GNU General Public License v3.0 | 6 votes |
def yaml_save(filename, data): """ ***Converter Special *** Save contents of an OrderedDict structure to a yaml file :param filename: name of the yaml file to save to :param data: OrderedDict to save """ sdata = convert_yaml(data) print(", saving to '{}'".format(os.path.basename(filename)+'.yaml')) if store_raw_output == True: with open(filename+'_raw.yaml', 'w') as outfile: outfile.write( sdata ) # Test if roundtrip gives the same result data = yaml.load(sdata, yaml.RoundTripLoader) _yaml_save_roundtrip(filename, data)
Example #25
Source File: oc_obj.py From ansible-redhat_openshift_utils with Apache License 2.0 | 6 votes |
def create(self, path, value): ''' create a yaml file ''' if not self.file_exists(): # deepcopy didn't work # Try to use ruamel.yaml and fallback to pyyaml try: tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False), yaml.RoundTripLoader) except AttributeError: tmp_copy = copy.deepcopy(self.yaml_dict) # set the format attributes if available try: tmp_copy.fa.set_block_style() except AttributeError: pass result = Yedit.add_entry(tmp_copy, path, value, self.separator) if result is not None: self.yaml_dict = tmp_copy return (True, self.yaml_dict) return (False, self.yaml_dict)
Example #26
Source File: test_box.py From Box with MIT License | 5 votes |
def test_to_yaml_basic(self): a = Box(test_dict) assert yaml.load(a.to_yaml(), Loader=yaml.SafeLoader) == test_dict
Example #27
Source File: test_box_list.py From Box with MIT License | 5 votes |
def test_box_list_to_yaml(self): bl = BoxList([{'item': 1, 'CamelBad': 2}]) assert yaml.load(bl.to_yaml(), Loader=yaml.SafeLoader)[0]['item'] == 1
Example #28
Source File: test_box.py From Box with MIT License | 5 votes |
def test_pickle(self): pic_file = os.path.join(tmp_dir, 'test.p') pic2_file = os.path.join(tmp_dir, 'test.p2') bb = Box(movie_data, conversion_box=False) pickle.dump(bb, open(pic_file, 'wb')) loaded = pickle.load(open(pic_file, 'rb')) assert bb == loaded assert loaded._box_config['conversion_box'] is False ll = [[Box({'a': 'b'})], [[{'c': 'g'}]]] bx = BoxList(ll) pickle.dump(bx, open(pic2_file, 'wb')) loaded2 = pickle.load(open(pic2_file, 'rb')) assert bx == loaded2 loaded2.box_options = bx.box_options
Example #29
Source File: package_utils.py From nni with MIT License | 5 votes |
def read_installed_package_meta(): config_file = get_package_config_path() if os.path.exists(config_file): with open(config_file, 'r') as f: config = yaml.load(f, Loader=yaml.Loader) else: config = defaultdict(list) for t in ALGO_TYPES: if t not in config: config[t] = [] return config
Example #30
Source File: test_converters.py From Box with MIT License | 5 votes |
def test_to_yaml(self): m_file = os.path.join(tmp_dir, "movie_data") movie_string = _to_yaml(movie_data) assert "Rick Moranis" in movie_string _to_yaml(movie_data, filename=m_file) assert "Rick Moranis" in open(m_file).read() assert yaml.load(open(m_file), Loader=yaml.SafeLoader) == yaml.load(movie_string, Loader=yaml.SafeLoader)