Coverage for pygeodesy/lazily.py: 96%

213 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-09-09 13:03 -0400

1 

2# -*- coding: utf-8 -*- 

3 

4u'''Lazily import C{pygeodesy} modules and attributes, based on 

5U{lazy_import<https://modutil.ReadTheDocs.io/en/latest/#lazy_import>} 

6from I{Brett Cannon}'s U{modutil<https://PyPI.org/project/modutil>}. 

7 

8C{Lazy import} is I{supported only for }U{Python 3.7+ 

9<https://Snarky.Ca/lazy-importing-in-python-3-7>} and is I{enabled by 

10default} in U{PyGeodesy 18.11.10<https://PyPI.org/project/PyGeodesy>} 

11I{and newer}. 

12 

13To I{enable} C{lazy import}, set C{env} variable C{PYGEODESY_LAZY_IMPORT} 

14to C{1}, C{2}, C{3} or higher prior to C{import pygeodesy}. To I{disable} 

15C{lazy import}, set C{env} variable C{PYGEODESY_LAZY_IMPORT} to C{0} or 

16an empty string. Use C{2} or higher to print a message for each lazily 

17imported module and attribute, similar to C{env} variable C{PYTHONVERBOSE} 

18showing imports. Using C{3} or higher also shows the importing file name 

19and line number. 

20 

21@note: C{Lazy import} applies only to top-level modules of C{pygeodesy}. 

22 The C{lazy import} of a top-level module invariably loads all 

23 sub-modules imported by that top-level module. 

24 

25@note: C{Lazy import} raises a L{LazyAttributeError} or L{LazyImportError} 

26 depending on the cause of the error and such errors can occur late, 

27 after all initial imports. 

28''' 

29 

30from pygeodesy import internals as _internals, interns as _interns, \ 

31 _isfrozen # DON'T _lazy_import2 

32# from pygeodesy.errors import _error_init, _ImmutableError, _xkwds_item2 # _ALL_MODS 

33from pygeodesy.internals import _caller3, _envPYGEODESY, _headof, printf, _tailof, \ 

34 typename, _versions # _getenv, _PYGEODESY_ENV, \ 

35# _MODS_Base, _MODS.sys_version_info2 

36from pygeodesy.interns import _attribute_, _by_, _COLONSPACE_, _COMMASPACE_, _DALL_, \ 

37 _DMAIN_, _doesn_t_exist_, _DOT_, _EQUALSPACED_, _from_, \ 

38 _HASH_, _line_, _module_, NN, _no_, _not_, _pygeodesy_, \ 

39 _pygeodesy_abspath_, _SPACE_, _SUB_PACKAGES, _or_, \ 

40 _UNDER_, _version_, _sys, _intern # function, _1_ 

41try: 

42 from importlib import import_module 

43except ImportError as x: # Python 2.6- 

44 raise ImportError(_COLONSPACE_(x, _versions())) 

45# import sys as _sys # from .interns 

46 

47_a0 = () # PYCHOK empty tuple 

48_asSPACED_ = ' as ' 

49_FOR_DOCS = _envPYGEODESY('FOR_DOCS') # for epydoc ... 

50_imported_ = 'imported' 

51_init__all__ = _FOR_DOCS or _envPYGEODESY('_init__all__', _DALL_) == _DALL_ # PYCHOK exported 

52_lazily_ = 'lazily' 

53_PYTHON_X_DEV = getattr(_sys.flags, 'dev_mode', False) # PYCHOK Python 3.2+ 

54_unlazy = _unLazy0 = _isfrozen or _internals._MODS.sys_version_info2 < (3, 7) # PYCHOK mod.__getattr__ 3.7+ 

55_WARNINGS_X_DEV = _envPYGEODESY('WARNINGS') and (_PYTHON_X_DEV or bool(_sys.warnoptions)) # PYCHOK .props 

56 

57# @module_property[_RO?] <https://GitHub.com/jtushman/proxy_tools/> <https://discuss.Python.org/t/47379> 

58isLazy = None # see @var isLazy in .__init__ 

59 

60 

61class LazyAttributeError(AttributeError): 

62 '''Raised if a C{lazily imported} attribute is missing or invalid. 

63 ''' 

64 def __init__(self, *args, **kwds): 

65 _ALL_MODS.errors._error_init(AttributeError, self, args, **kwds) 

66 

67 

68class LazyImportError(ImportError): 

69 '''Raised if C{lazy import} is not supported, disabled or failed. 

70 ''' 

71 def __init__(self, *args, **kwds): 

72 _ALL_MODS.errors._error_init(ImportError, self, args, **kwds) 

73 

74 

75class _Dict(dict): 

76 '''(INTERNAL) Imports C{dict}. 

77 ''' 

78 _name = NN 

79 

80 def __getattr__(self, attr): 

81 try: 

82 return self[attr] 

83 except KeyError: 

84 return dict.__getattr__(self, attr) 

85 

86# def __setattr__(self, attr, value): 

87# if attr in self: 

88# self[attr] = value 

89# else: 

90# dict.__setattr__(self, attr, value) 

91 

92 def add(self, name, mod_, *subs): 

93 '''Add a C{[name] = mod_} item. 

94 

95 @raise AssertionError: The B{C{name}} already exists 

96 with a different B{C{mod_}}. 

97 ''' 

98 try: 

99 sub = self[name] # duplicate OK 

100 if sub != mod_ and sub not in subs: 

101 t = _DOT_(self._name, name) 

102 t = _COLONSPACE_(t, repr(sub)) 

103 t = _COMMASPACE_(t, _not_(repr(mod_))) 

104 raise AssertionError(t) 

105 except KeyError: 

106 self[name] = mod_ 

107 

108 def _NAME(self, which): 

109 self._name = _intern(typename(which).upper()) 

110 

111 

112class _NamedEnum_RO(dict): 

113 '''(INTERNAL) C{Read_Only} enum-like C{dict} sub-class. 

114 ''' 

115# _name = NN # also first kwd, __init__(_name=...) 

116 

117 def _DOT_(self, attr): # PYCHOK no cover 

118 return _DOT_(self._name, attr) # PYCHOK _name 

119 

120 def __getattr__(self, attr): 

121 try: 

122 return self[attr] 

123 except KeyError: 

124 t = self._DOT_(attr) 

125 raise LazyAttributeError(t, txt=_doesn_t_exist_) 

126 

127 def __setattr__(self, attr, value): # PYCHOK no cover 

128 e = _ALL_MODS.errors 

129 raise e._ImmutableError(self, attr, value, 

130 Error=LazyAttributeError) 

131 

132 def enums(self): 

133 # Yield all C{(mod_, tuple)} pairs 

134 for m, t in dict.items(self): 

135 n = m.replace(_UNDER_, _DOT_) 

136 if n != m: 

137 if m.startswith(_UNDER_): 

138 continue # skip _name= ... 

139 u = m.rstrip(_UNDER_) 

140 if u != m: 

141 u = len(u) 

142 n = n[:u] + m[u:] 

143 yield n, t 

144 

145 def fill_D(self, _D, which): 

