commit: a0d10b164038c4ef172039f5d281240c48d3611f
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 16 17:06:12 2018 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Aug 16 20:05:10 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a0d10b16
repoman.config: Make yaml loader optional
Make the yaml loader optional, delaying the failure until the user
attempts to actually load a yaml file. Given that pyyaml is an external
dependency, there is no real reason to fail as soon as repoman.config is
loaded if YAML may not be used at all.
Reviewed-by: Zac Medico <zmedico <AT> gentoo.org>
repoman/lib/repoman/config.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/repoman/lib/repoman/config.py b/repoman/lib/repoman/config.py
index 578bbccde..decf9b90a 100644
--- a/repoman/lib/repoman/config.py
+++ b/repoman/lib/repoman/config.py
@@ -6,7 +6,10 @@ import json
import os
import stat
-import yaml
+try:
+ import yaml
+except ImportError:
+ yaml = None
try:
FileNotFoundError
@@ -73,6 +76,9 @@ def _yaml_load(filename):
Load filename as YAML and return a dict. Raise ConfigError if
it fails to load.
"""
+ if yaml is None:
+ raise ImportError('Please install pyyaml in order to read yaml
files')
+
with open(filename, 'rt') as f:
try:
return yaml.safe_load(f)