[fix] Removing YAML inheritance as it doesn't merge nested dictionaries
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ from geodata.address_expansions.address_dictionaries import address_phrase_dicti
|
|||||||
from geodata.configs.utils import nested_get, DoesNotExist, recursive_merge
|
from geodata.configs.utils import nested_get, DoesNotExist, recursive_merge
|
||||||
from geodata.math.sampling import cdf, check_probability_distribution
|
from geodata.math.sampling import cdf, check_probability_distribution
|
||||||
|
|
||||||
|
|
||||||
this_dir = os.path.realpath(os.path.dirname(__file__))
|
this_dir = os.path.realpath(os.path.dirname(__file__))
|
||||||
|
|
||||||
ADDRESS_CONFIG_DIR = os.path.join(this_dir, os.pardir, os.pardir, os.pardir,
|
ADDRESS_CONFIG_DIR = os.path.join(this_dir, os.pardir, os.pardir, os.pardir,
|
||||||
@@ -29,14 +30,17 @@ class AddressConfig(object):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
config = yaml.load(open(os.path.join(ADDRESS_CONFIG_DIR, filename)))
|
config = yaml.load(open(os.path.join(ADDRESS_CONFIG_DIR, filename)))
|
||||||
default = config['default']
|
|
||||||
countries = config.pop('countries', {})
|
countries = config.pop('countries', {})
|
||||||
|
|
||||||
if countries:
|
for k in countries.keys():
|
||||||
default['countries'] = countries
|
country_config = countries[k]
|
||||||
|
config_copy = copy.deepcopy(config)
|
||||||
|
countries[k] = recursive_merge(config_copy, country_config)
|
||||||
|
|
||||||
|
config['countries'] = countries
|
||||||
|
|
||||||
lang = filename.strip('.yaml')
|
lang = filename.strip('.yaml')
|
||||||
self.address_configs[lang] = default
|
self.address_configs[lang] = config
|
||||||
|
|
||||||
self.sample_phrases = {}
|
self.sample_phrases = {}
|
||||||
|
|
||||||
@@ -55,7 +59,6 @@ class AddressConfig(object):
|
|||||||
if country_config:
|
if country_config:
|
||||||
config = country_config
|
config = country_config
|
||||||
|
|
||||||
|
|
||||||
value = nested_get(config, keys)
|
value = nested_get(config, keys)
|
||||||
if value is not DoesNotExist:
|
if value is not DoesNotExist:
|
||||||
return value
|
return value
|
||||||
|
|||||||
Reference in New Issue
Block a user