146 # Fill C{_Dict _D}. 

147 _D._NAME(which) 

148 _a = _D.add 

149 for m, t in self.enums(): 

150 _a(m, _DOT_(m, NN, NN)) # import module 

151 for a in t: 

152 a, _, as_ = a.partition(_asSPACED_) 

153 if as_: # import attr as attr_ 

154 _a(as_, _DOT_(m, a, NN), *_SUB_PACKAGES) 

155 else: 

156 _a(a, m) 

157 return _D 

158 

159 

160def _a(*names): 

161 '''(INTERNAL) Intern all C{names}. 

162 ''' 

163 return tuple(map(_intern, names)) if names else _a0 

164 

165 

166def _ALL_ATTRS(*attrs): 

167 '''(INTERNAL) Unravel all exported module attributes. 

168 ''' 

169 t = () 

170 for attr in attrs: 

171 t += tuple(map(_getattras, attr)) 

172 return t 

173 

174 

175_ALL_INIT = _a(_pygeodesy_abspath_, _version_) 

176 

177# __all__ value for most modules, accessible as _ALL_LAZY.<module> 

178_ALL_LAZY = _NamedEnum_RO(_name='_ALL_LAZY', 

179 albers=_a('AlbersEqualArea', 'AlbersEqualArea2', 'AlbersEqualArea4', 

180 'AlbersEqualAreaCylindrical', 'AlbersEqualAreaNorth', 'AlbersEqualAreaSouth', 

181 'AlbersError', 'Albers7Tuple'), 

182 auxilats=_a(), # module only 

183 azimuthal=_a('AzimuthalError', 'Azimuthal7Tuple', 

184 'Equidistant', 'EquidistantExact', 'EquidistantGeodSolve', 'EquidistantKarney', 

185 'Gnomonic', 'GnomonicExact', 'GnomonicGeodSolve', 'GnomonicKarney', 

186 'LambertEqualArea', 'Orthographic', 'Stereographic', 

187 'equidistant', 'gnomonic'), 

188 basics=_a('clips', 'copysign0', 'copytype', 'halfs2', 

189 'int1s', 'isbool', 'isCartesian', 'isclass', 'iscomplex', 'isDEPRECATED', 'isfloat', 

190 'isidentifier', 'isinstanceof', 'isint', 'isiterable', 'isiterablen', 'isiterabletype', 

191 'iskeyword', 'isLatLon', 'islistuple', 'isNvector', 'isodd', 

192 'isscalar', 'issequence', 'isstr', 'issubclassof', 'itemsorted', 

193 'len2', 'map1', 'map2', 'max2', 'min2', 'neg', 'neg_', 

194 'signBit', 'signOf', 'splice', 'str2ub', 'ub2str', 'unsigned0'), 

195 booleans=_a('BooleanFHP', 'BooleanGH', 'LatLonFHP', 'LatLonGH', 

196 'isBoolean'), 

197 cartesianBase=_a('RadiusThetaPhi3Tuple', 'rtp2xyz', 'rtp2xyz_', 'xyz2rtp', 'xyz2rtp_'), 

198 clipy=_a('ClipCS4Tuple', 'ClipFHP4Tuple', 'ClipGH4Tuple', 'ClipLB6Tuple', 'ClipSH3Tuple', 

199 'clipCS4', 'clipFHP4', 'clipGH4', 'clipLB6', 'clipSH', 'clipSH3'), 

200 css=_a('CassiniSoldner', 'Css', 'CSSError', 'toCss', 

201 'EasNorAziRk4Tuple', 'EasNorAziRkEqu6Tuple', 'LatLonAziRk4Tuple'), 

202 constants=_a('DIG', 'EPS', 'EPS0', 'EPS02', 'EPS1', 'EPS2', 'EPS4', 'EPS_2', 

203 'INF', 'INT0', 'MANT_DIG', 'MAX', 'MAX_EXP', 'MIN', 'MIN_EXP', 'NAN', 'NEG0', 'NINF', 

204 'PI', 'PI2', 'PI_2', 'PI3', 'PI_3', 'PI3_2', 'PI4', 'PI_4', 'PI_6', 

205 'R_FM', 'R_GM', 'R_KM', 'R_M', 'R_MA', 'R_MB', 'R_NM', 'R_QM', 'R_SM', 'R_VM', 

206 'float_', 'float0_', 'isclose', 'isfinite', 'isinf', 'isint0', 

207 'isnan', 'isnear0', 'isnear1', 'isnear90', 'isneg', 'isneg0', 'isninf', 'isnon0', 

208 'remainder'), 

209 datums=_a('Datum', 'Datums', 'Transform', 'Transforms'), 

210# deprecated=_a(), # module only 

211 dms=_a('F_D', 'F_DM', 'F_DMS', 'F_DEG', 'F_MIN', 'F_SEC', 'F_D60', 'F__E', 'F__F', 'F__G', 'F_RAD', 

212 'F_D_', 'F_DM_', 'F_DMS_', 'F_DEG_', 'F_MIN_', 'F_SEC_', 'F_D60_', 'F__E_', 'F__F_', 'F__G_', 'F_RAD_', 

213 'F_D__', 'F_DM__', 'F_DMS__', 'F_DEG__', 'F_MIN__', 'F_SEC__', 'F_D60__', 'F__E__', 'F__F__', 'F__G__', 'F_RAD__', 

214 'S_DEG', 'S_MIN', 'S_SEC', 'S_DMS', 'S_RAD', 'S_SEP', 

215 'bearingDMS', 'clipDegrees', 'clipRadians', 'compassDMS', 'compassPoint', 

216 'degDMS', 'latDMS', 'latlonDMS', 'latlonDMS_', 'lonDMS', 'normDMS', 

217 'parseDDDMMSS', 'parseDMS', 'parseDMS2', 'parse3llh', 'parseRad', 'precision', 'toDMS'), 

218 ecef=_a('EcefFarrell21', 'EcefFarrell22', 'EcefKarney', 'EcefSudano', 'EcefUPC', 'EcefVeness', 'EcefYou', 

219 'EcefError', 'EcefMatrix', 'Ecef9Tuple'), 

220 ecefLocals=_a(), # module only 

221 elevations=_a('Elevation2Tuple', 'GeoidHeight2Tuple', 

222 'elevation2', 'geoidHeight2'), 

223 ellipsoidalBase=_a(), # module only 

224 ellipsoidalBaseDI=_a(), # module only 

225 ellipsoidalExact=_a(), # module only 

226 ellipsoidalGeodSolve=_a(), # module only 

227 ellipsoidalKarney=_a(), # module only 

228 ellipsoidalNvector=_a(), # module only 

229 ellipsoidalVincenty=_a('VincentyError',), # nothing else 

230 ellipsoids=_a('a_f2Tuple', 'Circle4Tuple', 'Curvature2Tuple', 

231 'Ellipsoid', 'Ellipsoid2', 'Ellipsoids', 

232 'a_b2e', 'a_b2e2', 'a_b2e22', 'a_b2e32', 'a_b2f', 'a_b2f_', 'a_b2f2', 'a_b2n', 

233 'a_f2b', 'a_f_2b', 'b_f2a', 'b_f_2a', 

234 'e2f', 'e22f', 

235 'f2e2', 'f2e22', 'f2e32', 'f_2f', 'f2f_', 'f2f2', 'f2n', 'n2e2', 'n2f', 'n2f_'), 

236 elliptic=_a('Elliptic', 'EllipticError', 'Elliptic3Tuple'), 

237 epsg=_a('Epsg', 'EPSGError'), 

238 errors=_a('AuxError', 'ClipError', 'CrossError', 'GeodesicError', 'IntersectionError', 

239 'NumPyError', 'LenError', 'LimitError', 'MGRSError', 

240 'ParseError', 'PointsError', 'RangeError', 'RhumbError', 

241 'SciPyError', 'SciPyWarning', 'TRFError', 'TriangleError', 'UnitError', 'VectorError', 

242 'crosserrors', 'exception_chaining', 'isError', 'limiterrors', 'rangerrors'), 

243 etm=_a('Etm', 'ETMError', 'ExactTransverseMercator', 

244 'parseETM5', 'toEtm8'), 

245 fmath=_a('Fdot', 'Fdot_', 'Fhorner', 'Fhypot', 'Fpolynomial', 'Fpowers', 'Fcbrt', 'Froot', 'Fsqrt', 

246 'bqrt', 'cbrt', 'cbrt2', 'euclid', 'euclid_', 

247 'facos1', 'fasin1', 'fatan', 'fatan1', 'fatan2', 'favg', 

248 'fdot', 'fdot_', 'fdot3', 'fma', 'fmean', 'fmean_', 'fhorner', 'fidw', 'f2mul_', 

249 'fpolynomial', 'fpowers', 'fprod', 'frandoms', 'frange', 'freduce', 'fremainder', 

250 'hypot', 'hypot_', 'hypot1', 'hypot2', 'hypot2_', 

251 'norm2', 'norm_', 'sqrt0', 'sqrt3', 'sqrt_a', 'zcrt', 'zqrt'), 

252 formy=_a('Radical2Tuple', 

253 'angle2chord', 'antipode', 'antipode_', 'bearing', 'bearing_', 

254 'chord2angle', 'compassAngle', 'cosineLaw', 'cosineLaw_', 

255 'equirectangular', 'equirectangular4', 'euclidean', 'euclidean_', 

256 'excessAbc_', 'excessCagnoli_', 'excessGirard_', 'excessLHuilier_', 

257 'excessKarney', 'excessKarney_', 'excessQuad', 'excessQuad_', 

258 'flatLocal', 'flatLocal_', 'flatPolar', 'flatPolar_', 

259 'hartzell', 'haversine', 'haversine_', 'heightOf', 'heightOrthometric', 'horizon', 'hubeny', 'hubeny_', 

260 'intersection2', 'intersections2', 'isantipode', 'isantipode_', 'isnormal', 'isnormal_', 

261 'normal', 'normal_', 'opposing', 'opposing_', 'radical2', 

262 'thomas', 'thomas_', 'vincentys', 'vincentys_'), 

263 frechet=_a('Frechet', 'FrechetDegrees', 'FrechetError', 'FrechetRadians', 'FrechetCosineLaw', 

264 'FrechetDistanceTo', 'FrechetEquirectangular', 'FrechetEuclidean', 'FrechetExact', 

265 'FrechetFlatLocal', 'FrechetFlatPolar', 'FrechetHaversine', 'FrechetHubeny', 'FrechetKarney', 

266 'FrechetThomas', 'FrechetVincentys', 'Frechet6Tuple', 

267 'frechet_'), 

268 fstats=_a('Fcook', 'Flinear', 'Fwelford'), 

269 fsums=_a('Fsum', 'DivMod2Tuple', 'Fsum2Tuple', 'ResidualError', 

270 'f2product', 'fsum', 'fsum_', 'fsumf_', 'fsum1', 'fsum1_', 'fsum1f_', 'nonfiniterrors'), 

271 gars=_a('Garef', 'GARSError'), 

272 geodesici=_a('Intersectool', 'Intersectool5Tuple', 'Intersect7Tuple', 

273 'Intersector', 'Intersector5Tuple', 'Middle5Tuple', 'XDict'), 

274 geodesicw=_a('Geodesic', 'GeodesicLine', 'Geodesic_WGS84'), 

275 geodesicx=_a('gx', 'gxarea', 'gxbases', 'gxline', # modules 

276 'GeodesicAreaExact', 'GeodesicExact', 'GeodesicLineExact', 'PolygonArea'), 

277 geodsolve=_a('GeodesicSolve', 'GeodesicLineSolve', 'GeodSolve12Tuple'), 

278 geohash=_a('Geohash', 'Geohashed', 'GeohashError', 'Neighbors8Dict', 'Resolutions2Tuple', 'Sizes3Tuple'), 

279 geoids=_a('GeoidError', 'GeoidEGM96', 'GeoidG2012B', 'GeoidKarney', 'GeoidPGM', 'egmGeoidHeights', 

280 'PGMError', 'GeoidHeight5Tuple'), 

281 hausdorff=_a('Hausdorff', 'HausdorffDegrees', 'HausdorffError', 'HausdorffRadians', 'HausdorffCosineLaw', 

282 'HausdorffDistanceTo', 'HausdorffEquirectangular', 'HausdorffEuclidean', 'HausdorffExact', 

283 'HausdorffFlatLocal', 'HausdorffFlatPolar', 'HausdorffHaversine', 'HausdorffHubeny', 

284 'HausdorffKarney', 'HausdorffThomas', 'HausdorffVincentys', 'Hausdorff6Tuple', 

285 'hausdorff_', 'randomrangenerator'), 

286 heights=_a('HeightCubic', 'HeightError', 'HeightIDWcosineLaw', 'HeightIDWdistanceTo', 

287 'HeightIDWequirectangular', 'HeightIDWeuclidean', 'HeightIDWexact', 'HeightIDWflatLocal', 

288 'HeightIDWflatPolar', 'HeightIDWhaversine', 'HeightIDWhubeny', 'HeightIDWkarney', 'HeightIDWthomas', 

289 'HeightIDWvincentys', 'HeightLinear', 'HeightLSQBiSpline', 'HeightSmoothBiSpline'), 

290 internals=_internals.__all__, 

291 interns=_interns.__all__, 

292 iters=_a('LatLon2PsxyIter', 'PointsIter', 'points2', 

293 'isNumpy2', 'isPoints2', 'isTuple2', 'iterNumpy2', 'iterNumpy2over'), 

294 karney=_a('Area3Tuple', 'Caps', 'Direct9Tuple', 'GDict', 'Inverse10Tuple', 'Rhumb8Tuple'), 

295 ktm=_a('KTMError', 'KTransverseMercator'), 

296 latlonBase=_a('latlon2n_xyz', 'philam2n_xyz'), 

297 lazily=_a('LazyAttributeError', 'LazyImportError', 'isLazy'), 

298 lcc=_a('Conic', 'Conics', 'Lcc', 'LCCError', 'toLcc'), 

299 ltp=_a('Attitude', 'AttitudeError', 'ChLV', 'ChLVa', 'ChLVe', 'Frustum', 

300 'LocalCartesian', 'LocalError', 'Ltp', 'tyr3d'), 

301 ltpTuples=_a('Aer', 'Aer4Tuple', 'Attitude4Tuple', 

302 'ChLVEN2Tuple', 'ChLV9Tuple', 'ChLVYX2Tuple', 'ChLVyx2Tuple', 

303 'Enu', 'Enu4Tuple', 'Footprint5Tuple', 'Local9Tuple', 'Los', 

304 'Ned', 'Ned4Tuple', 'Uvw', 'Uvw3Tuple', 'XyzLocal', 'Xyz4Tuple'), 

305 mgrs=_a('Mgrs', 'parseMGRS', 'toMgrs', 'Mgrs4Tuple', 'Mgrs6Tuple'), 

306 named=_a('ADict', 

307 'callername', 'classname', 'classnaming', 'modulename', 

308 'nameof', 'notImplemented', 'notOverloaded'), 

309 namedTuples=_a('Bearing2Tuple', 'Bounds2Tuple', 'Bounds4Tuple', 

310 'Destination2Tuple', 'Destination3Tuple', 

311 'Distance2Tuple', 'Distance3Tuple', 'Distance4Tuple', 

312 'EasNor2Tuple', 'EasNor3Tuple', 'Forward4Tuple', 'Intersection3Tuple', 

313 'LatLon2Tuple', 'LatLon3Tuple', 'LatLon4Tuple', 

314 'LatLonDatum3Tuple', 'LatLonDatum5Tuple', 

315 'LatLonPrec3Tuple', 'LatLonPrec5Tuple', 

316 'NearestOn2Tuple', 'NearestOn3Tuple', 'NearestOn6Tuple', 'NearestOn8Tuple', 

317 'PhiLam2Tuple', 'PhiLam3Tuple', 'PhiLam4Tuple', 'Point3Tuple', 'Points2Tuple', 

318 'Reverse4Tuple', 'Triangle7Tuple', 'Triangle8Tuple', 'Trilaterate5Tuple', 

319 'UtmUps2Tuple', 'UtmUps5Tuple', 'UtmUps8Tuple', 'UtmUpsLatLon5Tuple', 

320 'Vector2Tuple', 'Vector3Tuple', 'Vector4Tuple'), 

321 nvectorBase=_a('NorthPole', 'SouthPole', 'n_xyz2latlon', 'n_xyz2philam'), 

322 osgr=_a('Osgr', 'OSGRError', 'parseOSGR', 'toOsgr'), 

323 points=_a('LatLon_', 'LatLon2psxy', 'Numpy2LatLon', 'Shape2Tuple', 'Tuple2LatLon', 

324 'areaOf', 'boundsOf', 'centroidOf', 'fractional', 

325 'isclockwise', 'isconvex', 'isconvex_', 'isenclosedBy', 'ispolar', 

326 'luneOf', 'nearestOn5', 'perimeterOf', 'quadOf'), 

327 props=_a('Property', 'Property_RO', 'property_doc_', 

328 'property_RO', 'property_ROnce', 'property_ROver', 

329 'deprecated_class', 'deprecated_function', 'deprecated_method', 

330 'deprecated_Property_RO', 'deprecated_property_RO', 'DeprecationWarnings'), 

331 resections=_a('Collins5Tuple', 'ResectionError', 'Survey3Tuple', 'Tienstra7Tuple', 

332 'TriAngle5Tuple', 'TriSide2Tuple', 'TriSide4Tuple', 

333 'cassini', 'collins5', 'pierlot', 'pierlotx', 'tienstra7', 

334 'snellius3', 'wildberger3', 

335 'triAngle', 'triAngle5', 'triArea', 'triSide', 'triSide2', 'triSide4'), 

336 rhumb=_a(), # module only 

337 rhumb_aux_=_a('RhumbAux', 'RhumbLineAux'), 

338 rhumb_ekx=_a('Rhumb', 'RhumbLine'), 

339 rhumb_solve=_a('RhumbSolve', 'RhumbLineSolve', 'RhumbSolve7Tuple'), 

340 sphericalBase=_a(), # module only 

341 sphericalNvector=_a(), # module only 

342 sphericalTrigonometry=_a(), # module only 

343 simplify=_a('simplify1', 'simplifyRDP', 'simplifyRW', 'simplifyVW'), 

344 solveBase=_a(), # module only 

345 streprs=_a('anstr', 'attrs', 'enstr2', 'fstr', 'fstrzs', 'hstr', 'instr', 

346 'lrstrip', 'pairs', 'reprs', 'strs', 'unstr'), 

347 trf=_a('RefFrame', 'RefFrames', 'TransformXform', 'TRFXform', 'TRFXform7Tuple', 

348 'date2epoch', 'epoch2date', 'trfTransform0', 'trfTransforms', 'trfXform'), 

349 triaxials=_a('BetaOmega2Tuple', 'BetaOmega3Tuple', 'Jacobi2Tuple', 

350 'JacobiConformal', 'JacobiConformalSpherical', 

351 'Triaxial', 'Triaxial_', 'TriaxialError', 'Triaxials', 'hartzell4'), 

352 units=_a('Azimuth', 'Band', 'Bearing', 'Bearing_', 'Bool', 

353 'Degrees', 'Degrees_', 'Degrees2', 'Distance', 'Distance_', 'Easting', 'Epoch', 

354 'Feet', 'FIx', 'Float_', 'Height', 'Height_', 'HeightX', 'Int_', 

355 'Lam', 'Lamd', 'Lat', 'Lat_', 'Lon', 'Lon_', 

356 'Meter', 'Meter_', 'Meter2', 'Meter3', 'Northing', 'Number_', 

357 'Phi', 'Phid', 'Precision_', 'Radians', 'Radians_', 'Radians2', 

358 'Radius_', 'Scalar', 'Scalar_', 'Zone'), 

359 unitsBase=_a('Float', 'Int', 'Radius', 'Str'), 

360 ups=_a('Ups', 'UPSError', 'parseUPS5', 'toUps8', 'upsZoneBand5'), 

361 utily=_a('acos1', 'acre2ha', 'acre2m2', 'agdf', 'asin1', 'atan1', 'atan1d', 'atan2', 'atan2b', 'atan2d', 

362 'chain2m', 'circle4', 'cot', 'cot_', 'cotd', 'cotd_', 

363 'degrees', 'degrees90', 'degrees180', 'degrees360', 'degrees2grades', 'degrees2m', 

364 'fathom2m', 'ft2m', 'furlong2m', # 'degrees2grades as degrees2gons', 

365 'gdf', 'grades', 'grades400', 'grades2degrees', 'grades2radians', 

366# 'grades as gons', 'grades400 as gons400', 'grades2degrees as gons2degrees', 'grades2radians as gons2radians', 

367 'ha2acre', 'ha2m2', 'hav', 'km2m', 

368 'm2acre', 'm2chain', 'm2degrees', 'm2fathom', 'm2ft', 'm2furlong', 

369 'm2ha', 'm2km', 'm2NM', 'm2radians', 'm2SM', 'm2toise', 'm2yard', 

370 'NM2m', 'radians', 'radiansPI', 'radiansPI2', 'radiansPI_2', 'radians2m', 

371 'sincos2', 'SinCos2', 'sincos2_', 'sincos2d', 'sincos2d_', 'sincostan3', 'sincostan3d', 'SM2m', 

372 'tan', 'tan_', 'tand', 'tand_', 'tan_2', 'tanPI_2_2', 'toise2m', 'truncate', 

373 'unroll180', 'unrollPI', 

374 'wrap90', 'wrap180', 'wrap360', 'wrapPI_2', 'wrapPI', 'wrapPI2', 'wrap_normal', 

375 'yard2m'), 

376 utm=_a('Utm', 'UTMError', 'parseUTM5', 'toUtm8', 'utmZoneBand5'), 

377 utmups=_a('UtmUps', 'UTMUPSError', 'parseUTMUPS5', 'toUtmUps8', 

378 'utmupsValidate', 'utmupsValidateOK', 'utmupsZoneBand5'), 

379 utmupsBase=_a(), # module only 

380 vector2d=_a('Circin6Tuple', 'Circum3Tuple', 'Circum4Tuple', 'Meeus2Tuple', 'Radii11Tuple', 'Soddy4Tuple', 'Triaxum5Tuple', 

381 'circin6', 'circum3', 'circum4', 'circum4_', 'meeus2', 'radii11', 'soddy4', 'triaxum5', 'trilaterate2d2'), 

382 vector3d=_a('Vector3d', 'intersection3d3', 'iscolinearWith', 'nearestOn', 'nearestOn6', 'parse3d', 

383 'trilaterate3d2'), 

384 vector3dBase=_a(), # module only 

385 webmercator=_a('Wm', 'WebMercatorError', 'parseWM', 'toWm', 'EasNorRadius3Tuple'), 

386 wgrs=_a('Georef', 'WGRSError'),) 

