File: due.py

package info (click to toggle)
mdanalysis 2.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,696 kB
  • sloc: python: 92,135; ansic: 8,156; makefile: 215; sh: 138
file content (95 lines) | stat: -rw-r--r-- 2,614 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# emacs: at the end of the file
# ex: set sts=4 ts=4 sw=4 et:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
"""Stub file for a guaranteed safe import of duecredit constructs:  if duecredit
is not available.

To use it, place it into your project codebase to be imported, e.g. copy as

    cp stub.py /path/tomodule/module/due.py

Note that it might be better to avoid naming it duecredit.py to avoid shadowing
installed duecredit.

Then use in your code as

    from .due import due, Doi, BibTeX

See  https://github.com/duecredit/duecredit/blob/master/README.md for examples.

Origin:     Originally a part of the duecredit
Copyright:  2015-2016  DueCredit developers
License:    BSD-2

Modified for MDAnalysis to avoid calls to fork which raises cryptic
warning under MPI(see PR #1794 for rationale)

"""

__version__ = "0.0.5"


class InactiveDueCreditCollector(object):
    """Just a stub at the Collector which would not do anything"""

    def _donothing(self, *args, **kwargs):
        """Perform no good and no bad"""
        pass  # pylint: disable=unnecessary-pass

    def dcite(self, *args, **kwargs):
        """If I could cite I would"""

        def nondecorating_decorator(func):
            return func

        return nondecorating_decorator

    cite = load = add = _donothing

    def __repr__(self):
        return self.__class__.__name__ + "()"


def _donothing_func(*args, **kwargs):
    """Perform no good and no bad"""
    pass  # pylint: disable=unnecessary-pass


try:
    # Avoid call of fork inside duecredit; see
    # https://github.com/MDAnalysis/mdanalysis/pull/1822#issuecomment-373009050
    import sys
    import os
    import duecredit

    from duecredit import due, BibTeX, Doi, Url

    if "due" in locals() and not hasattr(due, "cite"):
        raise RuntimeError(
            "Imported due lacks .cite. DueCredit is now disabled"
        )
except Exception as err:
    if not isinstance(err, ImportError):
        import logging
        import warnings

        errmsg = "Failed to import duecredit due to {}".format(str(err))
        warnings.warn(errmsg)
        logging.getLogger("duecredit").error(
            "Failed to import duecredit due to {}".format(str(err))
        )
    # else:
    #   Do not issue any warnings if duecredit is not installed;
    #   this is the user's choice (Issue #1872)

    # Initiate due stub
    due = InactiveDueCreditCollector()
    BibTeX = Doi = Url = _donothing_func

# Emacs mode definitions
# Local Variables:
# mode: python
# py-indent-offset: 4
# tab-width: 4
# indent-tabs-mode: nil
# End: