[fix] Removing YAML inheritance as it doesn't merge nested dictionaries
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
# 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.
|
||||
|
||||
default: &default
|
||||
# Number
|
||||
# ======
|
||||
# Number, No., #, etc. can be used in both floor and apartment numbers,
|
||||
@@ -1176,7 +1175,6 @@ default: &default
|
||||
countries:
|
||||
# United States
|
||||
us:
|
||||
<<: *default
|
||||
levels:
|
||||
storey: &story
|
||||
canonical: story
|
||||
@@ -1263,7 +1261,6 @@ countries:
|
||||
# Canada
|
||||
# Specifically Canadian English. If the address is in French it will use fr.yaml
|
||||
ca:
|
||||
<<: *default
|
||||
levels:
|
||||
# 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
|
||||
# Australia
|
||||
au:
|
||||
<<: *default
|
||||
po_boxes: &australia_po_boxes
|
||||
alphanumeric:
|
||||
default: *po_box
|
||||
@@ -1334,7 +1330,6 @@ countries:
|
||||
|
||||
# New Zealand - same rules as Australia
|
||||
nz:
|
||||
<<: *default
|
||||
po_boxes: *australia_po_boxes
|
||||
units: *australia_unit_types
|
||||
|
||||
|
||||
@@ -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.math.sampling import cdf, check_probability_distribution
|
||||
|
||||
|
||||
this_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
|
||||
ADDRESS_CONFIG_DIR = os.path.join(this_dir, os.pardir, os.pardir, os.pardir,
|
||||
@@ -29,14 +30,17 @@ class AddressConfig(object):
|
||||
continue
|
||||
|
||||
config = yaml.load(open(os.path.join(ADDRESS_CONFIG_DIR, filename)))
|
||||
default = config['default']
|
||||
countries = config.pop('countries', {})
|
||||
|
||||
if countries:
|
||||
default['countries'] = countries
|
||||
for k in countries.keys():
|
||||
country_config = countries[k]
|
||||
config_copy = copy.deepcopy(config)
|
||||
countries[k] = recursive_merge(config_copy, country_config)
|
||||
|
||||
config['countries'] = countries
|
||||
|
||||
lang = filename.strip('.yaml')
|
||||
self.address_configs[lang] = default
|
||||
self.address_configs[lang] = config
|
||||
|
||||
self.sample_phrases = {}
|
||||
|
||||
@@ -55,7 +59,6 @@ class AddressConfig(object):
|
||||
if country_config:
|
||||
config = country_config
|
||||
|
||||
|
||||
value = nested_get(config, keys)
|
||||
if value is not DoesNotExist:
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user