diff --git a/conans/__init__.py b/conans/__init__.py index abb29eb7149..4df6ae3e787 100644 --- a/conans/__init__.py +++ b/conans/__init__.py @@ -13,4 +13,4 @@ COMPLEX_SEARCH_CAPABILITY = "complex_search" SERVER_CAPABILITIES = [COMPLEX_SEARCH_CAPABILITY, ] -__version__ = '0.19.2' +__version__ = '0.19.3' diff --git a/conans/model/info.py b/conans/model/info.py index c7e3b33d4d7..24b4ead1c73 100644 --- a/conans/model/info.py +++ b/conans/model/info.py @@ -188,7 +188,8 @@ def create(settings, options, requires, indirect_requires, non_devs_requirements @staticmethod def loads(text): parser = ConfigParser(text, ["settings", "full_settings", "options", "full_options", - "requires", "full_requires", "scope", "recipe_hash"]) + "requires", "full_requires", "scope", "recipe_hash"], + raise_unexpected_field=False) result = ConanInfo() result.settings = Values.loads(parser.settings) diff --git a/conans/test/server/conf_test.py b/conans/test/server/conf_test.py index 992857087f5..8f2343f890f 100644 --- a/conans/test/server/conf_test.py +++ b/conans/test/server/conf_test.py @@ -1,3 +1,5 @@ +from conans.errors import ConanException +from conans.util.config_parser import ConfigParser import unittest from conans.util.files import save import os @@ -38,6 +40,35 @@ def setUp(self): save(server_conf, fileconfig % self.storage_path) self.environ = {} + def test_unexpected_section(self): + text = """ +[one] +text=value +[two] +other=var +[three] +var +[moon] +var=walker + """ + + self.assertRaises(ConanException, ConfigParser, text, ["one", "two", "three"]) + conf = ConfigParser(text, ["one", "two", "three"], raise_unexpected_field=False) + self.assertEquals(conf.one, "text=value") + self.assertEquals(conf.two, "other=var") + self.assertEquals(conf.three, "var") + self.assertEquals(conf.moon, "var=walker") + with self.assertRaisesRegexp(ConanException, "Unrecognized field 'NOEXIST'"): + conf.NOEXIST + + # IF an old config file is readed but the section is in the list, just return it empty + text = """ +[one] +text=value + """ + conf = ConfigParser(text, ["one", "two", "three"], raise_unexpected_field=False) + self.assertEquals(conf.two, "") + def test_values(self): config = ConanServerConfigParser(self.file_path, environment=self.environ) self.assertEquals(config.jwt_secret, "mysecret") diff --git a/conans/util/config_parser.py b/conans/util/config_parser.py index 534f5df381d..69465295594 100644 --- a/conans/util/config_parser.py +++ b/conans/util/config_parser.py @@ -26,7 +26,7 @@ class ConfigParser(object): as parser.section Currently used in ConanInfo and ConanFileTextLoader """ - def __init__(self, text, allowed_fields=None, parse_lines=False): + def __init__(self, text, allowed_fields=None, parse_lines=False, raise_unexpected_field=True): self._sections = {} self._allowed_fields = allowed_fields or [] pattern = re.compile("^\[([a-z_]{2,50})\]") @@ -43,7 +43,7 @@ def __init__(self, text, allowed_fields=None, parse_lines=False): else: raise ConanException("ConfigParser: Bad syntax '%s'" % line) if field: - if self._allowed_fields and field not in self._allowed_fields: + if self._allowed_fields and field not in self._allowed_fields and raise_unexpected_field: raise ConanException("ConfigParser: Unrecognized field '%s'" % field) current_lines = [] self._sections[field] = current_lines