def get(self, name, field): # consult environment, might be provided there and should take precedence env_var = ('DATALAD_%s_%s' % (name, field)).replace('-', '_') lgr.log(5, 'Credentials lookup attempt via env var %s', env_var) if env_var in os.environ: return os.environ[env_var] return self._keyring.get_password(self._get_service_name(name), field)
def get(self, name, field): # consult environment, might be provided there and should take precedence # NOTE: This env var specification is outdated and not advertised # anymmore, but needs to be supported. For example, it is used with and # was advertised for # https://github.com/datalad-datasets/human-connectome-project-openaccess env_var = ('DATALAD_%s_%s' % (name, field)).replace('-', '_') lgr.log(5, 'Credentials lookup attempt via env var %s', env_var) if env_var in os.environ: return os.environ[env_var] return self._keyring.get_password(self._get_service_name(name), field)
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)