def _notError(inst, name, args, kwds): # PYCHOK no cover '''(INTERNAL) Format an error message. ''' n = _DOT_(classname(inst, prefixed=True), _dunder_name(name, name)) m = _COMMASPACE_.join( modulename(c, prefixed=True) for c in inst.__class__.__mro__[1:-1]) return _COMMASPACE_(unstr(n, *args, **kwds), Fmt.PAREN(_MRO_, m))
def _all(globalocals): from pygeodesy.interns import NN as _NN, _attribute_, _COMMASPACE_, \ _DOT_, _module_, _s_ # PYCHOK expected from pygeodesy.streprs import Fmt as _Fmt # PYCHOK expected # collect all public module and attribute names and check # that modules are imported from this package, 'pygeodesy' # (but the latter only when not bundled with PyInstaller or # Py2Exe, since the file-layout is different. Courtesy of # GilderGeek<https://GitHub.com/mrJean1/PyGeodesy/issues/31>) ns = list(lazily._ALL_INIT) # XXX ps = () if _isfrozen else set([_pygeodesy_] + __name__.split(_DOT_)) for mod, attrs in lazily._ALL_LAZY.enums(): if mod not in globalocals: t = _DOT_(_pygeodesy_, mod) raise ImportError('missing %s%s: %s' % (_module_, _NN, t)) ns.append(mod) # check that all other public attributes do exist if attrs and isinstance(attrs, tuple): t = tuple(a for a in attrs if a not in globalocals) if t: s = _Fmt.SQUARE(_s_, len(t)) if len(t) > 1 else _NN t = _COMMASPACE_.join( _DOT_(_pygeodesy_, mod, a) for a in t) raise ImportError('missing %s%s: %s' % (_attribute_, s, t)) ns.extend(attrs) # XXX if ps: # check that mod is a _pygeodesy_ module # XXX m = globalocals[mod] # assert(m.__name__ == mod) # XXX f = getattr(m, '__file__', _NN) # XXX d = dirname(abspath(f)) if f else pygeodesy_abspath # XXX p = getattr(m, '__package__', _NN) or _pygeodesy_ # XXX if p not in ps or d != pygeodesy_abspath: # XXX raise ImportError('foreign module: %s from %r' % (_DOT_(p, mod), f or p)) return tuple(set(ns)) # remove duplicates
def _xkwds_Error(_xkwds_func, kwds, name_txt, txt='default'): # Helper for _xkwds_get and _xkwds_pop below from pygeodesy.streprs import Fmt, pairs f = _COMMASPACE_.join(pairs(kwds) + pairs(name_txt)) f = Fmt.PAREN(_xkwds_func.__name__, f) t = _multiple_ if name_txt else _no_ t = _SPACE_(t, _EQUAL_(_name_, txt), 'kwargs') return _AssertionError(f, txt=t)
def _fstrLL0(inst, prec, toRepr): # in .azimuthal, .css # (INTERNAL) For C{_AzimuthalBase.} and C{CassiniSoldner.} C{toStr} and C{toRepr}. t = tuple(_streprs(prec, inst.latlon0, Fmt.F, False, True, None)) if toRepr: n = inst.name if n: t += Fmt.EQUAL(_name_, repr(n)), t = Fmt.PAREN(inst.classname, _COMMASPACE_.join(t)) return t
def attrs(self, *names, **kwds): '''Join attributes as C{name=value} pairs. @arg names: The attribute names (C{str}s). @kwarg kwds: Keyword argument for function L{attrs}. @return: All C{name=value} pairs joined (C{str}). ''' return _COMMASPACE_.join(attrs(self, *names, **kwds))
def _or(*words): '''(INTERNAL) Join C{words} with C{", "} and C{" or "}. ''' t, w = NN, list(words) if w: t = w.pop() if w: w = _COMMASPACE_.join(w) t = _SPACE_(w, _or_, t) return t
def unstr(name, *args, **kwds): '''Return the string representation of an invokation. @arg name: Function, method or class name (C{str}). @arg args: Optional positional arguments. @kwarg kwds: Optional keyword arguments. @return: Representation (C{str}). ''' t = reprs(args, fmt=Fmt.g) + pairs(sorted(kwds.items())) return Fmt.PAREN(name, _COMMASPACE_.join(t))
def _instr(self, prec, *attrs, **kwds): '''(INTERNAL) Format, used by C{Conic}, C{Ellipsoid}, C{Transform}. ''' t = Fmt.EQUAL(_name_, repr(self.name)), if attrs: t += pairs(((a, getattr(self, a)) for a in attrs), prec=prec, ints=True) if kwds: t += pairs(kwds, prec=prec) return _COMMASPACE_.join(t)
def toStr(self, **unused): # PYCHOK expected '''Return this reference frame as a text string. @return: This L{RefFrame}'s attributes (C{str}). ''' e = self.ellipsoid t = (Fmt.EQUAL(_name_, repr(self.name)), Fmt.EQUAL(_epoch_, self.epoch), Fmt.PAREN(Fmt.EQUAL(_ellipsoid_, classname(e)), Fmt.EQUAL(_name_, repr(e.name)))) return _COMMASPACE_.join(t)
def toStr(self, **kwds): '''Return a C{str} representation. @arg kwds: Optional, overriding keyword arguments. ''' d = dict(name=self.name) if self.name else {} d = dict(datum=self.datum.name, lon0=self.lon0, k0=self.k0, extendp=self.extendp, **d) return _COMMASPACE_.join(pairs(d, **kwds))
def __init__(self, where, **lens_txt): # txt=None '''New L{LenError}. @arg where: Object with C{.__name__} attribute (C{class}, C{method}, or C{function}). @kwarg lens_txt: Two or more C{name=len(name)} pairs (C{keyword arguments}). ''' from pygeodesy.streprs import Fmt as _Fmt x = _xkwds_pop(lens_txt, txt=_invalid_) ns, vs = zip(*sorted(lens_txt.items())) ns = _COMMASPACE_.join(ns) vs = ' vs '.join(map(str, vs)) t = _SPACE_(_Fmt.PAREN(where.__name__, ns), _len_, vs) _ValueError.__init__(self, t, txt=x)
def _all_missing2(_all_): '''(INTERNAL) Get diffs between pygeodesy.__all__ and lazily._all_imports. ''' _alzy = _all_imports(**_NamedEnum_RO((a, ()) for a in _ALL_INIT)) return ((_DOT_('lazily', _all_imports.__name__), _COMMASPACE_.join(a for a in _all_ if a not in _alzy)), (_DOT_('pygeodesy', _a_l_l_), _COMMASPACE_.join(a for a in _alzy if a not in _all_)))
def toStr(self, prec=6, fmt=Fmt.F): # PYCHOK _Named '''Like C{str(dict)} but with C{floats} formatting by C{fstr}. ''' t = pairs(self.items(), prec=prec, fmt=fmt, sep=_COLONSPACE_) return Fmt.CURLY(_COMMASPACE_.join(sorted(t)))
def toRepr(self, prec=6, fmt=Fmt.F): # PYCHOK _Named '''Like C{repr(dict)} but with C{name} and C{floats} formatting by C{fstr}. ''' t = pairs(self.items(), prec=prec, fmt=fmt, sep=_EQUAL_) return Fmt.PAREN(self.name, _COMMASPACE_.join(sorted(t)))
import geographiclib v.append(_name_version(geographiclib)) except ImportError: pass try: import numpy v.append(_name_version(numpy)) except ImportError: pass try: import scipy v.append(_name_version(scipy)) except ImportError: pass x = os_path.basename(pygeodesy_abspath) print('%s%s (%s)' % (x, _COMMASPACE_.join(p), _COMMASPACE_.join(v))) except ImportError: m = os_path.dirname(__file__).replace(os.getcwd(), _DOT_).strip() if len(m.split()) > 1: m = Fmt.QUOTE2(m) v = sys.version_info[0] if v < 3: v = NN print('usage: python%s -m %s' % (v, m)) # **) MIT License # # Copyright (C) 2016-2021 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a