Python yaml.__version__() Examples
The following are 6
code examples of yaml.__version__().
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
yaml
, or try the search function
.
Example #1
Source File: utils.py From mead-baseline with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: utils.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
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
Example #3
Source File: config.py From ILCC with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #4
Source File: test.py From yq with Apache License 2.0 | 5 votes |
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")
Example #5
Source File: utils.py From mead-baseline with Apache License 2.0 | 5 votes |
def get_version(pkg): s = ".".join(pkg.__version__.split(".")[:2]) return float(s)
Example #6
Source File: filesystem.py From rednotebook with GNU General Public License v2.0 | 5 votes |
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)