Coverage for pygeodesy/lazily.py: 93%

209 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2024-07-10 09:25 -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, _xkwds_item2 # _ALL_MODS 

33from pygeodesy.internals import _caller3, _dunder_nameof, _dunder_ismain, \ 

34 _headof, _osversion2, printf, _Pythonarchine, \ 

35 _tailof # _Property_RO 

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

37 _doesn_t_exist_, _DOT_, _EQUALSPACED_, _from_, \ 

38 _HASH_, _immutable_, _line_, _module_, _no_, _not_, \ 

39 _or_, _pygeodesy_abspath_, _pygeodesy_, _SPACE_, \ 

40 _SUB_PACKAGES, _UNDER_, _version_, _sys, \ 

41 _intern # function 

42# from pygeodesy.streprs import unstr # _ALL_MODS 

43 

44try: 

45 from importlib import import_module 

46except ImportError as x: # Python 2.6- 

47 raise ImportError(_COLONSPACE_(_Pythonarchine(sep=_SPACE_), x)) 

48from os import getenv as _getenv 

49# import sys as _sys # from .interns 

50 

51__as__ = ' as ' 

52_dunder_all_ = '__all__' # in .__main__ 

53_enabled_ = 'enabled' 

54_FOR_DOCS = _getenv('PYGEODESY_FOR_DOCS', NN) # for epydoc ... 

55_i0 = () # PYCHOK empty tuple 

56_init__all__ = _FOR_DOCS or _getenv('PYGEODESY_INIT__ALL__', _dunder_all_) == _dunder_all_ # PYCHOK exported 

57_lazily_ = 'lazily' 

58_lazily_imported_ = _SPACE_(_HASH_, _lazily_, 'imported') 

59_PYGEODESY_GEOCONVERT_ = 'PYGEODESY_GEOCONVERT' # PYCHOK .mgrs, test.bases 

60_PYGEODESY_GEODSOLVE_ = 'PYGEODESY_GEODSOLVE' # PYCHOK .geodsolve, test.bases 

61_PYGEODESY_INTERSECTTOOL_ = 'PYGEODESY_INTERSECTTOOL' # PYCHOK .intersectool, test.bases 

62_PYGEODESY_LAZY_IMPORT_ = 'PYGEODESY_LAZY_IMPORT' 

63_PYGEODESY_RHUMBSOLVE_ = 'PYGEODESY_RHUMBSOLVE' # PYCHOK .rhumb.solve, test.bases 

64_PYTHON_X_DEV = getattr(_sys, '_xoptions', {}).get('dev', # Python 3.2+ 

65 _getenv('PYTHONDEVMODE', NN)) # PYCHOK exported 

66_sys_version_info2 = _sys.version_info[:2] # in .basics, .fmath, ... 

67_unlazy = _unLazy0 = _isfrozen or _sys_version_info2 < (3, 7) # PYCHOK mod.__getattr__ 3.7+ 

68_WARNINGS_X_DEV = _getenv('PYGEODESY_WARNINGS', NN) and ( 

69 _PYTHON_X_DEV or bool(_sys.warnoptions)) # PYCHOK .props 

70# @module_property[_RO?] <https://GitHub.com/jtushman/proxy_tools/> 

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

72 

73 

74class LazyAttributeError(AttributeError): 

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

76 ''' 

77 def __init__(self, *name_value, **txt): 

78 _ALL_MODS.errors._error_init(AttributeError, self, name_value, **txt) 

79 

80 

81class LazyImportError(ImportError): 

82 '''Raised if C{lazy import} is not supported, disabled or failed some other way. 

83 ''' 

84 def __init__(self, *name_value, **txt): 

85 _ALL_MODS.errors._error_init(ImportError, self, name_value, **txt) 

86 

87 

88class _Dict(dict): 

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

90 ''' 

91 _name = NN 

92 

93 def __getattr__(self, attr): 

94 try: 

95 return self[attr] 

96 except KeyError: 

97 return dict.__getattr__(self, attr) 

98 

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

100# if attr in self: 

101# self[attr] = value 

102# else: 

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

104 

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

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

107 

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

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

110 ''' 

111 if name in self: 

112 sub = self[name] # duplicate OK 

113 if sub != mod_ and sub not in subs: # PYCHOK no cover 

114 t = _DOT_(self._name, name) 

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

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

117 raise AssertionError(t) 

118 else: 

119 self[name] = mod_ 

120 

121 def _NAME(self, which): 

122 self._name = _intern(_dunder_nameof(which).upper()) 

123 

124 

125class _NamedEnum_RO(dict): 

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

127 ''' 

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

129 

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

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

132 

133 def __getattr__(self, attr): 

134 try: 

135 return self[attr] 

136 except KeyError: 

137 t = self._DOT_(attr) 

138 raise LazyAttributeError(t, txt=_doesn_t_exist_) 

139 

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

141 t = _EQUALSPACED_(self._DOT_(attr), repr(value)) 

