Coverage for pygeodesy/lazily.py : 93%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
U{lazy_import<https://modutil.ReadTheDocs.io/en/latest/#lazy_import>} from Brett Cannon's U{modutil<https://PyPI.org/project/modutil>}.
C{Lazy import} is I{supported only for U{Python 3.7+ <https://Snarky.CA/lazy-importing-in-python-3-7>}} and is I{enabled by default in U{PyGeodesy 18.11.10+<https://PyPI.org/project/PyGeodesy>} and later}.
To disable C{lazy import}, set environment variable C{PYGEODESY_LAZY_IMPORT} to C{0} or an empty string. Use C{2} or higher to print a message for each lazily imported module and attribute, similar to environment variable C{PYTHONVERBOSE} showing imports. Using C{3} or higher also shows the importing file name and line number.
@note: C{Lazy import} applies only to top-level modules of C{pygeodesy}. A C{lazy import} of a top-level module also loads all sub-modules imported by that top-level module.
@var isLazy: Lazy import setting (C{int} 0, 1, 2 or 3+) from environment variable C{PYGEODESY_LAZY_IMPORT}, or C{None} if C{lazy import} is not supported or not enabled, or C{False} if initializing C{lazy import} failed. '''
# @module_property[_RO?] <https://GitHub.com/jtushman/proxy_tools/>
'''Lazy import is not supported, disabled or failed some other way. '''
'''(INTERNAL) C{Read_Only} enum-like C{dict} sub-class. ''' except KeyError: raise AttributeError("%s.%s doesn't exist" % (self._name, attr)) # PYCHOK expected
raise TypeError('Read_Only %s.%s = %r' % (self._name, attr, value)) # PYCHOK expected
'''(INTERNAL) Only export B{C{names}} when making docs to force C{epydoc} to include classes, methods, functions and other names in the documentation. Using C{epydoc --private ...} tends to include too much private documentation. '''
# __all__ value for most modules, accessible as _ALL_LAZY.<module> bases=(), # module and for backward compatibility only clipy=('clipCS3', 'clipSH', 'clipSH3'), css=('CassiniSoldner', 'Css', 'CSSError', 'toCss'), datum=('R_M', 'R_MA', 'R_MB', 'R_KM', 'R_NM', 'R_SM', 'R_FM', 'R_VM', 'Datum', 'Ellipsoid', 'Transform', 'Datums', 'Ellipsoids', 'Transforms'), deprecated=('HeightIDW', 'HeightIDW2', 'HeightIDW3', 'RefFrameError', # DEPRECATED classes 'areaof', 'bounds', 'decodeEPSG2', 'encodeEPSG', # most of the DEPRECATED functions 'equirectangular3', 'hypot3', 'isenclosedby', 'nearestOn3', 'nearestOn4', 'parseUTM', 'perimeterof', 'polygon', 'simplify2', 'toUtm', 'utmZoneBand2'), dms=('F_D', 'F_DM', 'F_DMS', 'F_DEG', 'F_MIN', 'F_SEC', 'F_RAD', 'F_D_', 'F_DM_', 'F_DMS_', 'F_DEG_', 'F_MIN_', 'F_SEC_', 'F_RAD_', 'F_D__', 'F_DM__', 'F_DMS__', 'F_DEG__', 'F_MIN__', 'F_SEC__', 'F_RAD__', 'S_DEG', 'S_MIN', 'S_SEC', 'S_RAD', 'S_SEP', 'RangeError', 'bearingDMS', 'clipDMS', 'compassDMS', 'compassPoint', 'degDMS', 'latDMS', 'lonDMS', 'normDMS', 'parseDMS', 'parseDMS2', 'parse3llh', 'precision', 'rangerrors', 'toDMS'), ecef=('EcefCartesian', 'EcefError', 'EcefKarney', 'EcefMatrix', 'EcefVeness', 'EcefYou'), elevations=('elevation2', 'geoidHeight2'), ellipsoidalKarney=(), # module only ellipsoidalNvector=(), # module only ellipsoidalVincenty=('VincentyError',), # nothing else elliptic=('Elliptic', 'EllipticError'), epsg=('Epsg', 'EPSGError'), etm=('Etm', 'ETMError', 'ExactTransverseMercator', 'parseETM5', 'toEtm8'), fmath=('EPS', 'EPS_2', 'EPS1', 'EPS1_2', 'INF', 'MANTIS', 'MAX', 'MIN', 'NAN', 'NEG0', # constants 'Fdot', 'Fhorner', 'Fpolynomial', 'Fsum', 'acos1', 'cbrt', 'cbrt2', 'favg', 'fdot', 'fdot3', 'fmean', 'fhorner', 'fidw', 'fpolynomial', 'fpowers', 'fprod', 'frange', 'freduce', 'fStr', 'fStrzs', 'fsum', 'fsum_', 'hypot', 'hypot1', 'hypot_', 'isfinite', 'isinf', 'isint', 'isnan', 'isneg0', 'isscalar', 'len2', 'map1', 'map2', 'scalar', 'sqrt3'), formy=('antipode', 'bearing', 'bearing_', 'compassAngle', 'euclidean', 'euclidean_', 'equirectangular', 'equirectangular_', 'haversine', 'haversine_', 'heightOf', 'horizon', 'isantipode', 'points2', 'vincentys', 'vincentys_'), frechet=('Frechet', 'FrechetDegrees', 'FrechetRadians', 'FrechetError', 'FrechetEquirectangular', 'FrechetEuclidean', 'FrechetHaversine', 'FrechetVincentys', 'fractional', 'frechet_'), gars=('Garef', 'GARSError'), geohash=('Geohash', 'GeohashError'), geoids=('GeoidError', 'GeoidG2012B', 'GeoidKarney', 'GeoidPGM', 'egmGeoidHeights', 'PGMError'), hausdorff=('Hausdorff', 'HausdorffDegrees', 'HausdorffRadians', 'HausdorffError', 'HausdorffEquirectangular', 'HausdorffEuclidean', 'HausdorffHaversine', 'HausdorffKarney', 'HausdorffVincentys', 'hausdorff_', 'randomrangenerator'), heights=('HeightError', 'SciPyError', 'SciPyWarning', 'HeightIDWequirectangular', 'HeightIDWeuclidean', 'HeightIDWhaversine', 'HeightIDWkarney', 'HeightIDWvincentys', 'HeightCubic', 'HeightLinear', 'HeightLSQBiSpline', 'HeightSmoothBiSpline'), lazily=('LazyImportError', 'isLazy'), lcc=('Conic', 'Conics', 'Lcc', 'LCCError', 'toLcc'), mgrs=('Mgrs', 'MGRSError', 'parseMGRS', 'toMgrs'), named=('classname', 'classnaming', 'inStr', 'nameof'), nvector=(), # module and for backward compatibility only osgr=('Osgr', 'OSGRError', 'parseOSGR', 'toOsgr'), points=('LatLon_', 'LatLon2psxy', 'Numpy2LatLon', 'Tuple2LatLon', 'areaOf', 'boundsOf', 'centroidOf', 'isclockwise', 'isconvex', 'isconvex_', 'isenclosedBy', 'ispolar', 'nearestOn5', 'perimeterOf'), sphericalNvector=(), # module only sphericalTrigonometry=(), # module only simplify=('simplify1', 'simplifyRDP', 'simplifyRDPm', 'simplifyRW', 'simplifyVW', 'simplifyVWm'), trf=('RefFrame', 'RefFrames', 'TRFError', 'date2epoch'), ups=('Ups', 'UPSError', 'parseUPS5', 'toUps8', 'upsZoneBand5'), utily=('OK', 'PI', 'PI2', 'PI_2', 'PI_4', 'R_M', 'LimitError', 'anStr', 'clipStr', 'degrees', 'degrees90', 'degrees180', 'degrees360', 'degrees2m', 'enStr2', 'false2f', 'ft2m', 'halfs2', 'isNumpy2', 'isPoints2', 'issequence', 'issubclassof', 'isTuple2', 'iterNumpy2', 'iterNumpy2over', 'limiterrors', 'm2degrees', 'm2ft', 'm2km', 'm2NM', 'm2SM', 'property_RO', 'radians', 'radiansPI', 'radiansPI2', 'radiansPI_2', 'sincos2', 'sincos2d', 'splice', 'tan_2', 'tanPI_2_2', 'unroll180', 'unrollPI', 'unStr', 'wrap90', 'wrap180', 'wrap360', 'wrapPI_2','wrapPI', 'wrapPI2'), utm=('Utm', 'UTMError', 'parseUTM5', 'toUtm8', 'utmZoneBand5'), utmups=('UtmUps', 'UTMUPSError', 'parseUTMUPS5', 'toUtmUps8', 'utmupsValidate', 'utmupsValidateOK', 'utmupsZoneBand5'), vector3d=('CrossError', 'crosserrors', 'VectorError'), # nothing else webmercator=('Wm', 'WebMercatorError', 'parseWM', 'toWm'), wgrs=('Georef', 'WGRSError'))
# DEPRECATED __all__ names overloading those in _ALL_LAZY.deprecated where # the new name is fully backward compatible in signature and return value fmath=('hypot_ as hypot3',), formy=('points2 as polygon',), heights=('HeightIDWequirectangular as HeightIDW2', 'HeightIDWeuclidean as HeightIDW', 'HeightIDWhaversine as HeightIDW3'), points=('areaOf as areaof', 'isenclosedBy as isenclosedby', 'perimeterOf as perimeterof'), simplify=('simplifyRW as simplify2',))
'''(INTERNAL) Build C{dict} of all lazy imports. ''' # imports naming conventions stored below - [<key>] = <from>: # import <module> - [<module>] = <module> # from <module> import <attr> - [<attr>] = <module> # from pygeodesy import <attr> - [<attr>] = <attr> # from <module> import <attr> as <name> - [<name>] = <module>.<attr> raise AssertionError('%s[%r] vs %r' % ('imports', imports[mod], mod)) else:
'''(INTERNAL) Get deltas between pygeodesy.__all__ and lazily._all_imports. ''' ('pygeodesy.__all__', ', '.join(a for a in _alzy if a not in _all_)))
'''(INTERNAL) Override C{dflts} with C{kwds}. '''
'''Check for and set up lazy importing.
@param _package_: The name of the package (C{str}) performing the imports, to help facilitate resolving relative imports.
@return: 2-Tuple (package, getattr) of the importing package for easy reference within itself and the callable to be set to `__getattr__`.
@raise LazyImportError: Lazy import not supported, an import failed or a module name or attribute name is invalid or does not exist.
@note: This is the original function U{modutil.lazy_import <https://GitHub.com/brettcannon/modutil/blob/master/modutil.py>} modified to handle the C{__all__} and C{__dir__} attributes and call C{importlib.import_module(<module>.<name>, ...)} without causing a C{ModuleNotFoundError}.
@see: The original U{modutil<https://PyPi.org/project/modutil>}, U{PEP 562<https://www.Python.org/dev/peps/pep-0562>} and U{Werkzeug<https://GitHub.com/pallets/werkzeug/blob/master/werkzeug/__init__.py>}. ''' global isLazy
raise LazyImportError('no %s.%s for Python %s', _package_, _lazy_import2.__name__, sys.version.split()[0])
isLazy = 1 # on by default on 3.7 else: raise LazyImportError('env %s=%r', 'PYGEODESY_LAZY_IMPORT', z) isLazy += 1
raise AttributeError('parent %r vs %r' % (parent, _package_)) except (AttributeError, ImportError) as x: isLazy = False # failed raise LazyImportError('init failed: %s', x)
else: # no import path names cwdir = ''
# only called once for each undefined pygeodesy attribute # importlib.import_module() implicitly sets sub-modules # on this module as appropriate for direct imports (see # note in the _lazy_import.__doc__ above). raise LazyImportError('no %s %s.%s', 'module', parent, mod) raise LazyImportError('%s.%s %r' % (mod, '__package__', imported.__package__)) # import the module or module attribute raise LazyImportError('no %s %s.%s', 'attribute', mod, attr or name)
else: raise LazyImportError('no %s %s.%s', 'module or attribute', parent, name)
# sys._getframe(1) ... 'importlib._bootstrap' line 1032, # may throw a ValueError('call stack not deep enough') except ValueError: pass
'''(INTERNAL) Copy an instance, shallow or deep.
@param inst: The instance to copy (C{_Named}). @keyword deep: If C{True} make a deep, otherwise shallow copy (C{bool}).
@return: The copy (C{This class} or subclass thereof). '''
# **) MIT License # # Copyright (C) 2018-2020 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |