Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: repoman/lib/repoman/
Date: Thu, 16 Aug 2018 20:05:42
Message-Id: 1534449910.a0d10b164038c4ef172039f5d281240c48d3611f.mgorny@gentoo
1 commit: a0d10b164038c4ef172039f5d281240c48d3611f
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Thu Aug 16 17:06:12 2018 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Thu Aug 16 20:05:10 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a0d10b16
7
8 repoman.config: Make yaml loader optional
9
10 Make the yaml loader optional, delaying the failure until the user
11 attempts to actually load a yaml file. Given that pyyaml is an external
12 dependency, there is no real reason to fail as soon as repoman.config is
13 loaded if YAML may not be used at all.
14
15 Reviewed-by: Zac Medico <zmedico <AT> gentoo.org>
16
17 repoman/lib/repoman/config.py | 8 +++++++-
18 1 file changed, 7 insertions(+), 1 deletion(-)
19
20 diff --git a/repoman/lib/repoman/config.py b/repoman/lib/repoman/config.py
21 index 578bbccde..decf9b90a 100644
22 --- a/repoman/lib/repoman/config.py
23 +++ b/repoman/lib/repoman/config.py
24 @@ -6,7 +6,10 @@ import json
25 import os
26 import stat
27
28 -import yaml
29 +try:
30 + import yaml
31 +except ImportError:
32 + yaml = None
33
34 try:
35 FileNotFoundError
36 @@ -73,6 +76,9 @@ def _yaml_load(filename):
37 Load filename as YAML and return a dict. Raise ConfigError if
38 it fails to load.
39 """
40 + if yaml is None:
41 + raise ImportError('Please install pyyaml in order to read yaml files')
42 +
43 with open(filename, 'rt') as f:
44 try:
45 return yaml.safe_load(f)