387 

388_ALL_DEPRECATED = _NamedEnum_RO(_name='_ALL_DEPRECATED', 

389 deprecated=_a('bases', 'datum', 'nvector', # DEPRECATED modules and ... 

390 'rhumbaux', 'rhumbBase', 'rhumbsolve', 'rhumbx'), # ... names 

391 deprecated_bases=_a('LatLonHeightBase', 'points2'), 

392 deprecated_classes=_a('ClipCS3Tuple', 'EasNorExact4Tuple', 'EcefCartesian', 'Fn_rt', 

393 'FrechetCosineAndoyerLambert', 'FrechetCosineForsytheAndoyerLambert', 

394 'HausdorffCosineAndoyerLambert', 'HausdorffCosineForsytheAndoyerLambert', 

395 'HeightIDW', 'HeightIDW2', 'HeightIDW3', 'HeightIDWcosineAndoyerLambert', 

396 'HeightIDWcosineForsytheAndoyerLambert', 'Helmert7Tuple', 

397 'Lam_', 'LatLonExact4Tuple', 'NearestOn4Tuple', 'Ned3Tuple', 

398 'Phi_', 'RefFrameError', 'Rhumb7Tuple', 'RhumbOrder2Tuple', 

399 'Transform7Tuple', 'TriAngle4Tuple', 'UtmUps4Tuple', 'XDist'), 

400 deprecated_consterns=_a('EPS1_2', 'MANTIS', 'OK'), 

401 deprecated_datum=_a('Curvature2Tuple', 'Datum', 'Ellipsoid', 'Transform', # assert 

402 'Datums', 'Ellipsoids', 'Transforms', 

403 'R_FM', 'R_KM', 'R_M', 'R_MA', 'R_MB', 'R_NM', 'R_SM', 'R_VM'), 

404 deprecated_functions=_a('anStr', 'areaof', 'atand', 'bounds', # most of the DEPRECATED functions, except ellipsoidal ... 

405 'clipCS3', 'clipDMS', 'clipStr', 'collins', 'copysign', # ... and spherical flavors 

406 'cosineAndoyerLambert', 'cosineAndoyerLambert_', 

407 'cosineForsytheAndoyerLambert', 'cosineForsytheAndoyerLambert_', 

408 'decodeEPSG2', 'encodeEPSG', 'enStr2', 'equirectangular_', 'equirectangular3', 

409 'excessAbc', 'excessGirard', 'excessLHuilier', 

410 'false2f', 'falsed2f', 'float0', 'fStr', 'fStrzs', 'Fsum2product', 

411 'hypot3', 'inStr', 'isenclosedby', 'istuplist', 

412 'joined', 'joined_', 'nearestOn3', 'nearestOn4', 

413 'parseUTM', 'perimeterof', 'polygon', 

414 'scalar', 'simplify2', 'simplifyRDPm', 'simplifyVWm', 

415 'tienstra', 'toUtm', 'triAngle4', 

416 'unsign0', 'unStr', 'utmZoneBand2'), 

417 deprecated_nvector=_a('LatLonNvectorBase', 'Nvector', 'sumOf', 'NorthPole', 'SouthPole'),) 

418 

419 

420class _ALL_MODS(_internals._MODS_Base): 

421 '''(INTERNAL) Memoized import of any L{pygeodesy} module. 

422 ''' 

423 def __getattr__(self, name): 

424 '''Get a C{pygeodesy} module or attribute by B{C{name}}. 

425 

426 @arg name: Un/qualified module or qualified attribute name (C{str}). 

427 

428 @raise ImportError: Importing module B{C{name}} failed. 

429 

430 @raise AttributeError: No attribute named B{C{name}}. 

431 ''' 

432 try: 

433 v = _lazy_dict[name] # package.__dict__ 

434 except KeyError: 

435 v = _lazy_module(name) # package.__getattr__ 

436 if _tailof(typename(v)) != name: 

437 try: 

438 v = getattr(v, _tailof(name)) 

439 except AttributeError: 

440 pass # XXX LazyAttributeError? 

441 return v 

442 

443 def getattr(self, name, *attr_dflt): # , parent=_pygeodesy_ 

444 '''Get an attribute of/or a C{pygeodesy} module. 

445 

446 @arg name: Un/qualified module name (C{str}). 

447 @arg attr_dflt: Optional attribute name (C{str}) and 

448 optional default value (any C{type}). 

449 

450 @return: The C{pygeodesy} module's attribute value. 

451 

452 @raise ImportError: Importing module B{C{name}} failed. 

453 

454 @raise AttributeError: No attribute named B{C{attr}}. 

455 ''' 