142 raise LazyAttributeError(_immutable_, txt=t) 

143 

144 def enums(self): 

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

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

147 n = m.replace(_UNDER_, _DOT_) 

148 if n != m: 

149 if m.startswith(_UNDER_): 

150 continue # skip _name= ... 

151 u = m.rstrip(_UNDER_) 

152 if u != m: 

153 u = len(u) 

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

155 yield n, t 

156 

157 def fill_D(self, _D, which): 

158 # Fill C{_Dict _D}. 

159 _D._NAME(which) 

160 _a = _D.add 

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

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

163 for a in t: 

164 a, _, as_ = a.partition(__as__) 

165 if as_: # import attr as attr_ 

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

167 else: 

168 _a(a, m) 

169 return _D 

170 

171 

172def _i(*names): 

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

174 ''' 

175 return tuple(map(_intern, names)) if names else _i0 

176 

177 

178def _ALL_ATTRS(*attrs): 

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

180 ''' 

181 t = () 

182 for attr in attrs: 

183 t += tuple(map(_getattrof, attr)) 

184 return t 

185 

186 

187_ALL_INIT = _i(_pygeodesy_abspath_, _version_) 

188 

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

190_ALL_LAZY = _NamedEnum_RO(_name='_ALL_LAZY', 

191 albers=_i('AlbersEqualArea', 'AlbersEqualArea2', 'AlbersEqualArea4', 

192 'AlbersEqualAreaCylindrical', 'AlbersEqualAreaNorth', 'AlbersEqualAreaSouth', 

193 'AlbersError', 'Albers7Tuple'), 

194 auxilats=_i(), # module only 

195 azimuthal=_i('AzimuthalError', 'Azimuthal7Tuple', 

196 'Equidistant', 'EquidistantExact', 'EquidistantGeodSolve', 'EquidistantKarney', 

197 'Gnomonic', 'GnomonicExact', 'GnomonicGeodSolve', 'GnomonicKarney', 

198 'LambertEqualArea', 'Orthographic', 'Stereographic', 

199 'equidistant', 'gnomonic'), 

200 basics=_i('clips', 'copysign0', 'copytype', 'halfs2', 

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

202 'isidentifier', 'isinstanceof', 'isint', 'isiterable', 'isiterablen', 'iskeyword', 

203 'isLatLon', 'islistuple', 'isNvector', 'isodd', 'isscalar', 'issequence', 'isstr', 

204 'issubclassof', 'itemsorted', 

205 'len2', 'map1', 'map2', 'neg', 'neg_', 

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

207 booleans=_i('BooleanFHP', 'BooleanGH', 'LatLonFHP', 'LatLonGH', 

208 'isBoolean'), 

209 cartesianBase=_i('RadiusThetaPhi3Tuple', 'rtp2xyz', 'rtp2xyz_', 'xyz2rtp', 'xyz2rtp_'), 

210 clipy=_i('ClipCS4Tuple', 'ClipFHP4Tuple', 'ClipGH4Tuple', 'ClipLB6Tuple', 'ClipSH3Tuple', 

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

212 css=_i('CassiniSoldner', 'Css', 'CSSError', 'toCss', 

213 'EasNorAziRk4Tuple', 'EasNorAziRkEqu6Tuple', 'LatLonAziRk4Tuple'), 

214 constants=_i('DIG', 'EPS', 'EPS0', 'EPS02', 'EPS1', 'EPS2', 'EPS4', 'EPS_2', 

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

216 'PI', 'PI2', 'PI_2', 'PI3', 'PI_3', 'PI3_2', 'PI4', 'PI_4', 

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

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

219 'isnan', 'isnear0', 'isnear1', 'isnear90', 'isneg0', 'isninf', 'isnon0', 

220 'remainder'), 

221 datums=_i('Datum', 'Datums', 'Transform', 'Transforms'), 

222# deprecated=_i(), # module only 

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

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

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

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

227 'bearingDMS', 'clipDegrees', 'clipRadians', 'compassDMS', 'compassPoint', 

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

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

230 ecef=_i('EcefError', 'EcefFarrell21', 'EcefFarrell22', 'EcefKarney', 'EcefMatrix', 

231 'EcefSudano', 'Ecef9Tuple', 'EcefVeness', 'EcefYou'), 

232 elevations=_i('Elevation2Tuple', 'GeoidHeight2Tuple', 

233 'elevation2', 'geoidHeight2'), 

234 ellipsoidalBase=_i(), # module only 

235 ellipsoidalBaseDI=_i(), # module only 

236 ellipsoidalExact=_i(), # module only 

237 ellipsoidalGeodSolve=_i(), # module only 

238 ellipsoidalKarney=_i(), # module only 

239 ellipsoidalNvector=_i(), # module only 

240 ellipsoidalVincenty=_i('VincentyError',), # nothing else 

241 ellipsoids=_i('a_f2Tuple', 'Circle4Tuple', 'Curvature2Tuple', 

242 'Ellipsoid', 'Ellipsoid2', 'Ellipsoids', 

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

244 'a_f2b', 'a_f_2b', 'b_f2a', 'b_f_2a', 

245 'e2f', 'e22f', 

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

247 elliptic=_i('Elliptic', 'EllipticError', 'Elliptic3Tuple'), 

248 epsg=_i('Epsg', 'EPSGError'), 

249 errors=_i('AuxError', 'ClipError', 'CrossError', 'GeodesicError', 'IntersectionError', 

250 'NumPyError', 'LenError', 'LimitError', 'MGRSError', 

251 'ParseError', 'PointsError', 'RangeError', 'RhumbError', 

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

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

254 etm=_i('Etm', 'ETMError', 'ExactTransverseMercator', 

255 'parseETM5', 'toEtm8'), 

256 fmath=_i('Fdot', 'Fhorner', 'Fhypot', 'Fpolynomial', 'Fpowers', 'Fcbrt', 'Froot', 'Fsqrt', 

257 'bqrt', 'cbrt', 'cbrt2', 'euclid', 'euclid_', 

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

259 'fdot', 'fdot3', 'fmean', 'fmean_', 'fhorner', 'fidw', 'fpolynomial', 

260 'fpowers', 'fprod', 'frandoms', 'frange', 'freduce', 'fremainder', 

261 'hypot', 'hypot_', 'hypot1', 'hypot2', 'hypot2_', 

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

263 formy=_i('Radical2Tuple', 

264 'antipode', 'antipode_', 'bearing', 'bearing_', 

265 'compassAngle', 'cosineForsytheAndoyerLambert', 'cosineForsytheAndoyerLambert_', 

266 'cosineAndoyerLambert', 'cosineAndoyerLambert_', 'cosineLaw', 'cosineLaw_', 

267 'equirectangular', 'equirectangular4', 'euclidean', 'euclidean_', 

268 'excessAbc_', 'excessCagnoli_', 'excessGirard_', 'excessLHuilier_', 

269 'excessKarney', 'excessKarney_', 'excessQuad', 'excessQuad_', 

270 'flatLocal', 'flatLocal_', 'flatPolar', 'flatPolar_', 

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

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

273 'latlon2n_xyz', 'normal', 'normal_', 'n_xyz2latlon', 'n_xyz2philam', 

274 'opposing', 'opposing_', 'philam2n_xyz', 'radical2', 

275 'thomas', 'thomas_', 'vincentys', 'vincentys_'), 

276 frechet=_i('Frechet', 'FrechetDegrees', 'FrechetError', 'FrechetRadians', 

277 'FrechetCosineAndoyerLambert', 'FrechetCosineForsytheAndoyerLambert', 

278 'FrechetCosineLaw', 'FrechetDistanceTo', 'FrechetEquirectangular', 

279 'FrechetEuclidean', 'FrechetExact', 'FrechetFlatLocal', 'FrechetFlatPolar', 

280 'FrechetHaversine', 'FrechetHubeny', 'FrechetKarney', 'FrechetThomas', 

281 'FrechetVincentys', 'Frechet6Tuple', 

282 'frechet_'), 

283 fstats=_i('Fcook', 'Flinear', 'Fwelford'), 

284 fsums=_i('Fsum', 'DivMod2Tuple', 'Fsum2Tuple', 'ResidualError', 

285 'fsum', 'fsum_', 'fsumf_', 'fsum1', 'fsum1_', 'fsum1f_'), 

286 gars=_i('Garef', 'GARSError'), 

287 geodesici=_i('Intersectool', 'Intersectool5Tuple', 'Middle5Tuple', 

288 'Intersector', 'Intersector5Tuple', 'XDict'), 

289 geodesicw=_i('Geodesic', 'GeodesicLine', 'Geodesic_WGS84'), 

290 geodesicx=_i('gx', 'gxarea', 'gxbases', 'gxline', # modules 

291 'GeodesicAreaExact', 'GeodesicExact', 'GeodesicLineExact', 'PolygonArea'), 

292 geodsolve=_i('GeodesicSolve', 'GeodesicLineSolve', 'GeodSolve12Tuple'), 

293 geohash=_i('Geohash', 'GeohashError', 'Neighbors8Dict', 'Resolutions2Tuple'), 

294 geoids=_i('GeoidError', 'GeoidG2012B', 'GeoidKarney', 'GeoidPGM', 'egmGeoidHeights', 

295 'PGMError', 'GeoidHeight5Tuple'), 

296 hausdorff=_i('Hausdorff', 'HausdorffDegrees', 'HausdorffError', 'HausdorffRadians', 

297 'HausdorffCosineAndoyerLambert', 'HausdorffCosineForsytheAndoyerLambert', 

298 'HausdorffCosineLaw', 'HausdorffDistanceTo', 'HausdorffEquirectangular', 

299 'HausdorffEuclidean', 'HausdorffExact', 'HausdorffFlatLocal', 'HausdorffFlatPolar', 

300 'HausdorffHaversine', 'HausdorffHubeny', 'HausdorffKarney', 'HausdorffThomas', 

301 'HausdorffVincentys', 'Hausdorff6Tuple', 

302 'hausdorff_', 'randomrangenerator'), 

303 heights=_i('HeightCubic', 'HeightError', 

304 'HeightIDWcosineAndoyerLambert', 'HeightIDWcosineForsytheAndoyerLambert', 

305 'HeightIDWcosineLaw', 'HeightIDWdistanceTo', 'HeightIDWequirectangular', 

306 'HeightIDWeuclidean', 'HeightIDWexact', 'HeightIDWflatLocal', 'HeightIDWflatPolar', 

307 'HeightIDWhaversine', 'HeightIDWhubeny', 'HeightIDWkarney', 'HeightIDWthomas', 

308 'HeightIDWvincentys', 'HeightLinear', 'HeightLSQBiSpline', 'HeightSmoothBiSpline'), 

309 internals=_internals.__all__, 

310 interns=_interns.__all__, 

311 iters=_i('LatLon2PsxyIter', 'PointsIter', 'points2', 

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

313 karney=_i('Area3Tuple', 'Caps', 'Direct9Tuple', 'GDict', 'Inverse10Tuple', 'Rhumb8Tuple'), 

314 ktm=_i('KTMError', 'KTransverseMercator'), 

315 latlonBase=_i(), # module only 

316 lazily=_i('LazyAttributeError', 'LazyImportError', 'isLazy'), 

317 lcc=_i('Conic', 'Conics', 'Lcc', 'LCCError', 'toLcc'), 

318 ltp=_i('Attitude', 'AttitudeError', 'ChLV', 'ChLVa', 'ChLVe', 'Frustum', 

319 'LocalCartesian', 'LocalError', 'Ltp', 'tyr3d'), 

320 ltpTuples=_i('Aer', 'Aer4Tuple', 'Attitude4Tuple', 

321 'ChLVEN2Tuple', 'ChLV9Tuple', 'ChLVYX2Tuple', 'ChLVyx2Tuple', 

322 'Enu', 'Enu4Tuple', 'Footprint5Tuple', 'Local9Tuple', 'Los', 

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

324 mgrs=_i('Mgrs', 'parseMGRS', 'toMgrs', 'Mgrs4Tuple', 'Mgrs6Tuple'), 

325 named=_i('ADict', 

326 'callername', 'classname', 'classnaming', 'modulename', 

327 'nameof', 'notImplemented', 'notOverloaded'), 

328 namedTuples=_i('Bearing2Tuple', 'Bounds2Tuple', 'Bounds4Tuple', 

329 'Destination2Tuple', 'Destination3Tuple', 

330 'Distance2Tuple', 'Distance3Tuple', 'Distance4Tuple', 

331 'EasNor2Tuple', 'EasNor3Tuple', 'Forward4Tuple', 'Intersection3Tuple', 

332 'LatLon2Tuple', 'LatLon3Tuple', 'LatLon4Tuple', 

333 'LatLonDatum3Tuple', 'LatLonDatum5Tuple', 

334 'LatLonPrec3Tuple', 'LatLonPrec5Tuple', 

335 'NearestOn2Tuple', 'NearestOn3Tuple', 'NearestOn6Tuple', 'NearestOn8Tuple', 

336 'PhiLam2Tuple', 'PhiLam3Tuple', 'PhiLam4Tuple', 'Point3Tuple', 'Points2Tuple', 

337 'Reverse4Tuple', 'Triangle7Tuple', 'Triangle8Tuple', 'Trilaterate5Tuple', 

338 'UtmUps2Tuple', 'UtmUps5Tuple', 'UtmUps8Tuple', 'UtmUpsLatLon5Tuple', 

339 'Vector2Tuple', 'Vector3Tuple', 'Vector4Tuple'), 

340 nvectorBase=_i('NorthPole', 'SouthPole'), 

341 osgr=_i('Osgr', 'OSGRError', 'parseOSGR', 'toOsgr'), 

342 points=_i('LatLon_', 'LatLon2psxy', 'Numpy2LatLon', 'Shape2Tuple', 'Tuple2LatLon', 

343 'areaOf', 'boundsOf', 'centroidOf', 'fractional', 

344 'isclockwise', 'isconvex', 'isconvex_', 'isenclosedBy', 'ispolar', 

345 'luneOf', 'nearestOn5', 'perimeterOf', 'quadOf'), 

346 props=_i('Property', 'Property_RO', 'property_RO', 'property_doc_', 

347 'deprecated_class', 'deprecated_function', 'deprecated_method', 

348 'deprecated_Property_RO', 'deprecated_property_RO', 'DeprecationWarnings'), 

349 resections=_i('Collins5Tuple', 'ResectionError', 'Survey3Tuple', 'Tienstra7Tuple', 

350 'TriAngle5Tuple', 'TriSide2Tuple', 'TriSide4Tuple', 

351 'cassini', 'collins5', 'pierlot', 'pierlotx', 'tienstra7', 

352 'snellius3', 'wildberger3', 

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

354 rhumb=_i(), # module only 

355 rhumb_aux_=_i('RhumbAux', 'RhumbLineAux'), 

356 rhumb_ekx=_i('Rhumb', 'RhumbLine'), 

357 rhumb_solve=_i('RhumbSolve', 'RhumbLineSolve', 'RhumbSolve7Tuple'), 

358 sphericalBase=_i(), # module only 

359 sphericalNvector=_i(), # module only 

360 sphericalTrigonometry=_i(), # module only 

361 simplify=_i('simplify1', 'simplifyRDP', 'simplifyRDPm', 'simplifyRW', 'simplifyVW', 'simplifyVWm'), 

362 solveBase=_i(), # module only 

363 streprs=_i('anstr', 'attrs', 'enstr2', 'fstr', 'fstrzs', 'hstr', 'instr', 

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

365 trf=_i('RefFrame', 'RefFrames', 'TransformXform', 'TRFXform', 'TRFXform7Tuple', 

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

367 triaxials=_i('BetaOmega2Tuple', 'BetaOmega3Tuple', 'Jacobi2Tuple', 

368 'JacobiConformal', 'JacobiConformalSpherical', 

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

370 units=_i('Band', 'Bearing', 'Bearing_', 'Bool', 

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

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

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

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

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

376 'Radius_', 'Scalar', 'Scalar_', 'Zone'), 

377 unitsBase=_i('Float', 'Int', 'Radius', 'Str'), 

378 ups=_i('Ups', 'UPSError', 'parseUPS5', 'toUps8', 'upsZoneBand5'), 

379 utily=_i('acos1', 'acre2ha', 'acre2m2', 'asin1', 'atan1', 'atan1d', 'atan2b', 'atan2d', 

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

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

382# 'degrees2grades as degrees2gons', 

383 'fathom2m', 'ft2m', 'furlong2m', 

384 'grades', 'grades400', 'grades2degrees', 'grades2radians', 

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

386 'km2m', 'm2chain', 'm2degrees', 'm2fathom', 'm2ft', 'm2furlong', 

387 'm2km', 'm2NM', 'm2radians', 'm2SM', 'm2toise', 'm2yard', 'NM2m', 

388 'radians', 'radiansPI', 'radiansPI2', 'radiansPI_2', 'radians2m', 

389 'sincos2', 'SinCos2', 'sincos2_', 'sincos2d', 'sincos2d_', 'sincostan3', 'SM2m', 

390 'tand', 'tand_', 'tan_2', 'tanPI_2_2', 'toise2m', 'truncate', 

391 'unroll180', 'unrollPI', 

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

393 'yard2m'), 

394 utm=_i('Utm', 'UTMError', 'parseUTM5', 'toUtm8', 'utmZoneBand5'), 

395 utmups=_i('UtmUps', 'UTMUPSError', 'parseUTMUPS5', 'toUtmUps8', 

396 'utmupsValidate', 'utmupsValidateOK', 'utmupsZoneBand5'), 

397 utmupsBase=_i(), # module only 

398 vector2d=_i('Circin6Tuple', 'Circum3Tuple', 'Circum4Tuple', 'Meeus2Tuple', 'Radii11Tuple', 'Soddy4Tuple', 

399 'circin6', 'circum3', 'circum4_', 'meeus2', 'radii11', 'soddy4'), 

400 vector3d=_i('Vector3d', 'intersection3d3', 'iscolinearWith', 'nearestOn', 'nearestOn6', 'parse3d', 

401 'trilaterate2d2', 'trilaterate3d2'), 

402 vector3dBase=_i(), # module only 

403 webmercator=_i('Wm', 'WebMercatorError', 'parseWM', 'toWm', 'EasNorRadius3Tuple'), 

404 wgrs=_i('Georef', 'WGRSError'),) 

405 

406_ALL_DEPRECATED = _NamedEnum_RO(_name='_ALL_DEPRECATED', 

407 deprecated=_i('bases', 'datum', 'nvector', # DEPRECATED modules and ... 

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

409 deprecated_bases=_i('LatLonHeightBase', 'points2'), 

410 deprecated_classes=_i('ClipCS3Tuple', 'EasNorExact4Tuple', 'EcefCartesian', 'Fn_rt', 

411 'HeightIDW', 'HeightIDW2', 'HeightIDW3', 'Helmert7Tuple', 

412 'Lam_', 'LatLonExact4Tuple', 'NearestOn4Tuple', 'Ned3Tuple', 

413 'Phi_', 'RefFrameError', 'Rhumb7Tuple', 'RhumbOrder2Tuple', 

414 'Transform7Tuple', 'TriAngle4Tuple', 'UtmUps4Tuple', 'XDist'), 

415 deprecated_consterns=_i('EPS1_2', 'MANTIS', 'OK'), 

416 deprecated_datum=_i('Curvature2Tuple', 'Datum', 'Ellipsoid', 'Transform', # assert 

417 'Datums', 'Ellipsoids', 'Transforms', 

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

419 deprecated_functions=_i('anStr', 'areaof', 'atand', 'bounds', # most of the DEPRECATED functions, except ... 

420 'clipCS3', 'clipDMS', 'clipStr', 'collins', 'copysign', # ... ellipsoidal, spherical flavors 

421 'decodeEPSG2', 'encodeEPSG', 'enStr2', 'equirectangular_', 'equirectangular3', 

422 'excessAbc', 'excessGirard', 'excessLHuilier', 

423 'false2f', 'falsed2f', 'float0', 'fStr', 'fStrzs', 'hypot3', 

424 'inStr', 'isenclosedby', 'istuplist', 

425 'joined', 'joined_', 'nearestOn3', 'nearestOn4', 

426 'parseUTM', 'perimeterof', 'polygon', 'scalar', 'simplify2', 

427 'tienstra', 'toUtm', 'triAngle4', 

428 'unsign0', 'unStr', 'utmZoneBand2'), 

429 deprecated_nvector=_i('LatLonNvectorBase', 'Nvector', 'sumOf', 'NorthPole', 'SouthPole'),) 

430 

431 

432class _ALL_MODS(_internals._MODS_Base): 

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

434 ''' 

435 def __getattr__(self, name): 

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

437 

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

439 

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

441 

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

443 ''' 

444 try: 

445 v = _lazy_dict[name] # package.__dict__ 

446 except KeyError: 

447 v = _lazy_module(name) # package.__getattr__ 

448 if _tailof(_dunder_nameof(v)) != name: 

449 try: 

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

451 except AttributeError: 

452 pass # XXX LazyAttributeError? 

453 return v 

454 

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

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

457 

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

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

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

461 

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

463 

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

465 

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

467 ''' 

468 v = self.getmodule(name) 

469 if attr_dflt: 

470 v = getattr(v, *attr_dflt) 

471 return v 

472 

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

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

475 

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

477 

478 @return: The C{pygeodesy} module. 

479 

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

481 ''' 

482 if _headof(name) != parent and not _dunder_ismain(name): 

483 name = _DOT_(parent, name) 

484 try: 

485 return _sys.modules[name] 

486 except KeyError: 

487 return _getmodule(name, parent) 

488 

489 def into(self, **mod_dunder_name_): 

490 '''Lazily import module C{mod} into module C{_dunder_name_} 

491 and set C{_dunder_name_._mod} to module C{mod}, I{once}. 

492 ''' 

493 class _Into(object): 

494 

495 def __getattr__(unused, name): 

496 mod, dun = self.errors._xkwds_item2(mod_dunder_name_) 

497 _mod = _UNDER_(NN, mod) 

498 d = self.getmodule(dun) # '__main__' OK 

499 i = _getattribute(d, _mod, dun) 

500 assert isinstance(i, _Into) 

501 m = self.getmodule(mod) 

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

503 return getattr(m, name) 

504 

505 return _Into() 

506 

507# @_Property_RO 

508# def _isBoolean(self): 

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

510# ''' 

511# return self.booleans.isBoolean 

512 

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

514 '''Yield the modules imported so far. 

515 ''' 

516 _hd = _headof 

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

518 if _hd(n) == _pygeodesy_: 

519 yield n, m 

520 

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

522 

523__all__ = _ALL_LAZY.lazily 

524__version__ = '24.07.09' 

525 

526 

527def _ALL_OTHER(*objs): 

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

529 ''' 

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

531 n = _tailof(_dunder_nameof(o)) 

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

533 return getattr(_interns, i, n) 

534 

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

536 

537 

538if _FOR_DOCS: 

539 _ALL_DOCS = _ALL_OTHER 

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

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

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

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

544 # too much internal documentation. 

545else: 

546 def _ALL_DOCS(*unused): 

547 return () 

548 

549 

550def _all_deprecates(): 

551 '''(INTERNAL) Build C{dict} of all deprecated imports. 

552 ''' 

553 _D = _ALL_DEPRECATES 

554 if not _D: 

555 _ALL_DEPRECATED.fill_D(_D, _all_deprecates) # see _all_imports() 

556 return _D 

557 

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

559 

560 

561def _all_imports(): 

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

563 ''' 

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

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

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

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

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

569 _D = _ALL_IMPORTS 

570 if not _D: 

571 _ALL_LAZY.fill_D(_D, _all_imports) # see _all_deprecates() 

572 return _D 

573 

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

575 

576 

577def _all_missing2(_all_): 

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

579 ''' 

580 def _diff(one, two): 

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

582 

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

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

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

586 (_DOT_(_pygeodesy_, _dunder_all_), _diff(_alzy.keys(), _all_))) 

587 

588 

589def _getattribute(m, name, mod=_pygeodesy_): 

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

591 ''' 

592 try: 

593 return getattr(m, name) 

594 except AttributeError: 

595 name = _DOT_(mod, name) 

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

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

598 

599 

600def _getattrof(attr_as): # .testDeprecated 

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

602 ''' 

603 a_, _, as_ = attr_as.partition(__as__) 

604 return as_ or a_.rstrip(_DOT_) 

605 

606 

607def _getmodule(name, *parent): 

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

609 ''' 

610 try: 

611 return import_module(name, parent) 

612 except ImportError: 

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

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

615 

616 

617# def _lazy_attributes(_dunder_name_): 

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

619# on lazily imported modules and sub-modules. 

620# ''' 

621# if _unlazy: 

622# raise AssertionError(_COMMASPACE_(_dunder_name_, _not_(_DEPRECATED_))) 

623# 

624# def _getattr(attr, *dflt): 

625# try: # a module name 

626# return _ALL_MODS.getmodule(attr) 

627# except (AttributeError, ImportError): 

628# return _ALL_MODS.getattr(_dunder_name_, attr, *dflt) 

629# 

630# return _getattr 

631 

632 

633_lazy_dict = {} # PYCHOK overwritten by _lazy_import2 

634 

635 

636def _lazy_import2(pack): # MCCABE 14 

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

638 

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

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

641 

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

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

644 C{package.__getattr__}. 

645 

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

647 invalid or does not exist. 

648 

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

650 an import failed. 

651 

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

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

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

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

656 causing a C{ModuleNotFoundError}. 

657 

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

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

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

661 ''' 

662 _DOT_ = _interns._DOT_ 

663 _SPACE_ = _interns._SPACE_ 

664 

665 if pack != _pygeodesy_ or _unlazy: # Python 3.7+ 

666 t = _no_(_DOT_(pack, _dunder_nameof(_lazy_import2))) # PYCHOK no cover 

667 raise LazyImportError(t, txt=_Pythonarchine(sep=_SPACE_)) 

668 

669 package, parent = _lazy_init2(pack) # _pygeodesy_ 

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

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

672 imports = _all_imports() 

673 deprecates = _all_deprecates() 

674 _dunder_package_ = '__package__' 

675 

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

677 # only called once for each undefined pygeodesy attribute 

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

679 if mod: 

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

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

682 # note in the _lazy_import2.__doc__ above). 

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

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

685 else: # from mod import name 

686 attr = name 

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

688 t = getattr(v, _dunder_package_, None) 

689 if t not in sub_packages: # invalid module package 

690 raise LazyImportError(_DOT_(mod, _dunder_package_), t) 

691 if attr: # get mod.attr 

692 v = _getattribute(v, attr, mod) 

693 

694 elif name in (_dunder_all_,): # XXX _dunder_dir_, _dunder_members_? 

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

696 else: # PYCHOK no cover 

697 t = _no_(_module_, _or_, _attribute_) 

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

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

700 

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

702 if isLazy > 1: 

703 t = _SPACE_(_lazily_imported_, _DOT_(parent, name)) 

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

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

706 if isLazy > 2: 

707 try: # see C{_caller3} 

708 _, f, s = _caller3(2) 

709 t = _SPACE_(t, _by_, f, _line_, s) 

710 except ValueError: 

711 pass 

712 printf(t) # XXX print 

713 

714 return v # __getattr__ 

715 

716 global _lazy_dict, _lazy_module 

717 _lazy_dict = package.__dict__ 

718 _lazy_module = __getattr__ 

719 

720 return package, __getattr__ # _lazy_import2 

721 

722 

723# def _lazy_import_all(_dunder_name_): 

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

725# of all items, see .deprecated.__init__ 

726# ''' 

727# if _unlazy: 

728# raise AssertionError(_COMMASPACE_(_dunder_name_, _not_(_DEPRECATED_))) 

729# 

730# _getattr = _lazy_attributes(_dunder_name_) # __name__.__getattr__ 

731# _import_start = _lazy_import_star(_dunder_name_, ALL_=_ALL_IMPORTS) 

732# 

733# def _import_all(attr, *dflt): 

734# return _import_star(_dunder_name_) if attr == _dunder_all_ else \ 

735# _getattr(attr, *dflt) 

736# 

737# return _import_all 

738 

739 

740def _lazy_import_as(_dunder_name_): 

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

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

743 lazily exported by C{__name__}. 

744 ''' 

745 if _unlazy: 

746 return None 

747 

748 def _import_as(mod): 

749 try: 

750 return _ALL_MODS.getmodule(_DOT_(_dunder_name_, mod)) 

751 except ImportError: 

752 return _lazy_module(mod) 

753 

754 return _import_as 

755 

756 

757# def _lazy_import_star(_dunder_name_, ALL_=_ALL_DEPRECATES): 

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

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

760# ''' 

761# if _unlazy: 

762# raise AssertionError(_COMMASPACE_(_dunder_name_, _not_(_DEPRECATED_))) 

763# 

764# def _import_star(_into_): 

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

766# ''' 

767# d = dict() 

768# nm = _tailof(_dunder_name_) 

769# _g = _ALL_MODS.getattr # pygeodesy.__getattr__ 

770# _h = _headof 

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

772# if _h(m) == nm: 

773# try: 

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

775# except (AttributeError, ImportError): 

776# pass 

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

778# return d.keys() # imported names 

779# 

780# return _import_star 

781 

782 

783def _lazy_init2(pack): 

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

785 

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

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

788 

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

790 for easy reference within itself and its name aka the 

791 C{parent}, same as B{C{pack}}. 

792 

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

794 an import failed or the package name is 

795 invalid or does not exist. 

796 

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

798 ''' 

799 global isLazy, _unLazy0 

800 

801 z = _getenv(_PYGEODESY_LAZY_IMPORT_, None) 

802 if z is None: # _PYGEODESY_LAZY_IMPORT_ not set 

803 isLazy = 1 # ... but only by default on 3.7 

804 else: 

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

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

807 

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

809 

810 if isLazy < 1: # not enabled 

811 raise LazyImportError(_PYGEODESY_LAZY_IMPORT_, repr(z), txt_not_=_enabled_) 

812 if _getenv('PYTHONVERBOSE', None): # PYCHOK no cover 

813 isLazy += 1 

814 

815 try: # to initialize in Python 3+ 

816 package = import_module(pack) 

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

818 if parent != pack: # assert 

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

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

821 

822 except (AttributeError, ImportError) as x: 

823 isLazy = False # failed 

824 raise LazyImportError(_lazy_init2.__name__, pack, cause=x) 

825 

826 return package, parent 

827 

828 

829def _lazy_module(name): # overwritten by _lazy_import2 

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

831 ''' 

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

833 m = _ALL_MODS.getmodule(name) 

834 except (AttributeError, ImportError) as x: 

835 raise LazyImportError(name, cause=x) 

836 _lazy_dict[name] = m # cache 

837 return m 

838 

839 

840# def _lazy_subs(_dunder_name_, force=_FOR_DOCS, over=False): 

841# '''(INTERNAL) Return the names of a package's sub-packages and 

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

843# ''' 

844# sm = dict() 

845# if force and not _dunder_ismain(_dunder_name_): 

846# nm = _tailof(_dunder_name_) 

847# _a = _ALL_MODS.getattr 

848# _m = _ALL_MODS.getmodule 

849# d = _a(_dunder_name_, _dunder_dict_, {}) 

850# for n in _a(_dunder_name_, _dunder_all_, ()): 

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

852# m = _a(_dunder_name_, n).__module__ 

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

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

855# # like import m as s 

856# m = _m(m) 

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

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

859# pass 

860# d.update(sm) 

861# 

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

863 

864 

865# del _i, _i0 

866 

867# _ = _ALL_MODS.errors # force import pygeodesy.errors 

868 

869if _dunder_ismain(__name__): # PYCHOK no cover 

870 

871 from timeit import timeit 

872 

873 def t1(): 

874 from pygeodesy.trf import RefFrame 

875 return RefFrame 

876 

877 def t2(): 

878 return _ALL_MODS.trf.RefFrame 

879 

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

881 

882 t1 = timeit(t1, number=1000000) 

883 t2 = timeit(t2, number=1000000) 

884 v = _SPACE_.join(_Pythonarchine() + _osversion2()) 

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

886 

887# del t1, t2, timeit, v 

888 

889# python3.12 -W ignore -m pygeodesy.lazily 

890# 0.145177 import vs 0.075402 _ALL_MODS: 1.93X, Python 3.12.3 64bit arm64 macOS 14.4.1 

891 

892# python3.11 -W ignore -m pygeodesy.lazily 

893# 0.381723 import vs 0.251589 _ALL_MODS: 1.52X, Python 3.11.5 64bit arm64 macOS 14.4.1 

894 

895# python3.10 -W ignore -m pygeodesy.lazily 

896# 0.378293 import vs 0.266507 _ALL_MODS: 1.42X, Python 3.10.8 64bit arm64 macOS 14.4.1 

897 

898# python2 -m pygeodesy.lazily 

899# 1.213805 import vs 0.474075 _ALL_MODS: 2.56X, Python 2.7.18 64bit arm64_x86_64 macOS 10.16 

900 

901# **) MIT License 

902# 

903# Copyright (C) 2018-2024 -- mrJean1 at Gmail -- All Rights Reserved. 

904# 

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

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

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

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

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

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

911# 

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

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

914# 

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

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

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

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

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

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

921# OTHER DEALINGS IN THE SOFTWARE.