本文整理汇总了Python中yaml.__version__方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.__version__方法的具体用法?Python yaml.__version__怎么用?Python yaml.__version__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml
的用法示例。
在下文中一共展示了yaml.__version__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_yaml
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import __version__ [as 别名]
def read_yaml(filepath: str, default_value: Optional[Any] = None, strict: bool = False) -> Dict:
"""Read a YAML file in. If no file is found and default value is set, return that instead. Otherwise error
:param filepath: str, A file to load
:param default_value: If the file doesn't exist, return return this. Defaults to an empty dict.
:param strict: bool, If true raise an error on file not found.
:return: dict, The read yaml object
"""
if not os.path.exists(filepath):
if strict:
raise IOError("No file {} found".format(filepath))
return default_value if default_value is not None else {}
with open(filepath) as f:
import yaml
from distutils.version import LooseVersion
if LooseVersion(yaml.__version__) >= LooseVersion("5.1"):
return yaml.load(f, Loader=yaml.FullLoader)
return yaml.load(f)
示例2: yaml_load
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import __version__ [as 别名]
def yaml_load(f: typing.Union[str, typing.IO[str]]) -> typing.Any:
"""Wrapper over yaml.load using the C loader if possible."""
start = datetime.datetime.now()
# WORKAROUND for https://github.com/yaml/pyyaml/pull/181
with log.ignore_py_warnings(
category=DeprecationWarning,
message=r"Using or importing the ABCs from 'collections' instead "
r"of from 'collections\.abc' is deprecated.*"):
data = yaml.load(f, Loader=YamlLoader)
end = datetime.datetime.now()
delta = (end - start).total_seconds()
deadline = 10 if 'CI' in os.environ else 2
if delta > deadline: # pragma: no cover
log.misc.warning(
"YAML load took unusually long, please report this at "
"https://github.com/qutebrowser/qutebrowser/issues/2777\n"
"duration: {}s\n"
"PyYAML version: {}\n"
"C extension: {}\n"
"Stack:\n\n"
"{}".format(
delta, yaml.__version__, YAML_C_EXT,
''.join(traceback.format_stack())))
return data
示例3: default_params
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import __version__ [as 别名]
def default_params():
'''Return default configuration
'''
default_params_yaml = open("config.yaml", "r")
if(yaml.__version__[0]>=5):
params = yaml.safe_load(default_params_yaml)
else:
params = yaml.load(default_params_yaml)
params['image_format'] = get_img_format(params['base_dir'])
return params
示例4: test_datetimes
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import __version__ [as 别名]
def test_datetimes(self):
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["."]), "")
if yaml.__version__ < '5.3':
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["-y", "."]), "- '2016-12-20T22:07:36'\n")
else:
self.assertEqual(self.run_yq("- 2016-12-20T22:07:36Z\n", ["-y", "."]), "- '2016-12-20T22:07:36+00:00'\n")
self.assertEqual(self.run_yq("2016-12-20", ["."]), "")
self.assertEqual(self.run_yq("2016-12-20", ["-y", "."]), "'2016-12-20'\n")
示例5: get_version
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import __version__ [as 别名]
def get_version(pkg):
s = ".".join(pkg.__version__.split(".")[:2])
return float(s)
示例6: get_platform_info
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import __version__ [as 别名]
def get_platform_info():
from gi.repository import GObject
from gi.repository import Gtk
import yaml
functions = [
platform.machine,
platform.platform,
platform.processor,
platform.python_version,
platform.release,
platform.system,
]
names_values = [(func.__name__, func()) for func in functions]
names_values.extend(
[
(
"GTK",
(
Gtk.get_major_version(),
Gtk.get_minor_version(),
Gtk.get_micro_version(),
),
),
("Glib", GObject.glib_version),
("PyGObject", GObject.pygobject_version),
("YAML", yaml.__version__),
]
)
vals = ["{}: {}".format(name, val) for name, val in names_values]
return "System info: " + ", ".join(vals)