456 v = self.getmodule(name) 

457 if attr_dflt: 

458 v = getattr(v, *attr_dflt) 

459 return v 

460 

461 def getmodule(self, name, parent=_pygeodesy_): 

462 '''Get a C{pygeodesy} module or the C{__main__}. 

463 

464 @arg name: Un/qualified module name (C{str}). 

465 

466 @return: The C{pygeodesy} module. 

467 

468 @raise ImportError: Importing module B{C{name}} failed. 

469 ''' 

470 if _headof(name) != parent and name != _DMAIN_: 

471 name = _DOT_(parent, name) 

472 try: 

473 return _sys.modules[name] 

474 except KeyError: 

475 return _getmodule(name, parent) 

476 

477 def imported(self, name): 

478 '''Return module or package C{name} if already imported. 

479 ''' 

480 return _sys.modules.get(name, None) 

481 

482 def into(self, **mod_DNAME): 

483 '''Deferred import of module C{mod} into module C{_DNAME_} 

484 and overwrite C{_DNAME_._mod} to module C{mod}, I{once} 

485 at the first access of an attribute of module C{mod}. 

486 ''' 

487 # assert len(mod_DNAME) == 1 

488 # mod, dun = mod_DNAME.popitem() 

489 

490 class _Into(object): 

491 

