File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4444# See the License for the specific language governing permissions and
4545# limitations under the License.
4646
47- from .util import u
47+ from .util import prnt , u
4848from .phonenumberutil import format_number , PhoneNumberFormat , is_valid_number
4949from .phonenumberutil import region_code_for_number
50- from .geodata import GEOCODE_DATA , GEOCODE_LONGEST_PREFIX
51- from .geodata .locale import LOCALE_DATA
5250
51+ # Import auto-generated data structures
52+ try :
53+ from .geodata import GEOCODE_DATA , GEOCODE_LONGEST_PREFIX
54+ from .geodata .locale import LOCALE_DATA
55+ except ImportError : # pragma no cover
56+ # Before the generated code exists, the geodata/ directory is empty.
57+ # The generation process imports this module, creating a circular
58+ # dependency. The hack below works around this.
59+ import os
60+ import sys
61+ if (os .path .basename (sys .argv [0 ]) == "buildgeocodingdata.py" or
62+ os .path .basename (sys .argv [0 ]) == "buildmetadatafromxml.py" ):
63+ prnt ("Failed to import generated data (but OK as during autogeneration)" , file = sys .stderr )
64+ GEOCODE_DATA = {}
65+ GEOCODE_LONGEST_PREFIX = 3
66+ LOCALE_DATA = {}
67+ else :
68+ raise
5369
5470def _may_fall_back_to_english (lang ):
5571 # Don't fall back to English if the requested language is among the following:
You can’t perform that action at this time.
0 commit comments