How to use the duecredit.log.lgr function in duecredit

To help you get started, we’ve selected a few duecredit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github duecredit / duecredit / duecredit / injections / View on Github external
def _orig_import(self, value):
        lgr.log(2, "Reassigning _orig_import from %r to %r", DueCreditInjector.__orig_import, value)
        DueCreditInjector.__orig_import = value
github duecredit / duecredit / duecredit / cmdline / View on Github external
def run(args):
    from import PickleOutput
    if not os.path.exists(args.filename):
        lgr.debug("File {0} doesn't exist.  No summary available".format(
        return 1

    due = PickleOutput.load(args.filename)

    if args.format == "text":
        out = TextOutput(sys.stdout, due,
    elif args.format == "bibtex":
        out = BibTeXOutput(sys.stdout, due)
        raise ValueError("unknown to treat %s" % args.format)
github duecredit / duecredit / duecredit / injections / View on Github external
if mod_name in self._delayed_injections:
            # should be hit only once, "theoretically" unless I guess reimport is used etc

        if mod_name not in self._entry_records:

        total_number_of_citations = sum(map(len, self._entry_records[mod_name].values()))
        lgr.log(logging.DEBUG + 5,
                "Process %d citation injections for %d objects for module %s",
                total_number_of_citations, len(self._entry_records[mod_name]), mod_name)

            mod = sys.modules[mod_name]
        except KeyError:
            lgr.warning("Failed to access module %s among sys.modules" % mod_name)

        # go through the known entries and register them within the collector, and
        # decorate corresponding methods
        # There could be multiple records per module
        for obj_path, obj_entry_records in iteritems(self._entry_records[mod_name]):
            parent, obj_name = None, None
            if obj_path:
                # so we point to an object within the mod
                    parent, obj_name, obj = find_object(mod, obj_path)
                except (KeyError, AttributeError) as e:
                    lgr.warning("Could not find %s in module %s: %s" % (obj_path, mod, e))

            # there could be multiple per func
github duecredit / duecredit / duecredit / View on Github external
def _get_duecredit_enable():
    env_enable = os.environ.get('DUECREDIT_ENABLE', 'no')
    if not env_enable.lower() in ('0', '1', 'yes', 'no', 'true', 'false'):
        lgr.warning("Misunderstood value %s for DUECREDIT_ENABLE. "
                    "Use 'yes' or 'no', or '0' or '1'")
    return env_enable.lower() in ('1', 'yes', 'true')
github duecredit / duecredit / duecredit / View on Github external

        # get all the paths
        paths = sorted(list(pmo))

        entries = []
        for path in paths:
            for c in pmo[path]:
                if c.entry not in entries:

        for entry in entries:
                bibtex = get_bibtex_rendering(entry)
                lgr.warning("Failed to generate bibtex for %s" % entry)
            self.fd.write(bibtex.rawentry + "\n")
github duecredit / duecredit / duecredit / View on Github external
def _get_active_due():
    from .config import CACHE_DIR, DUECREDIT_FILE
    from duecredit.collector import CollectorSummary, DueCreditCollector
    from .io import load_due

    # TODO:  this needs to move to atexit handling, that we load previous
    # one and them merge with new ones.  Informative bits could be -- how
    # many new citations we got
    if os.path.exists(DUECREDIT_FILE):
            due_ = load_due(DUECREDIT_FILE)
        except Exception as e:
            lgr.warning("Failed to load previously collected %s. "
                        "DueCredit will not be active for this session."
                        % DUECREDIT_FILE)
            return _get_inactive_due()
        due_ = DueCreditCollector()

    return due_
github duecredit / duecredit / duecredit / injections / View on Github external
"""Add a citation for a given module or object within it

        modulename : string
          Name of the module (possibly a sub-module)
        obj : string or None
          Name of the object (function, method within a class) or None (if for entire module)
        min_version, max_version : string or tuple, optional
          Min (inclusive) / Max (exclusive) version of the module where this
          citation is applicable
          Keyword arguments to be passed into cite. Note that "path" will be automatically set
          if not provided
        lgr.debug("Adding citation entry %s for %s:%s", _short_str(entry), modulename, obj)
        if modulename not in self._entry_records:
            self._entry_records[modulename] = {}
        if obj not in self._entry_records[modulename]:
            self._entry_records[modulename][obj] = []
        obj_entries = self._entry_records[modulename][obj]
        if 'path' not in kwargs:
            kwargs['path'] = modulename + ((":%s" % obj) if obj else "")
        obj_entries.append({'entry': entry,
                            'kwargs': kwargs,
                            'min_version': min_version,
                            'max_version': max_version})