[fix] Removing YAML inheritance as it doesn't merge nested dictionaries

This commit is contained in:
Al
2016-04-27 15:10:08 -04:00
parent 169f1db3bd
commit dff4a5e76e
2 changed files with 1147 additions and 1149 deletions

View File

@@ -10,7 +10,6 @@
# country overrides section. Each country can create its own copy of the entire top-level # country overrides section. Each country can create its own copy of the entire top-level
# structure and it will be recursively merged with the defaults. # structure and it will be recursively merged with the defaults.
default: &default
# Number # Number
# ====== # ======
# Number, No., #, etc. can be used in both floor and apartment numbers, # Number, No., #, etc. can be used in both floor and apartment numbers,
@@ -1176,7 +1175,6 @@ default: &default
countries: countries:
# United States # United States
us: us:
<<: *default
levels: levels:
storey: &story storey: &story
canonical: story canonical: story
@@ -1263,7 +1261,6 @@ countries:
# Canada # Canada
# Specifically Canadian English. If the address is in French it will use fr.yaml # Specifically Canadian English. If the address is in French it will use fr.yaml
ca: ca:
<<: *default
levels: levels:
# Note: Canadian English uses "storey" keeping with the British convention, so no need to change that # Note: Canadian English uses "storey" keeping with the British convention, so no need to change that
@@ -1291,7 +1288,6 @@ countries:
combined_probability: 0.1 combined_probability: 0.1
# Australia # Australia
au: au:
<<: *default
po_boxes: &australia_po_boxes po_boxes: &australia_po_boxes
alphanumeric: alphanumeric:
default: *po_box default: *po_box
@@ -1334,7 +1330,6 @@ countries:
# New Zealand - same rules as Australia # New Zealand - same rules as Australia
nz: nz:
<<: *default
po_boxes: *australia_po_boxes po_boxes: *australia_po_boxes
units: *australia_unit_types units: *australia_unit_types

View File

@@ -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