File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,10 +11,14 @@ phonenumbers/geodata/locale.py: DumpLocale.class
1111
1212locale : phonenumbers/geodata/locale.py
1313
14- phonenumbers/geodata/__init__.py : buildgeocodingdata.py ../resources/geocoding
14+ phonenumbers/geodata :
15+ mkdir $@
16+ phonenumbers/geodata/__init__.py : buildgeocodingdata.py ../resources/geocoding | phonenumbers/geodata
1517 $(PYTHON ) buildgeocodingdata.py ../resources/geocoding $@
1618
17- tests/testgeodata/__init__.py : buildgeocodingdata.py ../resources/test/geocoding
19+ tests/testgeodata :
20+ mkdir $@
21+ tests/testgeodata/__init__.py : buildgeocodingdata.py ../resources/test/geocoding | tests/testgeodata
1822 $(PYTHON ) buildgeocodingdata.py ../resources/test/geocoding $@
1923
2024geodata : phonenumbers/geodata/__init__.py tests/testgeodata/__init__.py
Original file line number Diff line number Diff line change 4545
4646from .phonenumberutil import format_number , PhoneNumberFormat , is_valid_number
4747from .phonenumberutil import region_code_for_number
48- from .geodata import GEOCODE_DATA , GEOCODE_LONGEST_PREFIX
49- from .geodata .locale import LOCALE_DATA
48+ try :
49+ from .geodata import GEOCODE_DATA , GEOCODE_LONGEST_PREFIX
50+ from .geodata .locale import LOCALE_DATA
51+ except ImportError : # pragma no cover
52+ # Before the generated code exists, the teodata/ directory is empty.
53+ # The generation process imports this module, creating a circular
54+ # dependency. The hack below works around this.
55+ import os
56+ import sys
57+ if (os .path .basename (sys .argv [0 ]) == "buildmetadatafromxml.py" or
58+ os .path .basename (sys .argv [0 ]) == "buildgeocodingdata.py" ):
59+ print >> sys .stderr , "Failed to import generated data (but OK as during autogeneration)"
60+ GEOCODE_DATA = {'1' : {'en' : u'United States' }}
61+ GEOCODE_LONGEST_PREFIX = 1
62+ LOCALE_DATA = {'US' : {'en' : u'United States' }}
63+ else :
64+ raise
5065
5166
5267def _may_fall_back_to_english (lang ):
Original file line number Diff line number Diff line change 4747 # dependency. The hack below works around this.
4848 import os
4949 import sys
50- if os .path .basename (sys .argv [0 ]) == "buildmetadatafromxml.py" :
50+ if (os .path .basename (sys .argv [0 ]) == "buildmetadatafromxml.py" or
51+ os .path .basename (sys .argv [0 ]) == "buildgeocodingdata.py" ):
5152 print >> sys .stderr , "Failed to import generated data (but OK as during autogeneration)"
5253 _COUNTRY_CODE_TO_REGION_CODE = {1 : ("US" ,)}
5354 else :
You can’t perform that action at this time.
0 commit comments