本文整理汇总了Python中ruamel.yaml.comments.CommentedMap方法的典型用法代码示例。如果您正苦于以下问题:Python comments.CommentedMap方法的具体用法?Python comments.CommentedMap怎么用?Python comments.CommentedMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ruamel.yaml.comments
的用法示例。
在下文中一共展示了comments.CommentedMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def __init__(self, steps_dir=None, working_dir=None):
self.working_dir = working_dir
if self.working_dir:
self.working_dir = os.path.abspath(self.working_dir)
if not os.path.exists(self.working_dir):
os.makedirs(self.working_dir)
self.wf_steps = CommentedMap()
self.wf_inputs = CommentedMap()
self.wf_outputs = CommentedMap()
self.step_output_types = {}
self.steps_library = StepsLibrary(working_dir=working_dir)
self.has_workflow_step = False
self.has_scatter_requirement = False
self.has_multiple_inputs = False
self._wf_closed = False
self.load(steps_dir)
示例2: test_anchor_assigned
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def test_anchor_assigned(self):
from ruamel.yaml.comments import CommentedMap
data = load("""
a: &id002
b: 1
c: 2
d: *id002
e: &etemplate
b: 1
c: 2
f: *etemplate
""")
d = data['d']
assert isinstance(d, CommentedMap)
assert d.yaml_anchor() is None # got dropped as it matches pattern
e = data['e']
assert isinstance(e, CommentedMap)
assert e.yaml_anchor().value == 'etemplate'
assert e.yaml_anchor().always_dump is False
示例3: fork
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def fork(self, strictindex, new_value):
"""
Return a chunk referring to the same location in a duplicated document.
Used when modifying a YAML chunk so that the modification can be validated
before changing it.
"""
forked_chunk = YAMLChunk(
deepcopy(self._ruamelparsed),
pointer=self.pointer,
label=self.label,
key_association=copy(self._key_association),
)
if self.is_scalar():
# Necessary for e.g. EmptyDict, which reports as a scalar.
forked_chunk.pointer.set(forked_chunk, '_ruamelparsed',
CommentedMap())
forked_chunk.pointer.set(forked_chunk, '_strictparsed',
CommentedMap(), strictdoc=True)
forked_chunk.contents[self.ruamelindex(strictindex)] = new_value.as_marked_up()
forked_chunk.strictparsed()[strictindex] = deepcopy(new_value.as_marked_up())
return forked_chunk
示例4: reorder
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def reorder(data, strict=True):
if type(data) is CommentedMap:
order = ComposeFormat.order_map(list(data.keys()))
keys = list(data.keys())
while ComposeFormat.sorted_by_order(keys, order, strict) != keys:
for a, b in zip(ComposeFormat.sorted_by_order(keys, order, strict), keys):
if a == b:
continue
data.move_to_end(b)
break
keys = list(data.keys())
for key, item in data.items():
if key in ComposeFormat.NON_SORTABLE_ARRAYS:
continue
ComposeFormat.reorder(item, strict)
return data
if type(data) is CommentedSeq:
for i, value in enumerate(data):
if type(value) is not CommentedMap:
data[i] = ComposeFormat.fix_sexadecimal_numbers(value)
data.sort()
return data
return data
示例5: test_step_cant_get_run_step_dynamically_round_trip
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def test_step_cant_get_run_step_dynamically_round_trip(mocked_moduleloader):
"""Step can't get run_step method on the dynamically imported module
with round trip yaml loaded context.
"""
stepcache.step_cache.clear()
with pytest.raises(AttributeError) as err_info:
with patch_logger('pypyr.dsl', logging.ERROR) as mock_logger_error:
with patch_logger('pypyr.cache.stepcache',
logging.ERROR) as mock_cache_logger_error:
commented_context = CommentedMap({'name': 'mocked.step'})
commented_context._yaml_set_line_col(1, 2)
Step(commented_context, None)
mocked_moduleloader.assert_called_once_with('mocked.step')
mock_logger_error.assert_called_once_with(
"Error at pipeline step mocked.step yaml line: 1, col: 2")
mock_cache_logger_error.assert_called_once_with(
"The step mocked.step in module 3 doesn't have a "
"run_step(context) function.")
assert str(err_info.value) == "'int' object has no attribute 'run_step'"
示例6: load
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def load() -> CommentedMap:
return config["plugin_config"]
示例7: load_base
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def load_base() -> RecursiveDict[CommentedMap]:
return RecursiveDict(config.load_base()["plugin_config"], CommentedMap)
示例8: save
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def save(data: RecursiveDict[CommentedMap]) -> None:
config["plugin_config"] = data
config.save()
示例9: load_config
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def load_config(self) -> CommentedMap:
return yaml.load(self.db_instance.config)
示例10: save_config
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def save_config(self, data: RecursiveDict[CommentedMap]) -> None:
buf = io.StringIO()
yaml.dump(data, buf)
self.db_instance.config = buf.getvalue()
示例11: is_dict
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def is_dict(obj):
"""
Check if object is a dict or the ruamel.yaml equivalent of a dict
"""
return isinstance(obj, (dict, CommentedMap))
示例12: as_yaml_object
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def as_yaml_object(self):
"""
Convert pullspec to a {"name": <name>, "image": <image>} object
:return: dict-like object compatible with ruamel.yaml
"""
return CommentedMap([("name", self.name), ("image", self.image)])
示例13: set_related_images
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def set_related_images(self):
"""
Find pullspecs in predefined locations and put all of them in the
.spec.relatedImages section (if it already exists, clear it first)
"""
named_pullspecs = self._named_pullspecs()
by_name = OrderedDict()
conflicts = []
for new in named_pullspecs:
# Keep track only of the first instance with a given name.
# Ideally, existing relatedImages should come first in the list,
# otherwise error messages could be confusing.
old = by_name.setdefault(new.name, new)
# Check for potential conflict (same name, different image)
if new.image != old.image:
msg = ("{old.description}: {old.image} X {new.description}: {new.image}"
.format(old=old, new=new))
conflicts.append(msg)
if conflicts:
raise RuntimeError("{} - Found conflicts when setting relatedImages:\n{}"
.format(self.path, "\n".join(conflicts)))
related_images = (self.data.setdefault("spec", CommentedMap())
.setdefault("relatedImages", CommentedSeq()))
del related_images[:]
for p in by_name.values():
log.debug("%s - Set relatedImage %s (from %s): %s",
self.path, p.name, p.description, p.image)
related_images.append(p.as_yaml_object())
示例14: delete_all_annotations
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def delete_all_annotations(obj):
if isinstance(obj, (dict, CommentedMap)):
obj.get("metadata", {}).pop("annotations", None)
for v in obj.values():
delete_all_annotations(v)
elif isinstance(obj, (list, CommentedSeq)):
for item in obj:
delete_all_annotations(item)
示例15: upgrade_settings
# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedMap [as 别名]
def upgrade_settings(defaults, current, key=None):
upgraded = False
res = CommentedMap()
for k, v in defaults.items():
if k not in current:
res[k] = v
upgraded = True
log.info("Added field: \'%s%s\'.", k, '' if not key else ' to \'%s\'.' % key)
else:
res[k] = current[k]
if hasattr(v, 'items'):
if k in current:
sub_upgrade, res[k] = upgrade_settings(v, current[k], k)
if sub_upgrade:
upgraded = True
else:
res[k] = v
upgraded = True
return upgraded, res
############################################################
# MAIN
############################################################