How to use the duecredit.utils.never_fail 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 / collector.py View on Github external
    @never_fail
    @borrowdoc(Citation, "__init__")
    def cite(self, entry, **kwargs):
        # TODO: if cite is invoked but no path is provided -- we must figure it out
        # I guess from traceback, otherwise how would we know later to associate it
        # with modules???
        path = kwargs.get('path', None)
        if path is None:
            raise ValueError('path must be provided')

        if isinstance(entry, DueCreditEntry):
            # new one -- add it
            self.add(entry)
            entry_ = self._entries[entry.get_key()]
        else:
            entry_ = self._entries[entry]
github duecredit / duecredit / duecredit / dueswitch.py View on Github external
    @never_fail
    def dump(self, **kwargs):
        """Dumps summary of the citations

        Parameters
        ----------
        **kwargs: dict
           Passed to `CollectorSummary` constructor.
        """
        from duecredit.collector import CollectorSummary
        due_summary = CollectorSummary(self.__collectors[True], **kwargs)
        due_summary.dump()
github duecredit / duecredit / duecredit / dueswitch.py View on Github external
@never_fail
def _get_inactive_due():
    # keeping duplicate but separate so later we could even place it into a separate
    # submodule to possibly minimize startup time impact even more
    from .collector import InactiveDueCreditCollector
    return InactiveDueCreditCollector()
github duecredit / duecredit / duecredit / collector.py View on Github external
    @never_fail
    def __str__(self):
        return self.__class__.__name__ + \
            ' {0:d} entries, {1:d} citations'.format(
                len(self._entries), len(self.citations))
github duecredit / duecredit / duecredit / collector.py View on Github external
    @never_fail
    def load(self, src):
        """Loads references from a file or other recognizable source

        ATM supported only
        - .bib files
        """
        # raise NotImplementedError
        if isinstance(src, str):
            if src.endswith('.bib'):
                self._load_bib(src)
            else:
                raise NotImplementedError('Format not yet supported')
        else:
            raise ValueError('Must be a string')
github duecredit / duecredit / duecredit / dueswitch.py View on Github external
    @never_fail
    def activate(self, activate=True):
        # 1st step -- if activating/deactivating switch between the two collectors
        if self.__active is not activate:
            # we need to switch the state
            # InactiveDueCollector also has those special methods defined
            # in DueSwitch so that client code could query/call (for no effect).
            # So we shouldn't delete or bind them either
            is_public_or_special = \
                lambda x: not (x.startswith('_')
                               or x in ('activate', 'active', 'dump'))
            # Clean up current bindings first
            for k in filter(is_public_or_special, dir(self)):
                delattr(self, k)

            new_due = self.__collectors[activate]
            for k in filter(is_public_or_special, dir(new_due)):
github duecredit / duecredit / duecredit / collector.py View on Github external
    @never_fail
    def __repr__(self):
        args = []
        if self.citations:
            args.append("citations={0}".format(repr(self.citations)))
        if self._entries:
            args.append("entries={0}".format(repr(self._entries)))

        if args:
            args = ", ".join(args)
        else:
            args = ""
        return self.__class__.__name__ + '({0})'.format(args)
github duecredit / duecredit / duecredit / collector.py View on Github external
    @never_fail
    def add(self, entry):
        """entry should be a DueCreditEntry object"""
        if isinstance(entry, list):
            for e in entry:
                self.add(e)
        else:
            key = entry.get_key()
            self._entries[key] = entry
            lgr.log(1, "Collector added entry %s", key)
github duecredit / duecredit / duecredit / dueswitch.py View on Github external
@never_fail
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):
        try:
            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()
github duecredit / duecredit / duecredit / collector.py View on Github external
    @never_fail
    @borrowdoc(Citation, "__init__", replace="PLUGDOCSTRING")
    def dcite(self, *args, **kwargs):
        """Decorator for references.  PLUGDOCSTRING

        Parameters
        ----------
        conditions: dict, optional
          If reference should be cited whenever parameters to the function call
          satisfy given values (all of the specified).
          Each key in the dictionary is a 2 element tuple with first element, integer,
          pointing to a position of the argument in the original function call signature,
          while second provides the name, thus if used as a keyword argument.
          Use "DC_DEFAULT" keyword as a value to depict default value (e.g. if no
          explicit value was provided for that positional or keyword argument).
          If "keyword argument" is of the form "obj.attr1.attr2", then actual value
          for comparison would be taken by extracting attr1 (and then attr2) attributes