|
1
|
|
|
# emacs: at the end of the file |
|
2
|
|
|
# ex: set sts=4 ts=4 sw=4 et: |
|
3
|
|
|
# noqa: E800 |
|
4
|
|
|
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### # |
|
5
|
|
|
""" |
|
6
|
|
|
|
|
7
|
|
|
Stub file for a guaranteed safe import of duecredit constructs: if duecredit |
|
8
|
|
|
is not available. |
|
9
|
|
|
|
|
10
|
|
|
To use it, place it into your project codebase to be imported, e.g. copy as |
|
11
|
|
|
|
|
12
|
|
|
cp stub.py /path/tomodule/module/due.py |
|
13
|
|
|
|
|
14
|
|
|
Note that it might be better to avoid naming it duecredit.py to avoid shadowing |
|
15
|
|
|
installed duecredit. |
|
16
|
|
|
|
|
17
|
|
|
Then use in your code as |
|
18
|
|
|
|
|
19
|
|
|
from .due import due, Doi, BibTeX, Text |
|
20
|
|
|
|
|
21
|
|
|
See https://github.com/duecredit/duecredit/blob/master/README.md for examples. |
|
22
|
|
|
|
|
23
|
|
|
Origin: Originally a part of the duecredit |
|
24
|
|
|
Copyright: 2015-2019 DueCredit developers |
|
25
|
|
|
License: BSD-2 |
|
26
|
|
|
""" |
|
27
|
|
|
|
|
28
|
|
|
__version__ = '0.0.8' |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
class InactiveDueCreditCollector: |
|
32
|
|
|
"""Just a stub at the Collector which would not do anything""" |
|
33
|
|
|
def _donothing(self, *args, **kwargs): |
|
34
|
|
|
"""Perform no good and no bad""" |
|
35
|
|
|
pass |
|
36
|
|
|
|
|
37
|
|
|
def dcite(self, *args, **kwargs): |
|
38
|
|
|
"""If I could cite I would""" |
|
39
|
|
|
def nondecorating_decorator(func): |
|
40
|
|
|
return func |
|
41
|
|
|
return nondecorating_decorator |
|
42
|
|
|
|
|
43
|
|
|
active = False |
|
44
|
|
|
activate = add = cite = dump = load = _donothing |
|
45
|
|
|
|
|
46
|
|
|
def __repr__(self): |
|
47
|
|
|
return self.__class__.__name__ + '()' |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
def _donothing_func(*args, **kwargs): |
|
51
|
|
|
"""Perform no good and no bad""" |
|
52
|
|
|
pass |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
try: |
|
56
|
|
|
from duecredit import due, BibTeX, Doi, Url, Text |
|
57
|
|
|
if 'due' in locals() and not hasattr(due, 'cite'): |
|
58
|
|
|
raise RuntimeError( |
|
59
|
|
|
'Imported due lacks .cite. DueCredit is now disabled') |
|
60
|
|
|
except Exception as e: |
|
61
|
|
|
if not isinstance(e, ImportError): |
|
62
|
|
|
import logging |
|
63
|
|
|
logging.getLogger('duecredit').error( |
|
64
|
|
|
f'Failed to import duecredit due to {e}') |
|
65
|
|
|
# Initiate due stub |
|
66
|
|
|
due = InactiveDueCreditCollector() |
|
67
|
|
|
BibTeX = Doi = Url = Text = _donothing_func |
|
68
|
|
|
|
|
69
|
|
|
# Emacs mode definitions |
|
70
|
|
|
# Local Variables: |
|
71
|
|
|
# mode: python |
|
72
|
|
|
# py-indent-offset: 4 |
|
73
|
|
|
# tab-width: 4 |
|
74
|
|
|
# indent-tabs-mode: nil |
|
75
|
|
|
# End: |
|
76
|
|
|
|