Michał Górny
2018-08-16 17:47:18 UTC
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.
---
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)
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.
---
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)
--
2.18.0
2.18.0