492 def __getattr__(unused, name): 

493 m = _getmodinto(mod_DNAME, _Into) 

494 return getattr(m, name) 

495 

496 return _Into() 

497 

498# @_Property_RO 

499# def _isBoolean(self): 

500# '''(INTERNAL) Get function C(.booleans.isBoolean}, I{once}. 

501# ''' 

502# return self.booleans.isBoolean 

503 

504 def items(self): # no module named 'items' 

505 '''Yield the modules imported so far. 

506 ''' 

507 for n, m in _sys.modules.items(): 

508 if _headof(n) == _pygeodesy_: 

509 yield n, m 

510 

511_internals._MODS = _ALL_MODS = _ALL_MODS() # PYCHOK singleton 

512 

513__all__ = _ALL_LAZY.lazily 

514__version__ = '25.09.09' 

515 

516 

517def _ALL_OTHER(*objs): 

518 '''(INTERNAL) Get class and function B{C{objs}} for __all__. 

519 ''' 

520 def _interned(o): # intern'd base name 

521 n = _tailof(typename(o)) 

522 i = NN(_UNDER_, n, _UNDER_) # intern'd 

523 return getattr(_interns, i, n) 

524 

525 return tuple(map(_interned, objs)) # map2 

526 

527 

528if _FOR_DOCS: # PYCHOK no cover 

529 _ALL_DOCS = _ALL_OTHER 

530 # (INTERNAL) Only export B{C{objs.__name__}} when making the 

531 # docs to force C{epydoc} to include certain classes, methods, 

532 # functions and other names in the documentation. Using the 

533 # C{epydoc --private ...} command line option tends to include 

534 # too much internal documentation. 

535else: 

536 def _ALL_DOCS(*unused): 

537 return () 

538 

539 

540def _all_deprecates(): 

541 '''(INTERNAL) Build C{dict} of all deprecated imports and attributes. 

542 ''' 

543 D = _ALL_DEPRECATES 

544 if not D: 

545 _ALL_DEPRECATED.fill_D(D, _all_deprecates) # see _all_imports() 

546 return D 

547 

548_ALL_DEPRECATES = _Dict() # PYCHOK _ALL_DEPRECATED.imports() 

549 

550 

551def _all_enums(): 

552 '''(INTERNAL) Yield all C{(mod_, tuple)} pairs for C{__init__._all}. 

553 ''' 

554 # assert _init__all__ 

555 for mod_t in _ALL_LAZY.enums(): 

556 yield mod_t 

557 if _FOR_DOCS: 

558 for mod_t in _ALL_DEPRECATED.enums(): 

559 yield mod_t 

560 

561 

562def _all_imports(): 

563 '''(INTERNAL) Build C{dict} of all lazy imports. 

564 ''' 

565 # imports naming conventions stored below - [<key>] = <from>: 

566 # import <module> - [<module>] = <module> 

567 # from <module> import <attr> - [<attr>] = <module> 

568 # from pygeodesy import <attr> - [<attr>] = <attr> 

569 # from <module> import <attr> as <name> - [<name>] = <module>.<attr>. 

570 D = _ALL_IMPORTS 

571 if not D: 

572 _ALL_LAZY.fill_D(D, _all_imports) # see _all_deprecates() 

573 return D 

574 

575_ALL_IMPORTS = _Dict() # PYCHOK _ALL_LAZY.imports() 

576 

577 

578def _all_missing2(_all_): 

579 '''(INTERNAL) Get diffs between pygeodesy.__all__ and lazily._all_imports. 

580 ''' 

581 def _diff(one, two): 

582 return tuple(sorted(a for a in one if a not in two)) 

583 

584 _alzy = _Dict((a, a) for a in _ALL_INIT) 

585 _alzy.update(_all_imports()) # without _all_backups! 

586 return ((_DOT_(_lazily_, _all_imports.__name__), _diff(_all_, _alzy)), 

587 (_DOT_(_pygeodesy_, _DALL_), _diff(_alzy.keys(), _all_))) 

588 

589 

590def _getattras(attr_as): # test/testDeprecated 

591 '''(INTERNAL) Get the C{"as name"} or C{"name"} of a lazy entry. 

592 ''' 

593 a_, _, as_ = attr_as.partition(_asSPACED_) 

594 return as_ or a_.rstrip(_DOT_) 

595 

596 

597def _getmodattr(m, name, mod=_pygeodesy_): 

598 '''(INTERNAL) Get attr C{m.name}. 

599 ''' 

600 try: 

601 return getattr(m, name) 

602 except AttributeError: 

603 name = _DOT_(typename(m, mod), name) 

604 # <https://GitHub.com/mrJean1/PyGeodesy/issues/76> 

605 raise LazyAttributeError(_no_(_attribute_), txt=name) 

606 

607 

608def _getmodinto(mod_DNAME, *Intos): 

609 '''(INTERNAL) Core of C{_ALL_MODS.into}. 

610 ''' 

611 _MODS = _ALL_MODS 

612 mod, dun = _MODS.errors._xkwds_item2(mod_DNAME) 

613 _mod = _UNDER_(NN, mod) 

614 d = _MODS.getmodule(dun) # '__main__' OK 

615 i = _getmodattr(d, _mod, dun) 

616 assert isinstance(i, Intos) 

617 m = _MODS.getmodule(mod) 

618 setattr(d, _mod, m) # overwrite C{d._mod} 

619 if isLazy > 1: 

620 t = _SPACE_(_HASH_, _imported_, m.__name__) # typename(m) 

621 _hash_imported(t, _MODS.into.__name__) 

622 assert getattr(d, _mod, None) is m 

623 return m 

624 

625 

626def _getmodule(name, *parent): 

627 '''(INTERNAL) Wrapper for C{import_module}. 

628 ''' 

629 try: 

630 return import_module(name, parent) 

631 except ImportError: 

632 # <https://GitHub.com/mrJean1/PyGeodesy/issues/76> 

633 raise LazyImportError(_no_(_module_), txt=name) 

634 

635 

636def _hash_imported(t, by_into, up=3): 

637 '''(INTERNAL) Helper for C{_lazy_import2} and C{_ALL_MODS.into}. 

638 ''' 

639 if isLazy > 2: 

640 try: # see C{internals._caller3} 

