-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add basic skeleton for duecredit * Add initial duecredit tests * add duecredit to the environment * omit due.py from coverage * Update environment.yml * remove duecredit.p files * Update openfe/tests/utils/test_duecredit.py Co-authored-by: Irfan Alibay <[email protected]> --------- Co-authored-by: Richard Gowers <[email protected]>
- Loading branch information
1 parent
e03452a
commit 1a9f7eb
Showing
9 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# custom ignores | ||
.duecredit.p | ||
.xxrun | ||
.idea/ | ||
.vscode/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# 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, Text | ||
See https://github.com/duecredit/duecredit/blob/master/README.md for examples. | ||
Origin: Originally a part of the duecredit | ||
Copyright: 2015-2021 DueCredit developers | ||
License: BSD-2 | ||
""" | ||
|
||
__version__ = '0.0.9' | ||
|
||
|
||
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 | ||
|
||
def dcite(self, *args, **kwargs): | ||
"""If I could cite I would""" | ||
def nondecorating_decorator(func): | ||
return func | ||
return nondecorating_decorator | ||
|
||
active = False | ||
activate = add = cite = dump = load = _donothing | ||
|
||
def __repr__(self): | ||
return self.__class__.__name__ + '()' | ||
|
||
|
||
def _donothing_func(*args, **kwargs): | ||
"""Perform no good and no bad""" | ||
pass | ||
|
||
|
||
try: | ||
from duecredit import due, BibTeX, Doi, Url, Text # lgtm [py/unused-import] | ||
if 'due' in locals() and not hasattr(due, 'cite'): | ||
raise RuntimeError( | ||
"Imported due lacks .cite. DueCredit is now disabled") | ||
except Exception as e: | ||
if not isinstance(e, ImportError): | ||
import logging | ||
logging.getLogger("duecredit").error( | ||
"Failed to import duecredit due to %s" % str(e)) | ||
# Initiate due stub | ||
due = InactiveDueCreditCollector() | ||
BibTeX = Doi = Url = Text = _donothing_func | ||
|
||
# Emacs mode definitions | ||
# Local Variables: | ||
# mode: python | ||
# py-indent-offset: 4 | ||
# tab-width: 4 | ||
# indent-tabs-mode: nil | ||
# End: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import importlib | ||
import pytest | ||
|
||
import openfe | ||
|
||
|
||
pytest.importorskip('duecredit') | ||
|
||
|
||
@pytest.mark.skipif((os.environ.get('DUECREDIT_ENABLE', 'no').lower() | ||
in ('no', '0', 'false')), | ||
reason="duecredit is disabled") | ||
class TestDuecredit: | ||
|
||
@pytest.mark.parametrize('module, dois', [ | ||
['openfe.protocols.openmm_afe.equil_solvation_afe_method', | ||
['10.5281/zenodo.596504', '10.48550/arxiv.2302.06758', | ||
'10.5281/zenodo.596622', '10.1371/journal.pcbi.1005659']], | ||
['openfe.protocols.openmm_rfe.equil_rfe_methods', | ||
['10.5281/zenodo.1297683', '10.5281/zenodo.596622', | ||
'10.1371/journal.pcbi.1005659']], | ||
]) | ||
def test_duecredit_protocol_collection(self, module, dois): | ||
importlib.import_module(module) | ||
for doi in dois: | ||
assert openfe.due.due.citations[(module, doi)].cites_module | ||
|
||
def test_duecredit_active(self): | ||
assert openfe.due.due.active |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters