def _keyring(self): if self.__keyring_mod is None: # Setup logging for keyring if we are debugging, although keyring's logging # is quite scarce ATM from datalad.log import lgr import logging lgr_level = lgr.getEffectiveLevel() if lgr_level < logging.DEBUG: keyring_lgr = logging.getLogger('keyring') keyring_lgr.setLevel(lgr_level) keyring_lgr.handlers = lgr.handlers lgr.debug("Importing keyring") import keyring self.__keyring_mod = keyring if self.__keyring is None: from datalad.log import lgr # we use module bound interfaces whenever we were not provided a dedicated # backend self.__keyring = self.__keyring_mod the_keyring = self.__keyring_mod.get_keyring() if the_keyring.name.lower().startswith('null '): lgr.warning( "Keyring module returned '%s', no credentials will be provided", the_keyring.name) return self.__keyring
def __getitem__(self, module): # when ran straight in its source code -- fails to discover nipy's version.. TODO #if module == 'nipy': # import pdb; pdb.set_trace() if not isinstance(module, str): modname = module.__name__ else: modname = module module = None lgr.log(5, "Requested to provide version for %s", modname) # Early returns None so we do not store prev result for them # and allow users to install things at run time, so later check # doesn't pick it up from the _versions if modname not in self._versions: version = None # by default -- not present if modname in self.CUSTOM: try: version = self.CUSTOM[modname]() version = self._deduce_version(version) except Exception as exc: lgr.debug("Failed to deduce version of %s due to %s" % (modname, exc_str(exc))) return None else: if module is None: if modname not in sys.modules: try: module = __import__(modname) except ImportError: lgr.debug("Module %s seems to be not present" % modname) return None except Exception as exc: lgr.warning("Failed to import module %s due to %s", modname, exc_str(exc)) return None else: module = sys.modules[modname] if module: version = self._deduce_version(module) self._versions[modname] = version return self._versions.get(modname, self.UNKNOWN)
def _cached_load_document(url): """Loader of pyld document from a url, which caches loaded instance on disk """ doc_fname = _get_schema_url_cache_filename(url) doc = None if os.path.exists(doc_fname): try: lgr.debug("use cached request result to '%s' from %s", url, doc_fname) doc = pickle.load(open(doc_fname, 'rb')) except Exception as e: # it is OK to ignore any error and fall back on the true source lgr.warning( "cannot load cache from '%s', fall back on schema download: %s", doc_fname, exc_str(e)) if doc is None: from pyld.jsonld import load_document doc = load_document(url) assure_dir(dirname(doc_fname)) # use pickle to store the entire request result dict pickle.dump(doc, open(doc_fname, 'wb')) lgr.debug("stored result of request to '{}' in {}".format(url, doc_fname)) return doc
def test(*args, **kwargs): lgr.warning('Need numpy >= 1.2 for datalad.tests(). Nothing is done')