641 _, f, s = _caller3(up) 

642 t = _SPACE_(t, by_into, f, _line_, s) 

643 except ValueError: 

644 pass 

645 printf(t) # XXX print 

646 

647 

648# def _lazy_attributes(DUNDER_name): 

649# '''(INTERNAL) Return a function to C{B{__name__}.__getattr__(attr)} 

650# on lazily imported modules and sub-modules. 

651# ''' 

652# if _unlazy: 

653# raise AssertionError(_COMMASPACE_(DUNDER_name, _not_(_DEPRECATED_))) 

654# 

655# def _getattr(attr, *dflt): 

656# try: # a module name 

657# return _ALL_MODS.getmodule(attr) 

658# except (AttributeError, ImportError): 

659# return _ALL_MODS.getattr(DUNDER_name, attr, *dflt) 

660# 

661# return _getattr 

662 

663 

664_lazy_dict = {} # PYCHOK overwritten by _lazy_import2 

665 

666 

667def _lazy_import2(pack): # MCCABE 14 

668 '''Check for and set up C{lazy import}. 

669 

670 @arg pack: The name of the package (C{str}) performing the imports, 

671 to help resolving relative imports, usually C{__package__}. 

672 

673 @return: 2-Tuple C{(package, getattr)} of the importing package for 

674 easy reference within itself and the callable to be set to 

675 C{package.__getattr__}. 

676 

677 @raise LazyAttributeError: The package, module or attribute name is 

678 invalid or does not exist. 

679 

680 @raise LazyImportError: Lazy import not supported or not enabled or 

681 an import failed. 

682 

683 @note: This is I{Brett Cannon}'s function U{modutil.lazy_import 

684 <https://GitHub.com/brettcannon/modutil/blob/master/modutil.py>} 

685 modified to handle the C{__all__} and C{__dir__} attributes and 

686 call C{importlib.import_module(<module>.<name>, ...)} without 

687 causing a C{ModuleNotFoundError}. 

688 

689 @see: The original U{modutil<https://PyPI.org/project/modutil>}, 

690 U{PEP 562<https://www.Python.org/dev/peps/pep-0562>} and the 

691 U{new way<https://Snarky.CA/lazy-importing-in-python-3-7/>}. 

692 ''' 

693 if pack != _pygeodesy_ or _unlazy: # Python 3.7+ # PYCHOK no cover 

694 t = _DOT_(pack, typename(_lazy_import2)) 

695 raise LazyImportError(_no_(t), txt=_versions()) 

696 

697 package, parent = _lazy_init2(pack) # _pygeodesy_ 

698 

699 _DPACKAGE_ = '__package__' 

700 _lazily_imported_ = _SPACE_(_HASH_, _lazily_, _imported_, parent) 

701 

702 sub_packages = set((parent, NN) + tuple( 

703 _DOT_(parent, s) for s in _SUB_PACKAGES)) 

704 imports = _all_imports() 

705 deprecates = _all_deprecates() 

706 

707 def __getattr__(name): # __getattr__ only for Python 3.7+ 

708 # only called once for each undefined pygeodesy attribute 

709 mod = imports.get(name, NN) or deprecates.get(name, NN) 

710 if mod: 

711 # importlib.import_module() implicitly sets sub-modules 

712 # on this module as appropriate for direct imports (see 

713 # note in the _lazy_import2.__doc__ above). 

714 if mod.endswith(_DOT_): # import mod[.attr] as name 

715 mod, _, attr = mod[:-1].rpartition(_DOT_) 

716 else: # from mod import name 

717 attr = name 

718 v = _getmodule(_DOT_(pack, mod), parent) 

719 t = getattr(v, _DPACKAGE_, None) 

720 if t not in sub_packages: # invalid module package 

721 raise LazyImportError(_DOT_(mod, _DPACKAGE_), t) 

722 if attr: # get mod.attr 

723 v = _getmodattr(v, attr, mod) 

724 

725 elif name in (_DALL_,): # XXX _Ddir_, _Dmembers_? 

726 v = _ALL_INIT + tuple(imports.keys()) 

727 else: # PYCHOK no cover 

728 t = _no_(_module_, _or_, _attribute_) 

729 # <https://GitHub.com/mrJean1/PyGeodesy/issues/76> 

730 raise LazyAttributeError(t, txt=_DOT_(parent, name)) 

731 

732 setattr(package, name, v) # package.__dict__[name] = val 

733 if isLazy > 1: 

734 t = _DOT_(_lazily_imported_, name) 

735 if mod and _tailof(mod) != name: 

736 t = _SPACE_(t, _from_, _DOT_(NN, mod)) 

737 _hash_imported(t, _by_) 

738 

739 return v # __getattr__ 

740 

741 global _lazy_dict, _lazy_module 

742 _lazy_dict = package.__dict__ 

743 _lazy_module = __getattr__ 

744 

745 return package, __getattr__ # _lazy_import2 

746 

747 

748# def _lazy_import_all(Dname): 

749# '''(INTERNAL) Return a function mimicking C{from B{__name__} import *}, 

750# of all items, see .deprecated.__init__ 

751# ''' 

752# if _unlazy: 

753# raise AssertionError(_COMMASPACE_(Dname, _not_(_DEPRECATED_))) 

754# 

755# _getattr = _lazy_attributes(Dname) # __name__.__getattr__ 

756# _import_start = _lazy_import_star(Dname, ALL_=_ALL_IMPORTS) 

757# 

758# def _import_all(attr, *dflt): 

759# return _import_star(Dname) if attr == _DALL_ else \ 

760# _getattr(attr, *dflt) 

761# 

762# return _import_all 

763 

764 

765def _lazy_import_as(DUNDER_name): 

766 '''(INTERNAL) Return a function to C{import B{__name__}.mod as mod} 

767 I{of modules only}, see .deprecated, .rhumb or get an attribute 

768 lazily exported by C{__name__}. 

769 ''' 

770 if _unlazy: 

771 return None 

772 

773 def _import_as(mod): 

774 try: 

775 return _ALL_MODS.getmodule(_DOT_(DUNDER_name, mod)) 

776 except ImportError: 

777 return _lazy_module(mod) 

778 

779 return _import_as 

780 

781 

782# def _lazy_import_star(DUNDER_name, ALL_=_ALL_DEPRECATES): 

783# '''(INTERNAL) Return a function to mimick C{from B{__name__} import *}, 

784# of all DEPRECATED items, see .deprecated, .testDeprecated 

785# ''' 

786# if _unlazy: 

787# raise AssertionError(_COMMASPACE_(DUNDER_name, _not_(_DEPRECATED_))) 

788# 

789# def _import_star(_into_): 

790# '''Do C{from B{__name__} import *} inside module C{B{__into__}}. 

791# ''' 

792# d = dict() 

793# nm = _tailof(DUNDER_name) 

794# _g = _ALL_MODS.getattr # pygeodesy.__getattr__ 

795# for a, m in ALL_.items(): 

796# if _headof(m) == nm: 

797# try: 

798# d[a] = _g(m, a) 

799# except (AttributeError, ImportError): 

800# pass 

801# _sys.modules[_into_].__dict__.update(d) 

802# return d.keys() # imported names 

803# 

804# return _import_star 

805 

806 

807def _lazy_init2(pack): 

808 '''(INTERNAL) Initialize lazy import and set globals C{isLazy} and C{_unLazy0}. 

809 

810 @arg pack: The name of the package (C{str}) performing the imports, 

811 to resolve relative imports, usually C{__package__}. 

812 

813 @return: 2-Tuple C{(package, parent)} with the importing C{package} 

814 for easy reference within itself and its name aka the 

815 C(package)'s C{parent}, same as B{C{pack}}. 

816 

817 @raise LazyImportError: Lazy import not supported or not enabled, 

818 an import failed or the package name is 

819 invalid or does not exist. 

820 

821 @note: Global C{isLazy} is set accordingly. 

822 ''' 

823 global isLazy, _unLazy0 

824 

825 E = _internals._PYGEODESY_ENV('LAZY_IMPORT') 

826 z = _internals._getenv(E, _interns._1_) # 1 default on 3.7+ 

827 z = z.strip() # like PYTHONVERBOSE et.al. 

828 isLazy = int(z) if z.isdigit() else (1 if z else 0) 

829 

830 _unLazy0 = _unlazy or not isLazy # pre-3.7 or w/o lazy import 

831 

832 if isLazy < 1: # invalid, not enabled 

833 raise LazyImportError(E, repr(z), txt_not_='enabled') 

834 if _sys.flags.verbose: # PYCHOK no cover 

835 isLazy += 1 

836 

837 try: # to initialize in Python 3+ 

838 package = import_module(pack) 

839 parent = package.__spec__.parent # __spec__ only in Python 3.7+ 

840 if parent != pack: # assert 

841 t = _COMMASPACE_(parent, _not_(pack)) # PYCHOK no cover 

842 raise AttributeError(_EQUALSPACED_('parent', t)) 

843 

844 except (AttributeError, ImportError) as x: 

845 isLazy = False # failed 

846 z = typename(_lazy_init2) 

847 raise LazyImportError(z, pack, cause=x) 

848 

849 return package, parent 

850 

851 

852def _lazy_module(name): # overwritten by _lazy_import2 

853 '''(INTERNAL) Get or import a C{pygeodesy} module. 

854 ''' 

855 try: # most likely ... module has been imported 

856 m = _ALL_MODS.getmodule(name) 

857 except (AttributeError, ImportError) as x: 

858 raise LazyImportError(name, cause=x) 

859 _lazy_dict[name] = m # cache 

860 return m 

861 

862 

863# def _lazy_subs(__name__, force=_FOR_DOCS, over=False): 

864# '''(INTERNAL) Return the names of a __name__ package's sub-packages 

865# and update the package's C{__dict__} accordingly. 

866# ''' 

867# sm = dict() 

868# if force and __name__ != _DMAIN_: 

869# nm = _tailof(__name__) 

870# _a = _ALL_MODS.getattr 

871# _m = _ALL_MODS.getmodule 

872# d = _a(__name__, _DDICT_, {}) 

873# for n in _a(__name__, _DALL_, ()): 

874# try: # n is a class name, get its mod name 

875# m = _a(__name__, n).__module__ 

876# n, s = m.split(_DOT_)[-2:] 

877# if n == nm and s not in sm: 

878# m = _m(m) # == import m as s 

879# sm[s] = m if over else d.get(s, m) 

880# except (AttributeError, ImportError, ValueError) as x: 

881# pass 

882# d.update(sm) 

883# 

884# return _ALL_OTHER(*sm.values()) 

885 

886 

887if __name__ == _DMAIN_: 

888 

889 def _main(): 

890 from timeit import timeit 

891 

892 def t1(): 

893 from pygeodesy.trf import RefFrame 

894 return RefFrame 

895 

896 def t2(): 

897 return _ALL_MODS.trf.RefFrame 

898 

899 assert t1() is t2() # prime each 

900 

901 t1 = timeit(t1, number=1000000) 

902 t2 = timeit(t2, number=1000000) 

903 A = typename(_ALL_MODS) 

904 v = _versions() 

905 printf('%.6f import vs %.6f %s: %.2fX, %s', t1, t2, A, (t1 / t2), v) 

906 

907 _main() 

908 

909# % python3.13 -W ignore -m pygeodesy.lazily 

910# 0.054235 import vs 0.052469 _ALL_MODS: 1.03X, pygeodesy 25.4.24 Python 3.13.3 64bit arm64 macOS 15.4 

911 

912# % python2 -m pygeodesy.lazily 

913# 0.653715 import vs 0.321318 _ALL_MODS: 2.03X, pygeodesy 25.4.24 Python 2.7.18 64bit arm64_x86_64 macOS 10.16 

914 

915# % python3.13 -W ignore -m pygeodesy.lazily 

916# 0.106602 import vs 0.078136 _ALL_MODS: 1.36X, pygeodesy 24.10.24 Python 3.13.0 64bit arm64 macOS 14.6.1 

917 

918# % python3.12 -W ignore -m pygeodesy.lazily 

919# 0.138844 import vs 0.080458 _ALL_MODS: 1.73X, pygeodesy 24.10.24 Python 3.12.7 64bit arm64 macOS 14.6.1 

920 

921# % python3.11 -W ignore -m pygeodesy.lazily 

922# 0.387520 import vs 0.254229 _ALL_MODS: 1.52X, pygeodesy 24.10.24 Python 3.11.5 64bit arm64 macOS 14.6.1 

923 

924# % python3.10 -W ignore -m pygeodesy.lazily 

925# 0.371269 import vs 0.272897 _ALL_MODS: 1.36X, pygeodesy 24.10.24 Python 3.10.8 64bit arm64 macOS 14.6.1 

926 

927# % python3.8 -W ignore -m pygeodesy.lazily 

928# 0.555572 import vs 0.370304 _ALL_MODS: 1.50X, pygeodesy 24.10.24 Python 3.8.10 64bit arm64_x86_64 macOS 10.16 

929 

930# % python2 -m pygeodesy.lazily 

931# 1.160292 import vs 0.490279 _ALL_MODS: 2.37X, pygeodesy 24.10.24 Python 2.7.18 64bit arm64_x86_64 macOS 10.16 

932 

933# **) MIT License 

934# 

935# Copyright (C) 2018-2025 -- mrJean1 at Gmail -- All Rights Reserved. 

936# 

937# Permission is hereby granted, free of charge, to any person obtaining a 

938# copy of this software and associated documentation files (the "Software"), 

939# to deal in the Software without restriction, including without limitation 

940# the rights to use, copy, modify, merge, publish, distribute, sublicense, 

941# and/or sell copies of the Software, and to permit persons to whom the 

942# Software is furnished to do so, subject to the following conditions: 

943# 

944# The above copyright notice and this permission notice shall be included 

945# in all copies or substantial portions of the Software. 

946# 

947# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 

948# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

949# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 

950# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 

951# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 

952# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 

953# OTHER DEALINGS IN THE SOFTWARE.